-
Feb 5th, 2021, 04:42 AM
#1
Thread Starter
PowerPoster
[RESOLVED] FILL ARRAY problem
pseudo code:
DIM MIO_ARRAY() AS VARIANT
...
C = 0
Do While Not RS.EOF
C = C + 1
COLA = RS.Fields("COD").Value
MIO_ARRAY(C) = COLA
C=C+1
COLB = RS.Fields("COD1").Value
MIO_ARRAY(C) = COLB
....
COLZ = RS.Fields("COD78").Value
MIO_ARRAY(C) = COLZ
rs.movenext
loop
....
have error: Subscript out of range
NOTE:
The numbers of recordset are variable
Last edited by luca90; Feb 5th, 2021 at 04:52 AM.
-
Feb 5th, 2021, 05:00 AM
#2
Re: FILL ARRAY problem
Aircode
Code:
rs.movelast
ReDim MIO_ARRAY(1 To 2*rs.Recordcount)
rs.movefirst
Do While Not rs.eof
'blablablabla
Last edited by Zvoni; Tomorrow at 31:69 PM.
----------------------------------------------------------------------------------------
One System to rule them all, One Code to find them,
One IDE to bring them all, and to the Framework bind them,
in the Land of Redmond, where the Windows lie
---------------------------------------------------------------------------------
People call me crazy because i'm jumping out of perfectly fine airplanes.
---------------------------------------------------------------------------------
Code is like a joke: If you have to explain it, it's bad
-
Feb 5th, 2021, 08:56 AM
#3
Re: FILL ARRAY problem
Building the array dynamically is an easy cheat
Code:
Sub push(ary, value) 'this modifies parent ary object
On Error GoTo init
Dim x As Long
x = UBound(ary) 'Error If Not initalized
ReDim Preserve ary(UBound(ary) + 1)
ary(UBound(ary)) = value
Exit Sub
init: ReDim ary(0): ary(0) = value
End Sub
Private Sub Form_Load()
Dim x() As Variant
push x, 1
push x, 2
Debug.Print UBound(x) & " x(1) = " & x(1)
End Sub
I would probably build a class to hold the columns with public properties for each field so you had intellisense.
Hold each class instance in a collection
and then have a class.Init(rs) method to have it load itself from the current record.
Code:
Dim records as new collection
dim record as CRecord
while not rs.eof
set record = new CRecord
record.init(rs)
records.add record
rs.movenext
wend
'class CRecord
'------------------------
public COD as Variant
friend Sub Init(rs as recordset)
me.COD = rs("COD").value
...
end sub
Last edited by dz32; Feb 5th, 2021 at 09:01 AM.
-
Feb 5th, 2021, 09:51 AM
#4
Re: FILL ARRAY problem
"Do While Not End" is a silly double-negative. Use "Do Until End" instead.
-
Feb 5th, 2021, 10:01 AM
#5
Thread Starter
PowerPoster
Re: FILL ARRAY problem
Originally Posted by dilettante
"Do While Not End" is a silly double-negative. Use "Do Until End" instead.
Never used...
Example please.
-
Feb 5th, 2021, 10:06 AM
#6
Re: FILL ARRAY problem
Just replace "While" with "Until" and then drop the "Not" from the expression which follows.
-
Feb 5th, 2021, 10:09 AM
#7
Thread Starter
PowerPoster
Re: FILL ARRAY problem
Originally Posted by dilettante
Just replace "While" with "Until" and then drop the "Not" from the expression which follows.
Do Until RS.EOF
...
loop
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|