|
-
Nov 12th, 2001, 10:06 PM
#1
Thread Starter
Fanatic Member
array help
VB Code:
Dim varPIEQTY()
Dim varpiei As Integer
For varpiei = 0 To 100
varPIEQTY(varpiei) = 0
Next varpiei
subscript out of range
on
"varPIEQTY(varpiei) = 0"
ideas?
i haven't worked too much with arrays, but im trying to assign the array varPIEQTY(0) all the way to varPIEQTY(100) all = 0
this because i'll be filling in randoms parts in the array, and it seems if i haven't declared varPIEQTY(40) = 0 and i don't have a varPIEQTY(0), i get an errror...
-
Nov 12th, 2001, 10:09 PM
#2
Member
You never allocated the space for the array:
VB Code:
Dim varPIEQTY(0 To 10)
' or
Dim varPIEQTY()
ReDim varPIEQTY(0 To 10)
-
Nov 12th, 2001, 10:10 PM
#3
Addicted Member
you have to 'resize' the array before adding to it... I added a line to bump up the array size every 'varpiei' loop...
Dim varPIEQTY()
Dim varpiei As Integer
For varpiei = 0 To 100
ReDim Preserve varPIEQTY(varpiei)
varPIEQTY(varpiei) = 0
Next varpiei
Rikk =\=
Starcraft, Protoss Scout Driver!
-
Nov 12th, 2001, 10:15 PM
#4
Thread Starter
Fanatic Member
-
Nov 13th, 2001, 01:35 AM
#5
PowerPoster
Hi
Definitely dont do Rikk's suggestion... follow the turtle 
Redim preserve is unnecessary in this situation and will slow down the array allocation considerably.
VB Code:
'In forms declaration area (ie top of form)
Dim varPIEQTY()
Dim varpiei As Integer
'Within the particular event
ReDim Preserve varPIEQTY(100) 'Outside of the loop
For varpiei = 0 To 100
varPIEQTY(varpiei) = 0
Next varpiei
PS If u only want to set all elements to zero (or "" for a string) u can simple use the Erase command which is much faster than a loop
Regards
Stuart
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
|