VBA Arrays

  • Thread starter Roderick O'Regan
  • Start date
R

Roderick O'Regan

I've got a UserForm with a series of option buttons (I'm only using six here
but there could be up to 20) and have created an array for them.

Dim VarData(5) As Variant
VarData(0) = optRainbow
VarData(1) = optSmarties
VarData(2) = optMirage
VarData(3) = optGrass
VarData(4) = optClouds
VarData(5) = opt1Red

Using an If...Else if... statement might be OK for a few items but I believe
a Select Case would be better for larger quantities. (Am I correct?)

If I select one of the option buttons this will show which VarData array
variable is True. For the sake of argument, let's say that VarData(1) is
equal to True in this instance from my list above.

How could I use this value in a Select Case statement, perhaps, which if
VarData(1) is True it will indicate that a certain graphic is to be placed
in a document (e.g. c:\graphics\widget.jpg)?

I've written the array but cannot seem to harness the 'True' bit to an
expression.

Regards

Roderick O'Regan
 
P

Peter Hewett

Hi Roderick O'Regan

Using an array like this gets you nothing. You end up with big chunks of code
assigning OptionButton values to array elements, you then iterate through a loop
to find out which one was set! Why not use each OptionButtons Click event to
set a Private scope variable for the OptionButton group, or assign the name of
the graphic.

HTH + Cheers - Peter
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top