PDA

View Full Version : really big multidimensional arrays in VB6


drunkmonkey
12-27-01, 08:55 AM
I need to make a multidimensional array with 5 dimensions, I tried using this code to declare it:
Dim maindata(0 To 5, 0 To 1, 0 To 99, 0 To 3, 0 To 99) As Long
And this code to insert a value:
maindata(tabnumsel, invorlab, quicka, quickb, quickc) = txtdata.Text
I get the error message "Sub or Function not defined". Can anyone help me???
tabnumsel, invorlab, etc. are variables in my program
:beer: :mad: :rolleyes: :cool: :D

badgers
01-01-02, 09:19 AM
first ensure that your variables are declared as integers for the array index points.

second you can try clng(txtdata.text)
this will force VB to convert the string to a long.
You dimensioned the variable maindata as a long.

also when you dim you can just use:
dim MainData(5,1,99,3,99) as Long
this works for me with a form, textbox, and command button:
Private Sub Command1_Click()
Dim MainData(5, 1, 99, 3, 99) As Long
Dim TabNumSel As Integer, InVorLab As Integer, QuickA As Integer
Dim QuickB As Integer, QuickC As Integer
MainData(TabNumSel, InVorLab, QuickA, QuickB, QuickC) = CLng(TxtData.Text)
MsgBox MainData(0, 0, 0, 0, 0)
End Sub


One thing if you are trying to make the array a PUBLIC declare you can't.
you have to declare the public array in a module and then refrence the array in the module. Don't ask me why it just works that way.


form code now:
Public i As Integer

Private Sub Command1_Click()
i = i + 1
Dim TabNumSel As Integer, InVorLab As Integer, QuickA As Integer
Dim QuickB As Integer, QuickC As Integer
Module1.MainData(TabNumSel + i, InVorLab, QuickA, QuickB, QuickC) = CLng(TxtData.Text)
MsgBox MainData(i, 0, 0, 0, 0)
End Sub

Module1 code is simple:
Public MainData(5, 1, 99, 3, 99) As Long

I just used the variable i to quickly test retaining data with repetitive calls to the routine.
hope this helps