• Support
  • Articles
  • Resources
  • Products

Multiple Sub Routine Call and Return points ('compound' sub routine)

Moderator: boris

2 postsPage 1 of 1

stevo
Newbie

Posts:
19
Joined: Tue Oct 15, 2013 11:08 pm
by stevo » Wed Dec 16, 2015 11:04 pm
You can cross multiple Sub routines and Return/Exit points.
You might want to assign different values or use different variables based on different calling criteria.

Thanks Boris and The TeraTerm Project!

I hope you find this interesting and useful :)

Code: Select all

  1.  
  2. CLOSETT ; not needed for testing
  3. ;=================================================================================
  4. :Main
  5.     TRUE  = 1
  6.     FALSE = 0
  7.    
  8.     For x 1 5
  9.         THISCALLED = TRUE
  10.         if x = 1 || x = 2 call Sub1
  11.         if x = 3 || x = 4 call Sub2
  12.         if x = 5 call Sub3
  13.         messagebox msg 'msg'
  14.     Next
  15.    
  16.     messagebox 'If you see this without seeing any errors, then it works! You can have multiple "RETURN" points within a single subroutine' 'SUCCESS!! :)'
  17. END
  18. ;=================================================================================
  19. ; 'COMPOUND' SUB-ROUTINE - mulitple entry points and multiple exit/return points
  20. ;=================================================================================
  21. :Sub1
  22.     if THISCALLED = TRUE then ; if this is the Sub that was called, then this will be TRUE, else it will be FALSE
  23.         SUBCALLED = 'Sub1'
  24.         THISCALLED = FALSE
  25.     endif
  26. :Sub2
  27.     if THISCALLED = TRUE then
  28.         SUBCALLED = 'Sub2'
  29.         THISCALLED = FALSE
  30.     endif
  31. :Sub3
  32.     if THISCALLED = TRUE then
  33.         SUBCALLED = 'Sub3'
  34.         THISCALLED = FALSE
  35.     endif
  36.     ;-----------------------------------------------------------------------------
  37.    
  38.     if x = 1 || x = 3 then
  39.         Sprintf2 msg 'Sub Called = %s; x = %d; x is ODD' SUBCALLED x
  40.         RETURN
  41.     elseif x = 2 || x = 4 then
  42.         Sprintf2 msg 'Sub Called = %s; x = %d; x is EVEN' SUBCALLED x
  43.         RETURN
  44.     else
  45.         Sprintf2 msg 'Sub Called = %s; x = %d; x is FIVE' SUBCALLED x
  46.     endif
  47. RETURN
  48. ;=================================================================================
  49.  
boris
Moderator, LogMeTT and TTLEditor developer

Posts:
1591
Joined: Sat Jan 08, 2005 2:52 pm
by boris » Thu Dec 17, 2015 12:45 am
Tested, works perfectly. Thanks for sharing this, stevo!!

Best regards,
Boris
Display posts from previous:
Sort by:

2 postsPage 1 of 1

Users browsing this forum: No registered users