help with arrays

  • Thread starter Thread starter mike
  • Start date Start date
M

mike

I am trying to create an array but am getting a data type
mismatch error on the ReDim statement. Can anyone tell me
why?

One other thing that may be important is that I have
declared Cust, DocNo, DrBr, etc as public variables at the
beginning of the module and assigned different data types
to the variables depending on the data in the particular
field.

Dim i As Integer
Dim Writeoffs()
JVCounter = 1
ReDim Writeoffs(1 To i, Cust, DocNo, DrBr, CrBr, _
DrAcctAmt, CrAcctAmt, DrAcctNo, CrAcctNo, Descr)

Any help would be greatly appreciated. Thanks.
 
I posted tested code that works based on your description. Frankly, the
code you show demonstrates you don't seem to have a concept of how to use
arrays or how they are dimensioned.

given those are your fields


Dim i As Integer
Dim Writeoffs()
Dim FieldNames as Variant
JVCounter = 1
FieldNames = Array("Cust", "DocNo", "DrBr", "CrBr":, _
"DrAcctAmt", "CrAcctAmt", "DrAcctNo", "CrAcctNo", "Descr")
numElem = Ubound(FieldNames,1) - Lbound(FieldNames,1) + 1
ReDim Writeoffs(1 To i, 1 to NumElem)

Would be the direction you are headed.

Think of the array being identical to the rows and cells of your speadsheet.
You spreadsheet has two dimensions; so does the array.

Your filed names would not be variables unless you are going to use
variables that just happen to share the name of the fields. (but for what
purpose it would be hard to fathom).
 
Your right. I am new to VBA and am trying to learn as
much as possible. I understand the concept of arrays and
how they can be used but I am having difficulty in how
they are dimensioned. If you can point me to a good
resource or reference, it would be greatly appreciated.
 
I post sample code specific to your situation that works. I gave you an
revised example of what you tried.

Perhaps looking at these and asking questions about what you don't
understand. There really isn't a whole lot of mystery to them, so you won't
find pages of information written on them.
 
Back
Top