• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 124
  • Last Modified:

How to store my buttons in an array

Hi all

I want to store my commandButtons in an array

Dim arrCmdButtons(11) As CommandButton

'-- initialize this array with command buttons

arrCmdButtons(0) = R_cmdAddGS
arrCmdButtons(1) = R_cmdRemoveGS
arrCmdButtons(2) = R_cmdUp
arrCmdButtons(3) = R_cmdDown
arrCmdButtons(4) = R_cmdBoarding
arrCmdButtons(5) = R_cmdGrooming
arrCmdButtons(6) = R_cmdEdit
arrCmdButtons(7) = R_cmdReserve
arrCmdButtons(8) = R_cmdTransac
arrCmdButtons(9) = R_cmdCancel
arrCmdButtons(10) = R_cmdBook

but I am getting the following: object or variable is not set.

What you think the problem is ?
0
Ramesh4u
Asked:
Ramesh4u
1 Solution
 
Éric MoreauSenior .Net ConsultantCommented:
because CommandButton are objects, you need to use SET:

SET arrCmdButtons(0) = R_cmdAddGS
0
 
leojlCommented:
hi ram,

The easy way to create a control array is in design mode
put the command button on the form.Name it
arrCmdButtons then set index = 0.


now you can add more buttons with Load as follows:

Private Sub Form_DblClick()
For i = 1 To 10
Load arrCmdButtons(i)
arrCmdButtons(i).Left = arrCmdButtons(i - 1).Left
arrCmdButtons(i).Top = arrCmdButtons(i - 1).Top + arrCmdButtons(i_1).Height
arrCmdButtons(i).Visible = True
Next
arrCmdButtons(1).Caption = "R_cmdRemoveGS"
' etc to put Captions on the buttons
End Sub

In design mode I set arrCmdButtons(0) = R_cmdAddGS

I just used Form_DblClick()to launch the Load thing.
You could launch it however you wish

0
 
Ramesh4uAuthor Commented:

Thank you emoreau
0

Featured Post

[Webinar] Kill tickets & tabs using PowerShell

Are you tired of cycling through the same browser tabs everyday to close the same repetitive tickets? In this webinar JumpCloud will show how you can leverage RESTful APIs to build your own PowerShell modules to kill tickets & tabs using the PowerShell command Invoke-RestMethod.

Tackle projects and never again get stuck behind a technical roadblock.
Join Now