Take the 2-minute tour ×
Geographic Information Systems Stack Exchange is a question and answer site for cartographers, geographers and GIS professionals. It's 100% free, no registration required.

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.

share|improve this question
    
Just tested it - doesn't work. Gives the following error message: Commandinfo: Argument 2 out of range. Any ideas? –  user21948 Sep 12 '13 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 '13 at 21:06

1 Answer 1

up vote 1 down vote accepted

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

share|improve this answer

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

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