1

I have following code :

Sub create_ButtonFromVendor
      Dim i As Integer
      i=1
      Create ButtonPad "allVendor"  As
        ToggleButton
        Icon MI_ICON_ZOOM_QUESTION
          Calling get_Vendor
          HelpMsg vendors(i)
        Show
       For i = 2 TO Ubound(vendors)
          Alter ButtonPad "allVendor" Add
          ToggleButton
          Icon MI_ICON_ZOOM_QUESTION
          Calling vendor_ButtonAction(vendors(i))
          HelpMsg vendors(i)
        Show
      Next
    End Sub

It is small sub procedure. Here I wanted to create multiple buttons with different function in a loop. How would I add function in a loop? In the code I added above does not work as handler must be sub procedure without parameter.

2
  • Just tested it - doesn't work. Gives the following error message: Commandinfo: Argument 2 out of range. Any ideas?
    – user21948
    Sep 12, 2013 at 20:28
  • Welcome to GIS SE! Our protocols can take a little getting used to so I hope you don't mind me pointing out that you have placed what looks like a comment in the area reserved for directly providing an Answer to the Question posed.
    – PolyGeo
    Sep 12, 2013 at 21:06

1 Answer 1

1

I would let the buttons call the same subprecedure ...

For i = 2 To Ubound(vendors)
    Alter ButtonPad "allVendor" Add
       ToggleButton
          ID 1000 + i
          Icon MI_ICON_ZOOM_QUESTION
          Calling vendor_ButtonAction
          HelpMsg vendors(i)
Next

and in the subprocedure use CommandInfo() to figure out what button the user clicked on ...

Sub vendor_ButtonAction
   Dim nVendorIndex As Integer

   nVendorIndex = (CommandInfo(CMD_INFO_TOOLBTN) - 1000)

   Note "You clicked on vendor " & vendors(nVendorIndex)

End Sub

I have not tested the code, so I can not guarantee that it works, but I'm sure you get the idea

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.