Visual basic property setting and variables

  • Thread starter Thread starter Emyr Pugh
  • Start date Start date
E

Emyr Pugh

Is there any way to combine checkboxes with variables? Take for example
the following code:

CheckBox1.Caption = "This is CheckBox1"

but is there any way to refer to a non-specific checkbox e.g. CheckBox97
by using a variable. Something like this:

Checkbox(Variable).caption = "This is Checkbox ", variable

But this is not valid syntax, can anyone advise me as to the solution?
 
It sounds like you want a control array. If each checkbox has the same
control name then they are indexed as a control array. Then you would access
each individual checkbox using an index value. See the information about
control arrays in the VB/VBA Help. One place this won't work is in an
Outlook form, those controls don't support control arrays.
 
Thanks for your reply, can you show me how to define a control array
that will accept a numerical value. So that i can change the properties
of various checkboxes during runtime. The following code works:

Checkbox1.caption = "Whatever i want to change it to"

but how can i define a control array that will act as the checkbox1 part
of the above code?

do you know what i mean?

dim chkbox(i) as checkbox

or something like that? please help this is driving me insance
 
Please post parts of the preceding thread in your posts. Your interface
doesn't do that and it makes it very hard to follow a thread.

Nothing much to show. If I put a checkbox on a VB form as chkArray and then
add another checkbox and also name it chkArray then VB will ask you if you
want to create a control array. If you answer Yes then the first one will be
chkArray(1) and the second one will be chkArray(2) and so on. Then you
access the control you want as chkArray(1).Caption and so on.
 
Back
Top