By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
435,264 Members | 1,220 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 435,264 IT Pros & Developers. It's quick & easy.

jumping to another line

P: 13
I made a macro to sort a report that i can edited in VB. it works 98% of the time. r8002 is what i want it to find in this part of the macro. the only time this macro does not work is if there is not any r8002 to find and it stops. I want it to skip to the next part. is there any way i can make it say

"if you do not see this"( .WaitForEvent rcEnterPos, "30", "0", 6, 53)

than skip to the line that say (.TransmitANSI "top" )

this is just a chunk of the macro i have noted where it stops and where i would like it to jump to. is there an easy way i can do this?

If anyone can help thanks.

Expand|Select|Wrap|Line Numbers
  1. .TransmitANSI "f r8002 prev"
  2. .TransmitTerminalkey rcIBMNewLineKey
  3. .WaitForEvent rcKbdEnabled "30", "0", 1, 1
  4. .WaitForEvent rcEnterPos, "30", "0", 6, 53               (it stops here)
  5. .TransmitTerminalkey rcIBMNewLineKey
  6. .TransmitANSI "dd"
  7. .TransmitTerminalkey rcIBMEnterKey
  8. .WaitForEvent rcKbdEnabled "30", "0", 1, 1
  9. .WaitForEvent rcEnterPos, "30", "0", 7, 2
  10. .TransmitTerminalkey rcIBMHomeKey
  11. .TransmitANSI "bottom"
  12. .TransmitTerminalkey rcIBMEnterKey
  13. .WaitForEvent rcKbdEnabled "30", "0", 1, 1
  14. .WaitForEvent rcEnterPos, "30", "0", 4, 15
  15. .waitForDisplayString "===>", "30, 4, 10
  16. .TransmitTerminalkey rcIBMNewLineKey
  17. .TransmitTerminalkey rcIBMNewLineKey
  18. .TransmitANSI "dd"
  19. .TransmitTerminalkey rcIBMEnterKey
  20. .WaitForEvent rcKbdEnabled "30", "0", 1, 1
  21. .WaitForEvent rcEnterPos, "30", "0", 5, 9
  22. .waitForDisplayString "******","30", 5, 2 
  23. .TransmitTerminalkey rcIBMHomeKey
  24. .TransmitANSI "top"                                  (I want it to jump to here)
  25. .TransmitTerminalkey rcIBMEnterKey
Sep 3 '07 #1
Share this Question
Share on Google+
9 Replies


P: 21
Expand|Select|Wrap|Line Numbers
  1. If .WaitForEvent rcEnterPos, "30", "0", 6, 53 = SomeReturnValue Then
  2. .TransmitTerminalkey rcIBMNewLineKey
  3. .TransmitANSI "dd"
  4. .TransmitTerminalkey rcIBMEnterKey
  5. .WaitForEvent rcKbdEnabled "30", "0", 1, 1
  6. .WaitForEvent rcEnterPos, "30", "0", 7, 2
  7. .TransmitTerminalkey rcIBMHomeKey
  8. .TransmitANSI "bottom"
  9. .TransmitTerminalkey rcIBMEnterKey
  10. .WaitForEvent rcKbdEnabled "30", "0", 1, 1
  11. .WaitForEvent rcEnterPos, "30", "0", 4, 15
  12. .waitForDisplayString "===>", "30, 4, 10
  13. .TransmitTerminalkey rcIBMNewLineKey
  14. .TransmitTerminalkey rcIBMNewLineKey
  15. .TransmitANSI "dd"
  16. .TransmitTerminalkey rcIBMEnterKey
  17. .WaitForEvent rcKbdEnabled "30", "0", 1, 1
  18. .WaitForEvent rcEnterPos, "30", "0", 5, 9
  19. .waitForDisplayString "******","30", 5, 2 
  20. .TransmitTerminalkey rcIBMHomeKey
  21. End IF
  22. .TransmitANSI "top"       
  23. .TransmitTerminalkey rcIBMEnterKey[/quote]
  24.  
Does waitforevents return anything?

If it does can you not just use If Then Else...???
Sep 3 '07 #2

P: 13
"If .WaitForEvent rcEnterPos, "30", "0", 6, 53 = SomeReturnValue Then"

"30", "0", 6, 53 is a cursor position i think that is what it is waiting for so would

If .WaitForEvent rcEnterPos,= "30", "0", 6, 53 then

and if it did not = "30", "0", 6, 53 it would junp to the line after end if?
can i start a line with "if"?

thanks its a little clealer
Sep 3 '07 #3

P: 13
i thinking about what you said about then else does this look like it would work? does "if" and "else" have to be on there own line? how important is spacing? on some examples i see the lines after "if" and "else" are indented? if this will work i think i am starting to understand if not i am lost :)


Expand|Select|Wrap|Line Numbers
  1. .TransmitANSI "f r8002 prev"
  2. .TransmitTerminalkey rcIBMNewLineKey
  3. .WaitForEvent rcKbdEnabled "30", "0", 1, 1
  4. if
  5. .WaitForEvent rcEnterPos,= "30", "0", 6, 53 then
  6. .TransmitTerminalkey rcIBMNewLineKey
  7. .TransmitANSI "dd"
  8. .TransmitTerminalkey rcIBMEnterKey
  9. .WaitForEvent rcKbdEnabled "30", "0", 1, 1
  10. .WaitForEvent rcEnterPos, "30", "0", 7, 2
  11. .TransmitTerminalkey rcIBMHomeKey
  12. .TransmitANSI "bottom"
  13. .TransmitTerminalkey rcIBMEnterKey
  14. .WaitForEvent rcKbdEnabled "30", "0", 1, 1
  15. .WaitForEvent rcEnterPos, "30", "0", 4, 15
  16. .waitForDisplayString "===>", "30, 4, 10
  17. .TransmitTerminalkey rcIBMNewLineKey
  18. .TransmitTerminalkey rcIBMNewLineKey
  19. .TransmitANSI "dd"
  20. .TransmitTerminalkey rcIBMEnterKey
  21. .WaitForEvent rcKbdEnabled "30", "0", 1, 1
  22. .WaitForEvent rcEnterPos, "30", "0", 5, 9
  23. .waitForDisplayString "******","30", 5, 2
  24. .TransmitTerminalkey rcIBMHomeKey
  25. else
  26. .TransmitANSI "top"
  27. end if
  28. .TransmitTerminalkey rcIBMEnterKey
Sep 3 '07 #4

Expert 5K+
P: 8,434
It is standard practice to indent the lines of code that are dependent on an IF condition. In other words...
Expand|Select|Wrap|Line Numbers
  1. If <condition> Then
  2.     Do something
  3. Else
  4.     Do something different
  5. End If
To split the condition from the actual IF though, I believe you would have to use the line continuation character (_), such as...
Expand|Select|Wrap|Line Numbers
  1. If _
  2.     .WaitForEvent rcEnterPos,= "30", "0", 6, 53 Then
However, I fail to see what purpose this serves, apart from the purely cosmetic one of making the lines a bit shorter.
Sep 4 '07 #5

P: 13
thanks but still having trouble I will start from the beginning to make it easier.

I made a macro to sort a form and it works fine as long as every thing that it searches for is there to find. If not it times out waiting for an event. I do not know VB, The only reason I put the [ ] around [rcEnterPos, "30", "0", 6, 53] was because every time it hit a , or " it gave me an error "expected then or goto".

An if I do get the punctuation so the lines do not turn red it highlights ".WaitForEvent" and says "argument not optional" what I am trying to do is after it searches for "R8002" and does not find it that it continues after the ELSE line without a time out. The argument i was trying to do is If waitforevent is = to the cursor Position Then continue to the next line and if not goto the line after Else. The reason I put the if statment where i did is because this is where it turns yellow in debug mode after the time out.

IF statement starts on line 107
ELSE on line 144

if it helps

waitForEvent = (event as long,TimeOut as String, Duration As Long Col As Long)

rcEnterPos = cursor enters Position




Expand|Select|Wrap|Line Numbers
  1. Sub FidSort124()
  2. '
  3. ' Generated by the Reflection Macro Recorder on 08-04-2007  23:02:52.74
  4. ' Generated by Reflection for IBM for Windows 10.0.244
  5. '
  6.     With Session
  7.         .WaitForEvent rcEnterPos, "30", "0", 4, 15
  8.         .WaitForDisplayString "===>", "30", 4, 10
  9.         .TransmitTerminalKey rcIBMTabKey
  10.         .TransmitANSI "csr "
  11.         .TransmitTerminalKey rcIBMHomeKey
  12.         .WaitForEvent rcEnterPos, "30", "0", 4, 15
  13.         .WaitForDisplayString "===>", "30", 4, 10
  14.         .TransmitANSI "f ""end of order filling"""
  15.         .TransmitTerminalKey rcIBMEnterKey
  16.         .WaitForEvent rcKbdEnabled, "30", "0", 1, 1
  17.         .WaitForEvent rcEnterPos, "30", "0", 6, 16
  18.         .WaitForDisplayString "-", "30", 6, 9
  19.         .TransmitTerminalKey rcIBMNewLineKey
  20.         .TransmitTerminalKey rcIBMNewLineKey
  21.         .TransmitANSI "dd"
  22.         .TransmitTerminalKey rcIBMEnterKey
  23.         .WaitForEvent rcKbdEnabled, "30", "0", 1, 1
  24.         .WaitForEvent rcEnterPos, "30", "0", 8, 2
  25.         .TransmitTerminalKey rcIBMHomeKey
  26.         .TransmitANSI "bottom"
  27.         .TransmitTerminalKey rcIBMEnterKey
  28.         .WaitForEvent rcKbdEnabled, "30", "0", 1, 1
  29.         .WaitForEvent rcEnterPos, "30", "0", 4, 15
  30.         .WaitForDisplayString "===>", "30", 4, 10
  31.         .TransmitTerminalKey rcIBMNewLineKey
  32.         .TransmitTerminalKey rcIBMNewLineKey
  33.         .TransmitTerminalKey rcIBMNewLineKey
  34.         .TransmitTerminalKey rcIBMNewLineKey
  35.         .TransmitTerminalKey rcIBMNewLineKey
  36.         .TransmitTerminalKey rcIBMNewLineKey
  37.         .TransmitTerminalKey rcIBMNewLineKey
  38.         .TransmitTerminalKey rcIBMNewLineKey
  39.         .TransmitTerminalKey rcIBMNewLineKey
  40.         .TransmitTerminalKey rcIBMNewLineKey
  41.         .TransmitTerminalKey rcIBMNewLineKey
  42.         .TransmitTerminalKey rcIBMNewLineKey
  43.         .TransmitTerminalKey rcIBMNewLineKey
  44.         .TransmitTerminalKey rcIBMNewLineKey
  45.         .TransmitTerminalKey rcIBMNewLineKey
  46.         .TransmitTerminalKey rcIBMNewLineKey
  47.         .TransmitTerminalKey rcIBMNewLineKey
  48.         .TransmitTerminalKey rcIBMNewLineKey
  49.         .TransmitTerminalKey rcIBMNewLineKey
  50.         .TransmitANSI "dd"
  51.         .TransmitTerminalKey rcIBMEnterKey
  52.         .WaitForEvent rcKbdEnabled, "30", "0", 1, 1
  53.         .WaitForEvent rcEnterPos, "30", "0", 5, 9
  54.         .WaitForDisplayString "******", "30", 5, 2
  55.         .TransmitTerminalKey rcIBMHomeKey
  56.         .TransmitANSI "top"
  57.         .TransmitTerminalKey rcIBMEnterKey
  58.         .WaitForEvent rcKbdEnabled, "30", "0", 1, 1
  59.         .WaitForEvent rcEnterPos, "30", "0", 4, 15
  60.         .WaitForDisplayString "===>", "30", 4, 10
  61.         .TransmitANSI "sort 45"
  62.         .TransmitTerminalKey rcIBMEnterKey
  63.         .WaitForEvent rcKbdEnabled, "30", "0", 1, 1
  64.         .WaitForEvent rcEnterPos, "30", "0", 4, 15
  65.         .WaitForDisplayString "===>", "30", 4, 10
  66.         .TransmitTerminalKey rcIBMNewLineKey
  67.         .TransmitTerminalKey rcIBMNewLineKey
  68.         .TransmitTerminalKey rcIBMNewLineKey
  69.         .TransmitTerminalKey rcIBMNewLineKey
  70.         .TransmitTerminalKey rcIBMNewLineKey
  71.         .TransmitTerminalKey rcIBMNewLineKey
  72.         .TransmitTerminalKey rcIBMNewLineKey
  73.         .TransmitTerminalKey rcIBMNewLineKey
  74.         .TransmitTerminalKey rcIBMNewLineKey
  75.         .TransmitTerminalKey rcIBMNewLineKey
  76.         .TransmitTerminalKey rcIBMNewLineKey
  77.         .TransmitTerminalKey rcIBMNewLineKey
  78.         .TransmitANSI "dd"
  79.         .TransmitTerminalKey rcIBMEnterKey
  80.         .WaitForEvent rcKbdEnabled, "30", "0", 1, 1
  81.         .WaitForEvent rcEnterPos, "30", "0", 16, 2
  82.         .TransmitTerminalKey rcIBMHomeKey
  83.         .TransmitANSI "f r8000"
  84.         .TransmitTerminalKey rcIBMEnterKey
  85.         .WaitForEvent rcKbdEnabled, "30", "0", 1, 1
  86.         .WaitForEvent rcEnterPos, "30", "0", 6, 53
  87.         .TransmitTerminalKey rcIBMNewLineKey
  88.         .TransmitTerminalKey rcIBMUpKey
  89.         .TransmitTerminalKey rcIBMUpKey
  90.         .TransmitANSI "dd"
  91.         .TransmitTerminalKey rcIBMEnterKey
  92.         .WaitForEvent rcKbdEnabled, "30", "0", 1, 1
  93.         .WaitForEvent rcEnterPos, "30", "0", 5, 11
  94.         .TransmitTerminalKey rcIBMHomeKey
  95.         .TransmitANSI "bottom"
  96.         .TransmitTerminalKey rcIBMEnterKey
  97.         .WaitForEvent rcKbdEnabled, "30", "0", 1, 1
  98.         .WaitForEvent rcEnterPos, "30", "0", 4, 15
  99.         .WaitForDisplayString "===>", "30", 4, 10
  100.         .TransmitTerminalKey rcIBMPf8Key
  101.         .WaitForEvent rcKbdEnabled, "30", "0", 1, 1
  102.         .WaitForEvent rcEnterPos, "30", "0", 4, 15
  103.         .WaitForDisplayString "===>", "30", 4, 10
  104.         .TransmitANSI "f r8002 prev"
  105.         .TransmitTerminalKey rcIBMEnterKey
  106.         .WaitForEvent rcKbdEnabled, "30", "0", 1, 1
  107.         If _
  108.             .WaitForEvent = [rcEnterPos, "30", "0", 6, 53] Then
  109.         .TransmitTerminalKey rcIBMNewLineKey
  110.         .TransmitANSI "dd"
  111.         .TransmitTerminalKey rcIBMEnterKey
  112.         .WaitForEvent rcKbdEnabled, "30", "0", 1, 1
  113.         .WaitForEvent rcEnterPos, "30", "0", 7, 2
  114.         .TransmitTerminalKey rcIBMHomeKey
  115.         .TransmitANSI "bottom"
  116.         .TransmitTerminalKey rcIBMEnterKey
  117.         .WaitForEvent rcKbdEnabled, "30", "0", 1, 1
  118.         .WaitForEvent rcEnterPos, "30", "0", 4, 15
  119.         .WaitForDisplayString "===>", "30", 4, 10
  120.         .TransmitTerminalKey rcIBMNewLineKey
  121.         .TransmitTerminalKey rcIBMNewLineKey
  122.         .TransmitTerminalKey rcIBMNewLineKey
  123.         .TransmitTerminalKey rcIBMNewLineKey
  124.         .TransmitTerminalKey rcIBMNewLineKey
  125.         .TransmitTerminalKey rcIBMNewLineKey
  126.         .TransmitTerminalKey rcIBMNewLineKey
  127.         .TransmitTerminalKey rcIBMNewLineKey
  128.         .TransmitTerminalKey rcIBMNewLineKey
  129.         .TransmitTerminalKey rcIBMNewLineKey
  130.         .TransmitTerminalKey rcIBMNewLineKey
  131.         .TransmitTerminalKey rcIBMNewLineKey
  132.         .TransmitTerminalKey rcIBMNewLineKey
  133.         .TransmitTerminalKey rcIBMNewLineKey
  134.         .TransmitTerminalKey rcIBMNewLineKey
  135.         .TransmitTerminalKey rcIBMNewLineKey
  136.         .TransmitTerminalKey rcIBMNewLineKey
  137.         .TransmitTerminalKey rcIBMNewLineKey
  138.         .TransmitTerminalKey rcIBMNewLineKey
  139.         .TransmitANSI "dd"
  140.         .TransmitTerminalKey rcIBMEnterKey
  141.         .WaitForEvent rcKbdEnabled, "30", "0", 1, 1
  142.         .WaitForEvent rcEnterPos, "30", "0", 5, 9
  143.         .WaitForDisplayString "******", "30", 5, 2
  144.         Else _
  145.             :.TransmitTerminalKey rcIBMHomeKey
  146.         .TransmitANSI "top"
  147.         .TransmitTerminalKey rcIBMEnterKey
  148.         .WaitForEvent rcKbdEnabled, "30", "0", 1, 1
  149.         .WaitForEvent rcEnterPos, "30", "0", 4, 15
  150.         .WaitForDisplayString "===>", "30", 4, 10
  151.         .TransmitANSI "sort 124"
  152.         .TransmitTerminalKey rcIBMEnterKey
  153.         .WaitForEvent rcKbdEnabled, "30", "0", 1, 1
  154.         .WaitForEvent rcEnterPos, "30", "0", 4, 15
  155.         .WaitForDisplayString "===>", "30", 4, 10
  156.         .TransmitTerminalKey rcIBMNewLineKey
  157.         .TransmitTerminalKey rcIBMNewLineKey
  158.         .TransmitTerminalKey rcIBMNewLineKey
  159.         .TransmitTerminalKey rcIBMNewLineKey
  160.         .TransmitTerminalKey rcIBMNewLineKey
  161.         .TransmitTerminalKey rcIBMNewLineKey
  162.         .TransmitTerminalKey rcIBMNewLineKey
  163.         .TransmitTerminalKey rcIBMNewLineKey
  164.         .TransmitTerminalKey rcIBMNewLineKey
  165.         .TransmitTerminalKey rcIBMTabKey
  166.         .TransmitTerminalKey rcIBMRightKey
  167.         .TransmitTerminalKey rcIBMRightKey
  168.         .TransmitTerminalKey rcIBMRightKey
  169.         .TransmitTerminalKey rcIBMRightKey
  170.         .TransmitTerminalKey rcIBMRightKey
  171.         .TransmitTerminalKey rcIBMRightKey
  172.         .TransmitTerminalKey rcIBMRightKey
  173.         .TransmitTerminalKey rcIBMRightKey
  174.         .TransmitTerminalKey rcIBMRightKey
  175.         .TransmitTerminalKey rcIBMRightKey
  176.         .TransmitANSI "FidSort "
  177.         .TransmitANSI (Now)
  178.         .TransmitTerminalKey rcIBMHomeKey
  179.         .WaitForEvent rcEnterPos, "30", "0", 4, 15
  180.         .WaitForDisplayString "===>", "30", 4, 10
  181.         .TransmitANSI "save"
  182.         .TransmitTerminalKey rcIBMEnterKey
  183.         .WaitForEvent rcKbdEnabled, "30", "0", 1, 1
  184.         .WaitForEvent rcEnterPos, "30", "0", 4, 15
  185.         .WaitForDisplayString "===>", "30", 4, 10
  186.         .TransmitANSI "prn 1 s8"
  187.         .TransmitTerminalKey rcIBMEnterKey
  188.         .WaitForEvent rcKbdEnabled, "30", "0", 1, 1
  189.         .WaitForEvent rcEnterPos, "30", "0", 4, 15
  190.         .WaitForDisplayString "===>", "30", 4, 10
  191.         .TransmitANSI "=9.onfbrat"
  192.         .TransmitTerminalKey rcIBMEnterKey
  193.           End If   
  194.     End With
  195. End Sub
Sep 10 '07 #6

P: 13
do i have to put something after the then to make it goto the next line? or does it just know to do that?

the only other way i can think of is to try is GOTO statement but from what a read it is not good to use them?

is there any other simple ways to make jumps in lines other than if, then. else?
Sep 11 '07 #7

P: 13
what about if waitForEvent = true then. do i have to put a goto after then or will it just go to the next line?
Sep 14 '07 #8

Expert 5K+
P: 8,434
Sorry, I haven't really been following this thread, largely because so much of the syntax looks unfamiliar. I'm not familiar with WaitForEvent and so on. What version of VB are you using, and what does all this relate to? In other words, what is a "Session" object?

Um... actually, you said that it was a macro. In what product?

As for the If/Then business, VB (or any language which includes this structure) will automatically follow the appropriate path through an IF...ELSE...END IF block. If the IF condition is True, it will execute the code following THEN. Otherwise, it will execute the code (if any) following ELSE. It will always either the True block or, if present, the False block. There is no need to "tell it" to go on to the next statement.

I suspect any confusion may arise from the nature of the WaitForEvent function (or method, or whatever it is). To judge from it's name, it will stop and wait for an event to occur. If that event never occurs, then maybe it will continue to wait forever. However, with parameters called "Timeout" and "Duration", it seems as though you should be able to control that. Most likely, if it times out, that is when you would hit the False condition and thus execute the Else block.

Most languages support a number of statements which control the flow of execution (or "make jumps in lines").

The main ones which come to mind, with some examples, would be...
  • Branching
    • If/Else
    • Select Case
  • Looping
    • For...Next
    • For Each...Next (not the same thing, at all)
    • Do While...Loop
    • Do Until...Loop
    • While...Wend
The GOTO statement should rarely be required, and is widely seen as a sign of poor, or at least lazy, programming.
Sep 15 '07 #9

P: 13
"The Reflection object name (Application vs session)
In versions of Reflection prior to 7.0, all methods and properties acted on the
Application object. The newer Session object is now used in all help programming examples. However, if you are creating and/or maintaining Reflection Basic scripts,
you should continue to use Application for the Reflection object name."
not sure what that means but it came out of the manual.

I'm using VB6.

The product is Reflection for IBM.

It says in the manual

Programming language elements that are common to all implementations of BASIC include:
Data types, variable and constants, and arrays (declared with Dim and Const)
•Operators and expressions (such as +, -, *, /, Not, Like, and Or)
•User-defined functions and procedures (Sub and Function)
•Control structures and loops (such as For ... Next, Do ... Loop, and If ... Then ... Else)
Additional concepts in VBA and stand-alone Visual Basic include:
•Objects
•Forms
•Events

So i think it would work if i knew how to "declare" it with a Dim or Const.

if you could give me an example using my code that would be great.
Sep 19 '07 #10

Post your reply

Sign in to post your reply or Sign up for a free account.