-
Help with GoTo statements and looping
Firstly, I'm new.
I'm scripting something that uses FORTRAN and need some help... I believe IF/THEN statements don't work properly here, so I'm forced to use "GoTo" statements.
**Goal**: I'm trying to create a script that repeats itself, then stops when it recognizes the end point. The end statement is "Waiting for Prompt: Default Portal:" Each time I run this, I want it to remove a random set of lines. I successfully got this to run a static 16 times, but wanted something more automated. The system I'm trying to run the script on is CLI based, if that helps.
**Problem**: It seems to get stuck in a loop, I think.
**Code**: See below...
*************************
rmvseconds:
.TransmitTerminalKey rcVtUpKey
.TransmitTerminalKey rcVtSelectKey
.TransmitTerminalKey rcVtRemoveKey
.Transmit CR
.StatusBar = ""
.Transmit "Y"
.StatusBar = ""
.Transmit CR
If .StatusBar = "Waiting for Prompt: Default Portal:" Then
GoTo ending
Else
GoTo rmvseconds:
ending:
.Transmit CR
.Transmit CR
End If
ErrorHandler:
Session.MsgBox Err.Description, vbExclamation + vbOKOnly
End Sub
********************
-
Re: Help with GoTo statements and looping
ok... let's think about this... basically you want to run some commands in a loop until a particular text is received, at which point, it exists out...
Code:
do loop 'Start the loop
.TransmitTerminalKey rcVtUpKey
.TransmitTerminalKey rcVtSelectKey
.TransmitTerminalKey rcVtRemoveKey
.Transmit CR
.StatusBar = ""
.Transmit "Y"
.StatusBar = ""
.Transmit CR
until .StatusBar = "Waiting for Prompt: Default Portal:" 'loop untl the status bar changes to this text
.Transmit CR
.Transmit CR
'There's probably more here that you're not showing....
'Exti so we don't fal into the error handle...
Exit Sub
'Presumably there's an On Error Goto ErrorHandler somewhere back at the top...
ErrorHandler:
Session.MsgBox Err.Description, vbExclamation + vbOKOnly
-tg
-
Re: Help with GoTo statements and looping
When I try to perform "do loop" it throws me an error "Compile error: Expected: While or Until at end of statement" From what I can tell, FORTRAN doesn't support do-loop structure. In case you were wondering why I was trying to use "GOTO".
http://www.obliquity.com/computer/fortran/do.html
"FORTRAN does not have a formal do-while loop structure but it is easy to construct one using IF and GOTO statements."
For some reason when I pasted some of the code was left out, I'll repost it in entirety.
Code:
Sub Newscript()
' Generated by Reflection for UNIX and OpenVMS 14.1.0.
On Error GoTo ErrorHandler
With Session
rmvseconds:
.TransmitTerminalKey rcVtUpKey
.TransmitTerminalKey rcVtSelectKey
.TransmitTerminalKey rcVtRemoveKey
.Transmit CR
.StatusBar = ""
.Transmit "Y"
.StatusBar = ""
.Transmit CR
If .StatusBar = "Waiting for Prompt: Default Division:" Then
GoTo ending
Else
GoTo rmvseconds:
ending:
.Transmit CR
.Transmit CR
End If
End With
ErrorHandler:
Session.MsgBox Err.Description, vbExclamation + vbOKOnly
End Sub
I hope I got this right, because I can't edit my posts..
-
Re: Help with GoTo statements and looping
To use a do while structure it would be
Code:
do while not .StatusBar = "Waiting for Prompt: Default Portal:" 'loop untl the status bar changes to this text
.TransmitTerminalKey rcVtUpKey
.TransmitTerminalKey rcVtSelectKey
.TransmitTerminalKey rcVtRemoveKey
.Transmit CR
.StatusBar = ""
.Transmit "Y"
.StatusBar = ""
.Transmit CR
Loop
.Transmit CR
.Transmit CR
That is the structure but I see that in your code you are setting the .StatusBar="" which looks like it would cause an infinite loop
-
Re: Help with GoTo statements and looping
Quote:
Originally Posted by
DataMiser
To use a do while structure it would be
Code:
do while not .StatusBar = "Waiting for Prompt: Default Portal:" 'loop untl the status bar changes to this text
.TransmitTerminalKey rcVtUpKey
.TransmitTerminalKey rcVtSelectKey
.TransmitTerminalKey rcVtRemoveKey
.Transmit CR
.StatusBar = ""
.Transmit "Y"
.StatusBar = ""
.Transmit CR
Loop
.Transmit CR
.Transmit CR
That is the structure but I see that in your code you are setting the .StatusBar="" which looks like it would cause an infinite loop
The .StatusBar = "Waiting for Prompt: Default Portal:" is the field that the CLI menu outputs when it requests the next field. I'm using it as a marker for when to exit the script (two carriage returns). I'll post a sample of what the recording is telling me.
Code:
' The following string was not unique:
' .WaitForString ESC & "[23;52H", NEVER_TIME_OUT, rcAllowKeystrokes
.StatusBar = "Waiting for Prompt: OK to DELETE the entire Abracadabra Entry?"
.WaitForString "K" & ESC & "[23;52H", NEVER_TIME_OUT, rcAllowKeystrokes
.StatusBar = ""
.Transmit "y"
.StatusBar = "Waiting for Prompt: OK to DELETE the entire Abracadabra Entry? y"
.WaitForString "23;53H", NEVER_TIME_OUT, rcAllowKeystrokes
.StatusBar = ""
.Transmit CR
' The following string was not unique:
' .WaitForString ESC & "[1m", NEVER_TIME_OUT, rcAllowKeystrokes
.WaitForString " " & ESC & "[15;3H" & ESC & "[0m" & ESC & "[1m", NEVER_TIME_OUT, rcAllowKeystrokes
' Press CursorUp (Move the cursor up one line).
.TransmitTerminalKey rcVtUpKey
' The following string was not unique:
' .WaitForString ESC & "[1m", NEVER_TIME_OUT, rcAllowKeystrokes
.StatusBar = "Waiting for Prompt: Default Portal:"
.WaitForString " " & ESC & "[11;19H" & ESC & "[0m" & ESC & "[1m", NEVER_TIME_OUT, rcAllowKeystrokes
.StatusBar = ""
' Press VtSelect (Select key).
.TransmitTerminalKey rcVtSelectKey
.StatusBar = "Waiting for Prompt: Default Portal:"
.WaitForString ESC & "[1m", NEVER_TIME_OUT, rcAllowKeystrokes
.StatusBar = ""
' Press VtRemove (Perform the VT terminal's Remove function).
.TransmitTerminalKey rcVtRemoveKey
I tried the code you listed, but it didn't execute...
Here is what I have now.
Code:
Sub SixJune()
' Generated by Reflection for UNIX and OpenVMS 14.1.0.
On Error GoTo ErrorHandler
Const NEVER_TIME_OUT = 0
Dim CR As String ' Chr(rcCR) = Chr(13) = Control-M
Dim ESC As String ' Chr(rcESC) = Chr(27) = Control-[
CR = Chr(Reflection2.ControlCodes.rcCR)
ESC = Chr(Reflection2.ControlCodes.rcESC)
With Session
Do While Not .StatusBar = "Waiting for Prompt: Default Portal:" 'loop until the status bar changes to this text
.TransmitTerminalKey rcVtUpKey
.TransmitTerminalKey rcVtSelectKey
.TransmitTerminalKey rcVtRemoveKey
.Transmit CR
.StatusBar = ""
.Transmit "Y"
.StatusBar = ""
.Transmit CR
Loop
.Transmit CR
.Transmit CR
End With
ErrorHandler:
Session.MsgBox Err.Description, vbExclamation + vbOKOnly
End Sub
-
Re: Help with GoTo statements and looping
Nevermind... I think I got this to work, but it doesn't stop looping :(
-
Re: Help with GoTo statements and looping
So is the line .Transmit "Y" changing the text in the status bar? If not then it would always be blank when it gets to your goto and likely in the do while as well.
Not sure what you meant when you said you tried the code but it did not execute. Did you get a RT error, a compile error or what?
What you show looks like in uses the structure I showed you but I am not sure if that is what you are saying did not execute or something else
Your initial post mentions that it seems to get stuck in the loop
Code:
.StatusBar = ""
.Transmit CR
If .StatusBar = "Waiting for Prompt: Default Portal:" Then
Unless the .Transmit does something that changes the status bar text then it is going to be blank and you are going to be stuck in a loop. Also note that the string must be an exact match when using the = operator,
-
Re: Help with GoTo statements and looping
I was mistaken earlier. The script does work, it just never ends the loop.
I believe it does change the status bar text. I posted this previously with everything included, but I'll try and break it down below from the recorder:
Code:
.StatusBar = "Waiting for Prompt: OK to DELETE the entire Abracadabra Entry?"
.StatusBar = ""
.Transmit "y"
.StatusBar = "Waiting for Prompt: OK to DELETE the entire Abracadabra Entry? y"
.StatusBar = ""
.Transmit CR
.TransmitTerminalKey rcVtUpKey
.StatusBar = "Waiting for Prompt: Default Portal:"
.StatusBar = ""
.TransmitTerminalKey rcVtSelectKey
After ".TransmitTerminalKey rcVtUpKey" it displays the status bar on the next line (bolded). Instead of stopping after see'ing it is the target loop end, it just ignores it and starts back from the top.
-
Re: Help with GoTo statements and looping
The code you have shown there changes the status bar but there is no loop
the code fromt he other post
Code:
Do While Not .StatusBar = "Waiting for Prompt: Default Portal:" 'loop until the status bar changes to this text
.TransmitTerminalKey rcVtUpKey
.TransmitTerminalKey rcVtSelectKey
.TransmitTerminalKey rcVtRemoveKey
.Transmit CR
.StatusBar = ""
.Transmit "Y"
.StatusBar = ""
.Transmit CR
Loop
Sets the status bar to "" within the loop The code in the first post also sets the status="" then checks to see if it = something else and if not then uses goto to loop
So like I said unless the .Transmit call actually executes a function that sets the status bar text then the loop would never exit
I am assuming that last code you posted has nothing to do with it as that also calls .transmit and is not in the loop
-
Re: Help with GoTo statements and looping
BTW:
Can be ugly to read as well as leading to errors. You can easily replace this with no performance penalty using:
-
Re: Help with GoTo statements and looping
Add this snippet of source code into the position where you wish to make a multipul of processing jobs, and then being able to do all of them at more or less at the very same time, even...
-
Re: Help with GoTo statements and looping
Not a good idea, doevents will allow events to fire but it does not allow 2 pieces of code to run at the same time, that requires threading. doevents can lead to many different issues and should be avoided when possible there are places to use it but you should make sure you know how it may effect your project before you do. For exampel adding a doevents within an event sub can cause that code to reenter and open up a big can of worms for you.
That of course has nothing to do with the issue at hand.
-
Re: Help with GoTo statements and looping
Try this :
Code:
Sub SixJune()
' Generated by Reflection for UNIX and OpenVMS 14.1.0.
On Error GoTo ErrorHandler
Const NEVER_TIME_OUT = 0
Dim CR As String ' Chr(rcCR) = Chr(13) = Control-M
Dim ESC As String ' Chr(rcESC) = Chr(27) = Control-[
CR = Chr(Reflection2.ControlCodes.rcCR)
ESC = Chr(Reflection2.ControlCodes.rcESC)
With Session
top:
.TransmitTerminalKey rcVtUpKey
.TransmitTerminalKey rcVtSelectKey
.TransmitTerminalKey rcVtRemoveKey
.Transmit CR
.StatusBar = ""
.Transmit "Y"
.StatusBar = ""
.Transmit CR
IF ( .StatusBar .EQ. "Waiting for Prompt: Default Portal:" ) THEN
.Transmit CR
.Transmit CR
GOTO fin
ELSE
GOTO top
END IF
fin:
End With
ErrorHandler:
Session.MsgBox Err.Description, vbExclamation + vbOKOnly
End Sub
-
Re: Help with GoTo statements and looping
Looking at the 'recording' in Post #5 it looks as if the Statusbar text is changed following a rcVtUpKey. That being the case, you need to check the text immediately after that has been transmitted.
Code:
Do
.TransmitTerminalKey rcVtUpKey
If .StatusBar = "Waiting for Prompt: Default Portal:" Then
Exit Do
Else
.TransmitTerminalKey rcVtSelectKey
.TransmitTerminalKey rcVtRemoveKey
.Transmit CR
.StatusBar = ""
.Transmit "Y"
.StatusBar = ""
.Transmit CR
End If
Loop
I'm a bit confused about what Fortran has to do with any of this.
{EDIT}: However, if you wanted to go back to GoTo's
Code:
StartLoop:
.TransmitTerminalKey rcVtUpKey
If .StatusBar = "Waiting for Prompt: Default Portal:" Then
GoTo ExitLoop
Else
.TransmitTerminalKey rcVtSelectKey
.TransmitTerminalKey rcVtRemoveKey
.Transmit CR
.StatusBar = ""
.Transmit "Y"
.StatusBar = ""
.Transmit CR
End If
GoTo StartLoop
ExitLoop:
.Transmit CR
.Transmit CR
{End EDIT}
I also noticed in Post #5 in the code posted
Code:
End With
ErrorHandler:
Session.MsgBox Err.Description, vbExclamation + vbOKOnly
End Sub
You need an Exit Sub before the error handler otherwise when the loop does exit, you'll display an error message of nothing.
Code:
End With
Exit Sub
ErrorHandler:
Session.MsgBox Err.Description, vbExclamation + vbOKOnly
End Sub
-
Re: Help with GoTo statements and looping
Quote:
Originally Posted by
Doogle
Looking at the 'recording' in Post #5 it looks as if the Statusbar text is changed following a rcVtUpKey. That being the case, you need to check the text immediately after that has been transmitted.
Code:
Do
.TransmitTerminalKey rcVtUpKey
If .StatusBar = "Waiting for Prompt: Default Portal:" Then
Exit Do
Else
.TransmitTerminalKey rcVtSelectKey
.TransmitTerminalKey rcVtRemoveKey
.Transmit CR
.StatusBar = ""
.Transmit "Y"
.StatusBar = ""
.Transmit CR
End If
Loop
For some reason it appears to be ignoring If .StatusBar = "Waiting for Prompt: Default Portal:" Then. It goes straight to the next line and repeats itself, as if it doesn't see the statusbar text. But it shows in the recording...
Sorry to be a bother..
-
Re: Help with GoTo statements and looping
Have you tried setting a break point and stepping through the code?
-
Re: Help with GoTo statements and looping
I'm pretty new to scripting. I just read about breakpoint's and noticed that if I leave the fields blank (as if everything is already deleted, and it should go up to "Default Portal:" and stop itself), it still tries to loop. It stops at the breakpoint.
Perhaps "If .StatusBar = "Waiting for Prompt: Default Portal:" Then" is the wrong syntax? I'm not too familiar with .StatusBar
To clarify, the "Default Portal:" field is blank and the field itself is what I would like to use as a stopping point.
-
Re: Help with GoTo statements and looping
Well you can use a Timer loop until the Interval has been reached and then execute the lines of source code after that???
-
Re: Help with GoTo statements and looping
Quote:
Originally Posted by
mitch27
I'm pretty new to scripting. I just read about breakpoint's and noticed that if I leave the fields blank (as if everything is already deleted, and it should go up to "Default Portal:" and stop itself), it still tries to loop. It stops at the breakpoint.
Perhaps "If .StatusBar = "Waiting for Prompt: Default Portal:" Then" is the wrong syntax? I'm not too familiar with .StatusBar
To clarify, the "Default Portal:" field is blank and the field itself is what I would like to use as a stopping point.
have you tried :
Code:
IF ( .StatusBar .EQ. "Waiting for Prompt: Default Portal:" ) THEN
or
Code:
IF ( .StatusBar .EQ. 'Waiting for Prompt: Default Portal:' ) THEN
-
Re: Help with GoTo statements and looping
The only thing I can suggest (as DataMiser has already suggested) is that you put a breakpoint on the 'Do' statement, check the contents of .StatusBar and then step through the code (using F8), checking the contents of .StatusBar after each step, or modify the code to output the details to the Immediate Window. I appreciate that this duplicates the functionality of the 'recorder' to some extent - but that might be misleading us all !
If, at the point the 'If' statement is executed, .StatusBar is blank, then it's obviously in the wrong place (or for some reason, your code can't 'see it' at all, or by the time control gets back to your Code it's been blanked out by something else)
Code:
Do
.TransmitTerminalKey rcVtUpKey
Debug.Print "After vcVtUpKey: StatusBar is: " & .StatusBar & " Length is: " & Len(.StatusBar)
If InStr(.StatusBar, vbTab) > 0 Then Debug.Print "There's a Tab Character in there!"
If .StatusBar = "Waiting for Prompt: Default Portal:" Then
Debug.Print "Exiting Loop"
Exit Do
Else
.TransmitTerminalKey rcVtSelectKey
Debug.Print "After vcVtSelectKey: StatusBar is: " & .StatusBar & " Length is: " & Len(.StatusBar)
If InStr(.StatusBar, vbTab) > 0 Then Debug.Print "There's a Tab Character in there!"
.TransmitTerminalKey rcVtRemoveKey
Debug.Print "After vcVtRemoveKey: StatusBar is: " & .StatusBar & " Length is: " & Len(.StatusBar)
If InStr(.StatusBar, vbTab) > 0 Then Debug.Print "There's a Tab Character in there!"
.Transmit CR
Debug.Print "After first Transmit CR: StatusBar is: " & .StatusBar & " Length is: " & Len(.StatusBar)
If InStr(.StatusBar, vbTab) > 0 Then Debug.Print "There's a Tab Character in there!"
.StatusBar = ""
.Transmit "Y"
Debug.Print "After Transmit Y: StatusBar is: " & .StatusBar & " Length is: " & Len(.StatusBar)
If InStr(.StatusBar, vbTab) > 0 Then Debug.Print "There's a Tab Character in there!"
.StatusBar = ""
.Transmit CR
Debug.Print "After second Transmit CR: StatusBar is: " & .StatusBar & " Length is: " & Len(.StatusBar)
If InStr(.StatusBar, vbTab) > 0 Then Debug.Print "There's a Tab Character in there!"
End If
Loop
EDIT3: Having Googled around it seems that it's quite common to separate items on the StatusBar using a Tab character. Also there may be an odd space character kicking around at the end of the Text. I've modified the above code to report the actual length of the text in .StatusBar (you're looking for exactly 35 characters) and also to report if there's a Tab character in it. The former situation would cause the 'If' statement to return False, but to the eye, the two values would look identical. I suppose it's within the bounds of possibility that there's some sort of other control character somewhere in the StatusBar text, which can't be seen.
If you run the above or step through line by line you should see when (or if) the StatusBar value changes to what you want (and what it changes to). That should give you an idea where to put the If statement and exit the loop.(You can view the Immediate Window from the View menu on the IDE.)
It'd be interesting to see the results from the Immediate Window if you execute the code above. It should give you some idea of whats going on.
I also note some messages like this:
' The following string was not unique:
' .WaitForString ESC & "[1m", NEVER_TIME_OUT, rcAllowKeystrokes
in the 'recorder' output - are they safe to ignore or are they indicitive of a problem ? (e.g. it doesn't wait so you're now out of sync with what's on the screen)
EDIT: I'm wondering if we're all assuming that the StatusBar will change to the required contents at the same point in the code. Is it possible that under one particular circumstance it could change after sending, say 'Transmit Y' and under different circumstances after, say 'Transmit CR'? i.e. It will depend when the 'virtual cursor' for the session is on the screen at the time the code executes.
EDIT2: BTW, please put me out of my misery and expalin what Fortran has to do with all this :)
-
Re: Help with GoTo statements and looping
I'm now beginning to wonder about the processes involved here.
[Taking-a-complete-flyer]
I'm guessing that you're using AttachMate or Reflection or some high level language to determine the logic you wish to follow for some sort of 'screen scraping' application.
That is being converted into an 'intermediate', something that looks like VB (with Fortran overtones, perhaps). It also appears that the 'intermediate' code is also translated / post processed in some way so that the extra statements (e.g. .WaitForString "23;53H", NEVER_TIME_OUT, rcAllowKeystrokes) are inserted in the appropriate places and it's this code that is actually being executed. If that is broadly accurate, perhaps the 'intermediate' code never 'sees' the .StatusBar changes and you should be modifying the code that is actually being executed (i.e. the result of the 'post processing of the 'intermediate' code).
[/Taking-a-complete-flyer]
-
Re: Help with GoTo statements and looping
I think my Fortran comment was mistaken in my first post. Sorry about that, I'm still pretty new to all this.
I tried your script to check for tabs, and it never screen printed anything. I also tried to print a test debug (Debug.Print "Test text") and nothing popped up. Perhaps I'm not see'ing the message?
Update related to your flyer post. It seems to only read the last message (.StatusBar = ""), and exits after see'ing the first entry... I wish it would read the important part which is the field itself, because .Statusbar = "" happens after every key input...
-
Re: Help with GoTo statements and looping
The output would have been printed to the Immediate Window - did you look at that ? As I said, you can open the Immediate Window from the View Menu on the main screen of the IDE.
-
Re: Help with GoTo statements and looping
I did, this is the output.
After vcVtUpKey: StatusBar is: Length is: 0
All the lines afterwards are the same, Length is 0.
-
Re: Help with GoTo statements and looping
So, the results imply that the .StatusBar in your VB code is either not the same .StatusBar in the Code being executed or that it's being changed prior to control returning to your VB Code. EDIT: or what you're doing is not changing the StatusBar's state.
Could you possibly describe the overall process, from doing whatever it is you do at the highest level and what happens from there? Is my [Taking-a-complete-flyer] post anything like what's going on ?
i.e. High Level Language -> 'VB' intermediate code -> code that is actually executed. I'm struggling to understand how the whole thing hangs together.
Is there a way you can post the 'actual' code that's being executed? (i.e. the code with all the 'WaitForString' statements). As I mentioned before, perhaps it's that code you should be modifying to incorporate the loop and test.
-
Re: Help with GoTo statements and looping
Can you please post your updated source code project, that would be really good if you could. So that we can see what kind of processes and levels are involved here???
-
Re: Help with GoTo statements and looping
Here is the recording unedited.
Code:
Sub Source()
' Generated by the Reflection Macro Recorder on 06-12-2013 10:10:57.69.
' Generated by Reflection for UNIX and OpenVMS 14.1.0.
On Error GoTo ErrorHandler
Const NEVER_TIME_OUT = 0
Dim CR As String ' Chr(rcCR) = Chr(13) = Control-M
Dim ESC As String ' Chr(rcESC) = Chr(27) = Control-[
CR = Chr(Reflection2.ControlCodes.rcCR)
ESC = Chr(Reflection2.ControlCodes.rcESC)
With Session
' Press CursorUp (Move the cursor up one line).
.TransmitTerminalKey rcVtUpKey
.WaitForString ESC & "[16;2H", NEVER_TIME_OUT, rcAllowKeystrokes
' Press VtSelect (Select key).
.TransmitTerminalKey rcVtSelectKey
' The following string was not unique:
' .WaitForString ESC & "[1m", NEVER_TIME_OUT, rcAllowKeystrokes
.WaitForString " " & ESC & "[16;3H" & ESC & "[0m" & ESC & "[1m", NEVER_TIME_OUT, rcAllowKeystrokes
' Press VtRemove (Perform the VT terminal's Remove function).
.TransmitTerminalKey rcVtRemoveKey
' The following string was not unique:
' .WaitForString ESC & "[1m", NEVER_TIME_OUT, rcAllowKeystrokes
.WaitForString " " & ESC & "[16;3H" & ESC & "[0m" & ESC & "[1m", NEVER_TIME_OUT, rcAllowKeystrokes
.Transmit CR
' The following string was not unique:
' .WaitForString ESC & "[23;37H", NEVER_TIME_OUT, rcAllowKeystrokes
.StatusBar = "Waiting for Prompt: OK to DELETE the entire TEST Entry?"
.WaitForString "K" & ESC & "[23;37H", NEVER_TIME_OUT, rcAllowKeystrokes
.StatusBar = ""
.Transmit "y"
.StatusBar = "Waiting for Prompt: OK to DELETE the entire TEST Entry? y"
.WaitForString "23;38H", NEVER_TIME_OUT, rcAllowKeystrokes
.StatusBar = ""
.Transmit CR
' The following string was not unique:
' .WaitForString ESC & "[1m", NEVER_TIME_OUT, rcAllowKeystrokes
.WaitForString " " & ESC & "[16;3H" & ESC & "[0m" & ESC & "[1m", NEVER_TIME_OUT, rcAllowKeystrokes
' Press CursorUp (Move the cursor up one line).
.TransmitTerminalKey rcVtUpKey
.WaitForString ESC & "[15;2H", NEVER_TIME_OUT, rcAllowKeystrokes
' Press VtSelect (Select key).
.TransmitTerminalKey rcVtSelectKey
' The following string was not unique:
' .WaitForString ESC & "[1m", NEVER_TIME_OUT, rcAllowKeystrokes
.WaitForString " " & ESC & "[15;3H" & ESC & "[0m" & ESC & "[1m", NEVER_TIME_OUT, rcAllowKeystrokes
' Press VtRemove (Perform the VT terminal's Remove function).
.TransmitTerminalKey rcVtRemoveKey
' The following string was not unique:
' .WaitForString ESC & "[1m", NEVER_TIME_OUT, rcAllowKeystrokes
.WaitForString " " & ESC & "[15;3H" & ESC & "[0m" & ESC & "[1m", NEVER_TIME_OUT, rcAllowKeystrokes
.Transmit CR
' The following string was not unique:
' .WaitForString ESC & "[23;36H", NEVER_TIME_OUT, rcAllowKeystrokes
.StatusBar = "Waiting for Prompt: OK to DELETE the entire AGE Entry?"
.WaitForString "K" & ESC & "[23;36H", NEVER_TIME_OUT, rcAllowKeystrokes
.StatusBar = ""
.Transmit "y"
.StatusBar = "Waiting for Prompt: OK to DELETE the entire AGE Entry? y"
.WaitForString "23;37H", NEVER_TIME_OUT, rcAllowKeystrokes
.StatusBar = ""
.Transmit CR
' The following string was not unique:
' .WaitForString ESC & "[1m", NEVER_TIME_OUT, rcAllowKeystrokes
.WaitForString " " & ESC & "[15;3H" & ESC & "[0m" & ESC & "[1m", NEVER_TIME_OUT, rcAllowKeystrokes
' Press CursorUp (Move the cursor up one line).
.TransmitTerminalKey rcVtUpKey
' The following string was not unique:
' .WaitForString ESC & "[1m", NEVER_TIME_OUT, rcAllowKeystrokes
.StatusBar = "Waiting for Prompt: Default Portal:"
.WaitForString " " & ESC & "[11;17H" & ESC & "[0m" & ESC & "[1m", NEVER_TIME_OUT, rcAllowKeystrokes
.StatusBar = ""
' Press VtSelect (Select key).
.TransmitTerminalKey rcVtSelectKey
.StatusBar = "Waiting for Prompt: Default Portal:"
.WaitForString ESC & "[1m", NEVER_TIME_OUT, rcAllowKeystrokes
.StatusBar = ""
.Transmit CR
' The following string was not unique:
' .WaitForString ESC & "[1m", NEVER_TIME_OUT, rcAllowKeystrokes
' .WaitForString " " & ESC & "[15;3H" & ESC & "[0m" & ESC & "[1m", NEVER_TIME_OUT, rcAllowKeystrokes
End With
Exit Sub
ErrorHandler:
Session.MsgBox Err.Description, vbExclamation + vbOKOnly
' Recording stopped at 10:11:31.47.
End Sub
-
Re: Help with GoTo statements and looping
I'm having trouble relating the code in the 'recording' to the VB Code. There's no sign of a Loop or an If statement. I'm not sure what has been 'recorded'.
-
Re: Help with GoTo statements and looping
He means saved to disk, when he means recorded. But that's from the old C60 and C90 audio tapes that were used as storage on the older versions of PCs that were like the Commodore C64, years ago...
-
Re: Help with GoTo statements and looping
Everything is Remmed out, so that it is totally ignored can you please post the whole source code??? And also name the Controls that you are using, so that I can code in Notepad and then send you the following source code...
-
Re: Help with GoTo statements and looping
How can the Recording be stopped at a certain level or positon only that is set as default when the end-user is operating the program??? Because say that the end-user ends the program, immideately when the program is executed into action. Say a second or less after it runs???
-
Re: Help with GoTo statements and looping
Have the keycodes be called in MouseDown or either KeyPress handlers of the Form or UserControl would be nice and also very fast to work with, so that you don't have any slow downs when working with the program on a very old computer, (Single Core) or even a high processing core(Dual, Triple or even Quad could be counted as being high processing like in Windows 8.00)
-
Re: Help with GoTo statements and looping
By the way I still cannot be able to find out what this kind of program really still does, right. Because there isn't very much process comments to read, but they are commands rather commented out so that the IDE doesn't execute them. Which is totally wrong, due to the fact that isn't good programming.
-
Re: Help with GoTo statements and looping
@TheiMp: OP is using a Product called 'Reflection' which, amongst other things, allows them to emulate certain types of Terminal Devices and to 'screen scrape' information from other applications running on various operating systems. It uses a High Level Language which at some point is translated into something like VB, that code, in turn is translated into code that actually executes. The problem OP is having is 'bespoking' the code to perform the actions they wish to .
It has absolutely nothing to do with Magnetic Tape Cassettes, Keycodes, MosueDown events, Forms or User Controls.
-
Re: Help with GoTo statements and looping
Sorry I thought you wanted a recording of what I wanted it to do. That was me just going through the motions without using the script. Basically we use a command line driven menu system that handles user accounts. It's structured as follows:
*******************
User: Last, First M
Default Portal: Randomportalname (I'd like for the script to stop when it knows it is in this field, but it doesn't stop and performs .Transmit CR, it adds a "y" entry into the Secondary Menus field and loops itself)
Select Secondary Menus:
Needsdeleted1
Needsdeleted2
Needsdeleted3
So on and so forth
(Cursor starts here)
*******************
I'm currently using
Code:
Sub TestGoTo()
On Error GoTo ErrorHandler
Const NEVER_TIME_OUT = 0
Dim ESC As String ' Chr(rcESC) = Chr(27) = Control-[
ESC = Chr(Reflection2.ControlCodes.rcESC)
With Session
StartLoop:
.TransmitTerminalKey rcVtUpKey
If .StatusBar = "" Then
GoTo ExitLoop
Else
.TransmitTerminalKey rcVtSelectKey
.TransmitTerminalKey rcVtRemoveKey
.Transmit CR
.StatusBar = ""
.Transmit "Y"
.StatusBar = ""
.Transmit CR
End If
GoTo StartLoop
ExitLoop:
.Transmit CR
.Transmit CR
ErrorHandler:
Session.MsgBox Err.Description, vbExclamation + vbOKOnly
End With
End Sub
This part of the recording seems to be the problem for me, I think:
Code:
.WaitForString " " & ESC & "[15;3H" & ESC & "[0m" & ESC & "[1m", NEVER_TIME_OUT, rcAllowKeystrokes
' Press CursorUp (Move the cursor up one line).
.TransmitTerminalKey rcVtUpKey
' The following string was not unique:
' .WaitForString ESC & "[1m", NEVER_TIME_OUT, rcAllowKeystrokes
.StatusBar = "Waiting for Prompt: Default Portal:"
.WaitForString " " & ESC & "[11;17H" & ESC & "[0m" & ESC & "[1m", NEVER_TIME_OUT, rcAllowKeystrokes
.StatusBar = ""
' Press VtSelect (Select key).
.TransmitTerminalKey rcVtSelectKey
I think the underlined portion is preventing the script from noticing the "Default Portal:" menu because it comes immediately afterwards.
I really appreciate your patience with me on this.
-
Re: Help with GoTo statements and looping
This type of Source Code that the OP is using looks quite much like the QBAISC source code that I used to write Cash Registers with, back in 2000. That was a very long time ago, in deed it was!!
-
Re: Help with GoTo statements and looping
Have you tried removing the 'StatusBar = ""' statements ?
should
Code:
If .StatusBar = "" Then
be
Code:
If .StatusBar <> "" Then
?
-
Re: Help with GoTo statements and looping
What kind of Control is StatusBar really from??? I guess that it's coming from them CommonControl SP6 for Visual Basic, right then???
-
Re: Help with GoTo statements and looping
No, it's not a VB Control, it's a Property of the Session Object which in turn is specific to the Application OP is using.
-
Re: Help with GoTo statements and looping
And then the Session Object, which is some sort of ActiveX Control Object, right. I'm just trying to get my feet into this again. But then that was something long ago, that didn't have any kind of Controls, at that...
-
Re: Help with GoTo statements and looping
If I removed them, what would I use to indicate the stopping point for the loop?
-
Re: Help with GoTo statements and looping
Well then you have to work from the original type of project that you had, previously posted. Cause now I ruined it, because I had saved over it by mistake. So sorry...
-
Re: Help with GoTo statements and looping
It was a rhetorical response...
I need something in the code that indicates a stopping point. Otherwise, it's useless.
-
Re: Help with GoTo statements and looping
I guess, try it in the something like an event that doesn't have a Timer in it???
-
Re: Help with GoTo statements and looping
Could you go into further detail on DoEvents? I'm pretty new to VB.
Thank you.
-
Re: Help with GoTo statements and looping
Well it's very hard to describe what to use it for, seeing that it can be used for many types of purposes. Like animation and also network support, like a login script, etc...
-
Re: Help with GoTo statements and looping
don't fib and don't sugar coat it.... DoEvents is for one purpose and one purpose only... when you use DoEvents, you're telling the system "Hey, I'm not doing anything important at the moment, if you have any waiting message in the message queue, process them." That's what it does... It comes with a price... and more often not, a lot of unintended consequences. There is a reason why this thread made it up to two pages before the suggestions came up.
-tg
-
Re: Help with GoTo statements and looping
And that is, sorry I have only been working by myself today. Everyone's out of the Office...
-
Re: Help with GoTo statements and looping
Quote:
Originally Posted by
techgnome
don't fib and don't sugar coat it.... DoEvents is for one purpose and one purpose only... when you use DoEvents, you're telling the system "Hey, I'm not doing anything important at the moment, if you have any waiting message in the message queue, process them." That's what it does... It comes with a price... and more often not, a lot of unintended consequences. There is a reason why this thread made it up to two pages before the suggestions came up.
-tg
Part of the reason is I'm also very new to this. Am I correct to say things aren't looking good as far as a solution to my problem?
-
Re: Help with GoTo statements and looping
my reply wasn't aimed at you... in was in direct response to theimp's suggestion of using doEvents... it's a slippery slope to start on... sometimes it becomes necessary, in which case, it can be used as long as you have a full and complete understanding of what it could do - specifically, releases the system to take action on other messages in the queue, which could include processing OTHER EVENTS in your app, that could cause you to end up someplace you're not prepared to be at yet.
That's all.
As for you issue specifically, I don't know. To be honest, I'm having trouble following the thread... so I'm leaving it in the (hopefully) capable hands of others who seem to have a better idea of what you're doing than I.
-tg
-
Re: Help with GoTo statements and looping
Well I guess that we could be able to get a Super Moderator to help us, but then that's the OP's decision, then not min to do???
-
Re: Help with GoTo statements and looping
I would like to try another route. Is there a way I could make the script stop when it reaches row 11 on the page?
-
Re: Help with GoTo statements and looping
But then that would be altering a long of source code. Also what are you going to skip from the line xyz to line 11???
-
Re: Help with GoTo statements and looping
Quote:
Originally Posted by
ThEiMp
But then that would be altering a long of source code. Also what are you going to skip from the line xyz to line 11???
What source code? Can I not tell the script to check what line/row is it on, and if it's on line 11, have it stop? Instead of going through the .StatusBar hassle.
-
Re: Help with GoTo statements and looping
Well then can't you use a GoTo I believe that you can use that in this type of instance or even a GoSub, either way???
-
Re: Help with GoTo statements and looping
Quote:
Originally Posted by
ThEiMp
Well then can't you use a GoTo I believe that you can use that in this type of instance or even a GoSub, either way???
I don't mind using If Then. I just need the script to stop. Is there a command that will look at line 11 so I can create a stopping point??
-
Re: Help with GoTo statements and looping
Quote:
Originally Posted by
mitch27
If I removed them, what would I use to indicate the stopping point for the loop?
My suggestion was something like this
Code:
Sub TestGoTo()
On Error GoTo ErrorHandler
Const NEVER_TIME_OUT = 0
Dim ESC As String ' Chr(rcESC) = Chr(27) = Control-[
ESC = Chr(Reflection2.ControlCodes.rcESC)
With Session
StartLoop:
.TransmitTerminalKey rcVtUpKey
If .StatusBar <> "" Then
GoTo ExitLoop
Else
.TransmitTerminalKey rcVtSelectKey
.TransmitTerminalKey rcVtRemoveKey
.Transmit CR
'.StatusBar = ""
.Transmit "Y"
'.StatusBar = ""
.Transmit CR
End If
GoTo StartLoop
ExitLoop:
Debug.Print .StatusBar ' display the contents of StatusBar in the Immediate Window
.Transmit CR
.Transmit CR
Exit Sub
ErrorHandler:
Session.MsgBox Err.Description, vbExclamation + vbOKOnly
End With
End Sub
-
Re: Help with GoTo statements and looping
I guess that you could be able to make it loop over on Line 11, but then what is so special about line 11???
-
Re: Help with GoTo statements and looping
Quote:
Originally Posted by
Doogle
My suggestion was something like this
Thank you for the response, I will try this in the morning and report back.
-
Re: Help with GoTo statements and looping
So sorry, I keep making that kind of mistake!!