Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Variable to shorten code 1

Status
Not open for further replies.

dvirgint

Programmer
Jun 28, 2010
85
CA
Hello,

My company has switched from Attachmate Extra! to Attachmate Reflection recently and I have been creating new macros with the new Reflection syntax.

All is going well, however I was wondering if there was a way to create a variable to shorten the extremely long Sendkey functions.

For example, to make the system send a "tab" key, you have to add ibm.CurrentScreen.SendControlKey(ControlKeyCode_Tab)

I thought I could do something like:
Set tabKey = ibm.CurrentScreen.SendControlKey(ControlKeyCode_Tab)
... but that did not work.

Any ideas on how to approach this?

Thanks for your help.
 
Have never used Attachmate Reflection, but can't you make a function to do the job like,
Code:
Declare Function sendkey(key)

Function sendkey(key)
  ibm.CurrentScreen.SendControlKey(key)
End Function

or if you want a Function, just for tab, then
Code:
Declare Function sendtab()

Function sendtab()
  ibm.CurrentScreen.SendControlKey(ControlKeyCode_Tab)
End Function

Then you just need to call it in main with,
Code:
Sub main
  sendkey("Hello World!")
End Sub

Don't know if the declaration of function syntax is the same in Reflection, because i use Extra!, and i'm not sure if this will work perfectly, but that is how i would do it.

Hope it helps
 
Sorry, just realize the function was called SendControlKey, so the first function should not use SendControlKey, but the Sendkeys function instead.
Also, if you want a function to handle more ControlKeys, then you can make a function with an argument for the Controlkey, and then have a Switch (Select case) statement inside the function to use the correct control key.

You also need to Dim your session objects before the functions are described.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top