|
-
Jul 9th, 2001, 04:31 AM
#1
Thread Starter
Member
Can I declare an array with unknown size?
Can I declare an array with unknown size?
Such as:
Dim strCode() As String
-
Jul 9th, 2001, 04:33 AM
#2
Frenzied Member
Er.. Yes..! Then you use the Redim function to change the size of it at run time.
'Buzby'
Visual Basic Developer
"I'm moving to Theory. Everything works there."
-
Jul 9th, 2001, 04:37 AM
#3
Fanatic Member
yes, and just to add to Buzby's post, use ReDim Preserve to keep all your existing array elements when you extend your array
i.e.
Code:
Dim s() as String 'string array
Dim i%
for i = 1 to 10
ReDim Preserve s(i)
Next i
Crispin
VB6 ENT SP5
VB.NET
W2K ADV SVR SP3
WWW.BLOCKSOFT.CO.UK
[Microsoft Basic: 1976-2001, RIP]
-
Jul 9th, 2001, 04:38 AM
#4
Addicted Member
I posted this a bit late!
To add an item to the array you would have to ReDim the array and use "Preserve" to keep the values:
Code:
Dim strCode As String
Dim topVar As Integer
Dim i As Integer
Dim YourNum as Integer
For i = 1 To YourNum
topVar = UBound(strCode)+1
ReDim Preserve strCode(topVar) As String
strCode(topVar) = "This is the last item in the array"
Next
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
|