Shop OBEX P1 Docs P2 Docs Learn Events
for next inside gosub??? — Parallax Forums

for next inside gosub???

4 yrs later4 yrs later Posts: 14
edited 2007-05-21 03:22 in BASIC Stamp
Is it a no-no to place a for next loop inside a gosub on a bs2?
The program seems to stop executing at the return point.....

Comments

  • Bruce BatesBruce Bates Posts: 3,045
    edited 2007-05-18 19:53
    No, but make sure you have the appropriate RETURN statements in the subroutines, to match the GOSUB's.

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
  • 4 yrs later4 yrs later Posts: 14
    edited 2007-05-18 21:29
    AFAIK, all that's needed is a RETURN, and it should return to the next command following the GOSUB command.....

    the GOSUB executes, but it stops running just before (shown by debug onto LCD executing) and does not execute the RETURN, which brings it back to a SEROUT to the LCD with different debug text.
    hmmmm....
  • FranklinFranklin Posts: 4,747
    edited 2007-05-18 21:32
    Could we see some code?

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    - Stephen
  • 4 yrs later4 yrs later Posts: 14
    edited 2007-05-20 13:41
    Sorry for the delay.....have a look at this chunk attached.......pretty simple stuff methinks......
  • FranklinFranklin Posts: 4,747
    edited 2007-05-20 15:08
    fill_loop:
    received:
    z = 1
    FOR z = 1 TO 255
    SEROUT 1, 16780, [noparse][[/noparse]254,140] 'show iteration
    SEROUT 1, 16780, [noparse][[/noparse]DEC z]
    act_gas = 0
    ones = 0
    tens = 0
    huns = 0
    thous = 0
    SEROUT 2, 16780, [noparse][[/noparse]"P"] 'send command to fire output
    SERIN 0, 16780, [noparse][[/noparse]junk, junk, junk, junk, e, f, junk, h, i, junk, junk, junk] 'Read the running digits into variables. g should always be a decimal point
    LOOKDOWN i, [noparse][[/noparse]48, 49, 50, 51, 52, 53, 54, 55, 56, 57, 58], ones 'put CO2 ones ascii chars into single bytes representing decimal digits
    LOOKDOWN h, [noparse][[/noparse]48, 49, 50, 51, 52, 53, 54, 55, 56, 57, 58], tens 'put CO2 tens ascii chars into single bytes representing decimal digits
    LOOKDOWN f, [noparse][[/noparse]48, 49, 50, 51, 52, 53, 54, 55, 56, 57, 58], huns 'put CO2 hundreds ascii chars into single bytes representing decimal digits
    LOOKDOWN e, [noparse][[/noparse]48, 49, 50, 51, 52, 53, 54, 55, 56, 57, 58], thous ' thousands
    IF thous = 0 THEN z1digit
    act_gas = (thous * 1000) 'build running net fill
    act_gas = act_gas + (huns * 100)
    act_gas = act_gas + (tens * 10)
    act_gas = act_gas + ones
    IF z = 1 AND text_in1 = 0 THEN tareout
    

    I don't see tareout. If you break out of a gosub with a goto the return becomes invalid (as I understand it, but I'm more often shown my erroneous ways by TWKMTI (those who know more than I)

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    - Stephen
  • TechnoRobboTechnoRobbo Posts: 323
    edited 2007-05-20 16:16
    You seem to have several duplicate labels -(shortened_pulse, ret_valves, full,badn2). You have 1 FOR and 2 NEXT statements. Are the labels N2valve, limit_pulse, zerror, begin and ret_digit·defined in the beginning? Is all this suppose to fit in one stamp?

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    Have Fun


    TR

    Post Edited (TechnoRobbo) : 5/20/2007 4:24:58 PM GMT
  • 4 yrs later4 yrs later Posts: 14
    edited 2007-05-21 03:22
    Yes, this and more fits quite easily. It could be a bit cleaner with more variable space....

    I replaced the GOSUB with a GOTO, and it runs quite well. I would really rather use GOSUB.

    So, directing to a label outside the GOSUB will break the loop? interesting. Perhaps I should move tareout: inside the subroutine....
Sign In or Register to comment.