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.

asked Aug 18, 2011 at 10:43
2
  • Just tested it - doesn't work. Gives the following error message: Commandinfo: Argument 2 out of range. Any ideas? Commented 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. Commented 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

answered Aug 18, 2011 at 17:52

Your Answer

Draft saved
Draft discarded

Sign up or log in

Sign up using Google
Sign up using Email and Password

Post as a guest

Required, but never shown

Post as a guest

Required, but never shown

By clicking "Post Your Answer", you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.