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!

EXTRA! Basic programming 3

Status
Not open for further replies.

johnsearcy5

Technical User
Jun 28, 2004
6
US
Is there a website that may have lessons or tutorials I can go to and learn this language? Maybe a book I can purchase? I have created some macros at work and I don't quite have the knowledge to make it work as i see it in my mind. Any information would be appreciated.

 
Not to my knowledge. The help files are very informative. You may also find this useful as a starting point:

How do I use VB(A) to manipulate attachmate (6.5+)? faq99-4069
I'm ready for Extra Basic... now what? faq99-4087
How do I get data to Excel? faq99-4068

calculus
 
Calculus -

I have two quick questions. Can a macro actually look for or recognize a word or group of words on the screen? Also, I tried that WaitForString command, but it didn't quite work as I planned. I thought it was going to wait for something I put in. How does this work?

Thanks
 
A little more detail on the questions please.

1. A macro can read the screen and look for whatever you want it to. You were on the right track with WaitForString.

2. I'm guessing you need a bit of help on WaitForString. This function will wait until it "sees" a group of letters on the screen. For instance:

Sess0.Screen.WaitForString "CICS", 1, 73

The 1, 73 specifies the X, Y coordinates you expect to see the string at. You can also leave this off and the function will wait until it sees the string anywhere on the screen.

I'm not sure what you're wanting the system to do. You mentioned waiting for you to type something. More detail on this would be helpful.

calculus
 
Hey Calculus -

I now have it waiting for a one letter input (WaitForKeys), but the WaitForString doesn't quite work like I want. That may take too long to explain and I type slow. But, I do want to ask you - Is EXTRA! Basic similar to VB? In other words, if there aren't any books/manuals on EXTRA! Basic, then would studying (from the beginning) VB be helpful. I do want to learn programming again. I took it way back in college (Pascal, COBOL), but the music took over and I dropped out. Now, the interest has peaked highly again as I am working on macros to help everyone at work be more efficient. Any advice would be helpful.

Thank you,
John
 
Yes, VB and EB are similar. Of course all programming is has the same logic, but the basic flow changes are very similar in VB and EB (For/Next, If/Then, Do/Loop).

In fact, most code can be pasted from EB into VB and will run with only minor changes.

calculus
 
Calculus and Search66 -

What book do you recommend (or hear of) that would be good to learn VB? I'm guessing that the macros for Excel and Word would be VB, also. Correct? It's so d$#% frustrating to know and visualize what could be written to help with processes at work (and other things) and not quite have the knowledge to do it completely!

Thank you,
John
 
I've learned entirely through trail/error, and the help files in EB. Help files in VB are sometimes a bit over the top for begginners, but are overall very good.

calculus
 
Calculus,

Thanks for your help on all of this. That is how it seems to be for me at this point - trial and error - and help files. I just don't have the time to study them like I want to at work. I'll get there, I see how my macro should work, now I'm working on putting it on paper persay. It's like a songwriter who hears an entire song in his head that has 6 chords in it, and he only knows 3 on the guitar. Oh, well - to studying we go.

Thanks,
John
 
johnsearcy5 (TechnicalUser)

Yes you can.

Example: John Smith

jFound = "false"
If GetValue(3,4,2) = "John Smith"
Then jfound = "True"
end if
else

next

loop

end sub
 
I have a small problem within a macro I have. The macro works but there is a delay within I'm trying to solve.
Here is the part of the macro where the problem is:

While (F<>"S" and F<>"Z" and F<>"E")
F=Sess0.Screen.WaitForKeys(F)
WEnd

What this is doing is obviously waiting for an input and if one of the above three keys are pressed it continues on with instructions. The person using it can page forward or back (F8 and F7) to where the correct field is and arrow up or down and it will 'wait' for one of those 3 keys. The problem is there is a pause as soon as they hit one of those 3 keys. They have to wait about 8 or 10 seconds then re-enter the key and it resumes as normal. If they enter(in the correct field)one of those 3 without paging forward or arrowing, it runs instantly. I have tried If Then and Do Loop statements and had F = " " to clear out the F. I tried taking the F = out in front of the Sess0.Screen.WaitForKeys(F). Nothing is working. One time I placed the F = " " within and before (in earlier part of macro)and it had no pause whatsoever. I can't seem to remember where I had them. What causes this and is there any remedy for the 'pause'??
 
I believe changing the "and" to an "or" may help. If I read the code correctly, it appears that you are asking for all three keys to be pressed at once.

Try:

While (F<>"S" or F<>"Z" or F<>"E")
F=Sess0.Screen.WaitForKeys(F)
WEnd

Hope this helps.
 
He should be using an "and" with the "while" statement. Otherwise the program will get caught in a loop. Because F will never "S" "Z" and "E" at the same time.

Since it's in a While loop try this:
Code:
While (F<>"S" and F<>"Z" and F<>"E")
   F=Sess0.Screen.WaitForKeys(0)
WEnd

This will make your wait 0 seconds. Once the user presses a key, it'll pick up the key that was pressed.
 
I wonder if it isn't a mistake to wait indefinitely for an occurrence whether it be waitforstring, etc as what happens if that string never occurs?

 
If it never occurs, then you'd have to end task to stop the program. You could put a counter into it and exit when it reaches a certain number. Or, if you wanted something that'd be more time based, you could grab the time when the do starts and when it's X time later it exits.

Code:
Counter = 0
Do While (F<>"S" and F<>"Z" and F<>"E")
   F=Sess0.Screen.WaitForKeys(0)
   Counter = Counter + 1
   If Counter = 5000 then
      TimedOut = true
      Exit Do
   End If
Loop
If TimedOut = true then
'Handle a TimedOut error here.
End If
 
Actually EB handles this for you. The only time you can wait indefinately is if you put the code in a loop. All of the WaitFor functions will time out on their own at about 35-40 seconds of waiting.

This is not necessarily good or bad, just the way it works.

calculus
 
EB would never 'time out' on its own in Skie's code as it is written (hence the counter to exit the loop).

Do While (F<>"S" and F<>"Z" and F<>"E")
F=Sess0.Screen.WaitForKeys(0)
Loop

Will loop forever until user presses a S Z or E. Calculus, the default timeout would only apply if it was used as follows F=Sess0.Screen.WaitForKeys("S").

The default timeout of 30 seconds doesn't apply as Skie is setting the wait time to 0 with WaitForKeys(0).

Note, This code is also great for looking for multiple screen responses as you can loop through many WaitFor's very quickly.

While RC = 0
select case true
Case MySess.WaitForString(0,"Request Completed")
rc = 1
Case MySess.WaitForString(0,"Invalid Action")
rc = 2
Case MySess.WaitForString(0,"Tilt")
rc = 3
end select
Wend

Without specifying to wait 0 the above loop would wait 30 seconds for the first Case 30 for the second and so on. Again you would need to add a timer or counter to exit the loop.

Also if 30 seconds is to long or to short you can adjust the milli seconds WaitForKeys(9000,"S") would only wait nine seconds.
 
But, the WaitForKeys is within an indefinate loop because you can't set multiple characters for WaitFor.

Instead, you have it wait for 0 milliseconds and loop. If a key is pressed it records it. If it's F, Z, or E then the loop ends.

If you only had to wait for one keystroke, then you could do:
Code:
F=Sess0.Screen.WaitForKeys(120000,"F")
If F <> "F" then
'Code goes here for F not being pressed within 2 minutes.
End If
 
Sorry I thought that's what I implied. You could wait for more keys like this but it's lengthier than yours.

began = timer
While RC = 0 and not timeout
select case true
Case MySess.WaitForKeys(0,"A")
rc = 1
Case MySess.WaitForKeys(0,"B")
rc = 2
Case MySess.WaitForKeys(0,"C")
rc = 3
end select
end = timer
if timer - begin => 120 then timeout = true
Wend
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top