0

I would like to run a couple of similar command sequences from a menu in Lauterbach T32 (or even from the toolbar, the issue is the same). Menu is built using something like:

menu.reprogram
(
 add toolbar 
(
toolitem "Say NE", "SN,r"
(
GOSUB sayNE
)
)
)
enddo
sayNE:
(
print "ne"
return
)

According to documentation, this is supposed to work. Something similar works if I remove the menu.reprogram part and only run "gosub sayNE".

But when this code is supposed from the actual menu callback, it does NOT. It prints "no such label" error message which is not really helpful.

I have even trying moving the subroutine into an included file, which is sourced in via Do ~~~~/subSayNE.cmm followed by gosub .... The Do ... command works but calling gosub afterwards brings the same "no such label" error as before.

It looks like there is a restriction on what's allowed to do but I cannot find it documented. Is there any way to use subroutines there or is there any better trick to run repeated actions with only minor modifications (parameters)?

1 Answers1

3

The subroutines are only available during the time the script is executed. When script execution ends (in your case this happends with the ENDDO command), the labels/subroutines cease to exist.

A good solution for this problem is to equip the script with a calling parameter. When the script is called without parameter, the menu or toolbar is installed. If the script is called with a parameter, then the subroutine with the same name is called.

The user will install the menu/toolbar by calling the script without parametes, while the menu/toolbar item will call the script with the subroutine name as parameter.

PRIVATE &parameter
ENTRY %LINE &parameter
IF "&parameter"!=""
(
  ;if parameter specified, go to subroutine with that name
  GOSUB &parameter
  ENDDO
)
ELSE
(
  ;set up script caller
  PRIVATE &CALL
  &CALL="DO """+OS.PresentPracticeFile()+""" "

  ; "&+" in the menu means that macro &CALL will be replaced at compile time
  MENU.ReProgram
  (&+
    ADD
    TOOLBAR
    (
      TOOLITEM "Say NE" "SN,r"
      (
        ;call script with parameter SayNe
        &CALL SayNe
      )
    )
  )
  ENDDO
)

;subroutines
SayNe:
(
  PRINT "ne"
  RETURN
)
Reinhard Weiss
  • 426
  • 2
  • 4