Click here to Skip to main content
15,905,028 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Without Using Redim Or fixing the size at time of declaration Can anyone halp me with the following code which fixes the size at runtime...

VB
Dim arr() As String
For i as Integer=0 to 100
     arr(i)=" "
Next i


But It shows Error at: arr(i)=" "
Is there any method to overcome it without fixing the range of string array at time of declaration ?
Posted

with arrays you need to define the number of elements to it before hand

i.e.

dim arr(100) as string

for i as integer = 0 to 100
  arr(i)= i.tostring
next i
 
Share this answer
 
Comments
Be Yourself 17-Nov-10 6:39am    
Thanks ..
With using Redim and without hardcoding the array size and compile time, your only option, using arrays, is:
Dim myArray( i ) As String

where i is a variable that is set somewhere that contains of the size of the array at runtime.

You're other, and more flexible option, would be to use a generic collection of Strings.
Dim myStrings As New List(Of String)

There's no need to define its capacity at all.
 
Share this answer
 
Comments
Be Yourself 17-Nov-10 11:40am    
Thanks for reminding.
Nice Call..

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900