• Support
  • Articles
  • Resources
  • Products

Dynamic Label Choice using ListBox

Moderator: boris

1 postPage 1 of 1

stevo
Newbie

Posts:
19
Joined: Tue Oct 15, 2013 11:08 pm
by stevo » Thu Jul 31, 2014 11:42 am
Here is how I dynamically choose a label or 'sub-routine' to call:

Code: Select all

  1. ; this is to test if we can assign a label name to a variable based on a condition and then goto whatever label name has been assigned to the variable
  2. closett
  3.  
  4. YesNoBox 'Do you want to run the Simple Example or the Complex Example?' 'Simple[Yes] or Complex[No]'
  5. if result=1 goto SimpleExample ; you chose 'Simple[Yes]'
  6. if result=0 goto ComplexExample ; you chose 'Complex[No]'
  7.  
  8. :SimpleExample
  9. strdim label 4
  10. label[0] = 'Label1'
  11. label[1] = 'Label2'
  12. label[2] = 'Label3'
  13. label[3] = 'Label4'
  14.  
  15. ListBox 'Please choose a label' 'Labels' label
  16. choice = result
  17. LabelChosen = label[choice]
  18. messagebox LabelChosen 'LabelChosen ='
  19.  
  20. sprintf2 gotoLabel 'goto %s' LabelChosen
  21. messagebox gotoLabel 'command: gotoLabel ='
  22. execcmnd gotoLabel
  23.  
  24. :Label1
  25. messagebox LabelChosen 'Which Label did we goto?'
  26. end
  27.  
  28. :Label2
  29. messagebox LabelChosen 'Which Label did we goto?'
  30. end
  31.  
  32. :Label3
  33. messagebox LabelChosen 'Which Label did we goto?'
  34. end
  35.  
  36. :Label4
  37. messagebox LabelChosen 'Which Label did we goto?'
  38. end
  39.  
  40. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  41. :ComplexExample
  42.  
  43. :CreateChoiceList
  44. Choices = 5
  45. strdim label Choices
  46. label[0] = 'Label1'
  47. label[1] = 'Label2'
  48. label[2] = 'Label3'
  49. label[3] = 'Label4'
  50. label[4] = 'Label5'
  51.  
  52. :ChoseInteractiveMode
  53. YesNoBox 'Do you want to run in INTERACTIVE mode?' 'Interactive[Yes] or Non-Interactive[No]'
  54. InteractiveMode = result
  55.  
  56. :CallInteractiveMode
  57. if InteractiveMode=1 call Interactive ; you chose 'Interactive[Yes]'
  58. if InteractiveMode=0 call NonInteractive ; you chose 'Non-Interactive[No]'
  59. messagebox 'RETURNed to CallInteractiveMode' 'Script is finished'
  60. END
  61.  
  62. :Interactive
  63. ListBox 'Please choose a label' 'Labels' label
  64. choice = result
  65. call GotoLabelChosen
  66. RETURN
  67.  
  68. :NonInteractive
  69. ; if you chose this option, then it will call all labels in succession
  70. For x 0 Choices-1
  71.     choice = x
  72.     call GotoLabelChosen
  73. Next
  74. RETURN
  75.  
  76. :GotoLabelChosen
  77. LabelChosen = label[choice]
  78. messagebox LabelChosen 'LabelChosen='
  79. sprintf2 callLabel 'call %s' LabelChosen
  80. messagebox callLabel 'callLabel='
  81. execcmnd callLabel
  82. RETURN ; to [Non]Interactive caller
  83.  
  84. :Label1
  85. sprintf2 title 'We went to Label %s' LabelChosen
  86. messagebox 'Command Group 1' title
  87. ; other commands here
  88. RETURN ; to GotoLabelChosen
  89.  
  90. :Label2
  91. sprintf2 title 'We went to Label %s' LabelChosen
  92. messagebox 'Command Group 2' title
  93. ; other commands here
  94. RETURN ; to GotoLabelChosen
  95.  
  96. :Label3
  97. sprintf2 title 'We went to Label %s' LabelChosen
  98. messagebox 'Command Group 3' title
  99. ; other commands here
  100. RETURN ; to GotoLabelChosen
  101.  
  102. :Label4
  103. sprintf2 title 'We went to Label %s' LabelChosen
  104. messagebox 'Command Group 4' title
  105. ; other commands here
  106. RETURN ; to GotoLabelChosen
  107.  
  108. :Label5
  109. sprintf2 title 'We went to Label %s' LabelChosen
  110. messagebox 'Command Group 5' title
  111. ; other commands here
  112. RETURN ; to GotoLabelChosen

Please post your comments and any inprovements. Enjoy! :smile:

1 postPage 1 of 1

Users browsing this forum: No registered users