Defining the length of an array variably

G

Guest

Is it possible to define the length of an array using a varaible. I have
tried:

Public blnCheckBoxArray(intNumberCheckboxes) As Boolean

but I get error message saying that a fixed value is expected. I ought to be
possible. The integer intNumberCheckboxes is set in the beginning of the
program so it does not change when running. Should I write something like
ByVal? I do not know...Please help me on this one if you can!
 
A

Ardus Petus

You musr ReDim your array somewhere in your code:

'---------------------------------------------------------------
Public blnCheckBoxArray() As Boolean

Sub tester()
Dim intNumberCheckboxes As Integer

intNumberCheckboxes = 10
ReDim blnCheckBoxArray(intNumberCheckboxes)
End Sub

'---------------------------------------------------------------

HTH
 
K

Ken Johnson

franzklammer said:
Is it possible to define the length of an array using a varaible. I have
tried:

Public blnCheckBoxArray(intNumberCheckboxes) As Boolean

but I get error message saying that a fixed value is expected. I ought to be
possible. The integer intNumberCheckboxes is set in the beginning of the
program so it does not change when running. Should I write something like
ByVal? I do not know...Please help me on this one if you can!

Hi franzklammer,

I think you have to leave the brackets empty...

Public blnCheckBoxArray() As Boolean

then after the value of intNumberCheckboxes has been determined you use
the ReDim statement to get the array inplace...

ReDim blnCheckBoxArray(intNumberCheckboxes)

Ken Johnson
 
G

Guest

yes I have tried that. however I get the message: Complie error Matrix
dimension already set. Any clues? Please I just dont get it....

"Ardus Petus" skrev:
 
N

Norman Jones

Hi Franz,
yes I have tried that. however I get the message: Complie error Matrix
dimension already set. Any clues? Please I just dont get it....

Show the problematic code.

The error could be produced with code like:

'===============>>
Dim intNumberCheckboxes As Long
Dim blnCheckBoxArray(1 To 10)

intNumberCheckboxes = 10

ReDim blnCheckBoxArray(intNumberCheckboxes)
'<<===============

In which case either delete:

Dim blnCheckBoxArray(1 To 10)

or replace it with:

Dim blnCheckBoxArray()
 

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

Similar Threads

Array dimension 1
Defining variables 14
array within array 3
CSE with function returning an array? 2
length of an array 3
len of item in an array 3
Declare a Public Array 5
Variably sized instances of a class 7

Top