chandu_kappa
asked on
VB - ARRAYS
i hv a problem see whether u could solve this
I hv an Array
dim sMyArray(100) as string
i hv to reinitilize this every time for some purpose
i.e putting this in a for loop
for i=0 to 100
sMyArray(i) = 0
next i
check it out is there any other way for this
I hv an Array
dim sMyArray(100) as string
i hv to reinitilize this every time for some purpose
i.e putting this in a for loop
for i=0 to 100
sMyArray(i) = 0
next i
check it out is there any other way for this
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
no i don't wana to redim the array just the value inside to be initilized
the situation is like this
declared an array as integer
dim iMyArray(100) as integer
dim i as integer
i hv to reinitilize this every time
i.e putting this in a for loop
for i=0 to 100
sMyArray(i) = 0
next i
check it out is there any other way ,to initialize other than FOR loop.i dont want to use loop.
get back immediately
the situation is like this
declared an array as integer
dim iMyArray(100) as integer
dim i as integer
i hv to reinitilize this every time
i.e putting this in a for loop
for i=0 to 100
sMyArray(i) = 0
next i
check it out is there any other way ,to initialize other than FOR loop.i dont want to use loop.
get back immediately
The array elements should already be initialised to zero. Try the following to prove this.
Create a form with a command button.
Dim iMyArray(100) As Integer
Private Sub Command1_Click()
intElement = Int(Rnd() * 100 + 1)
MsgBox (intElement & " = " & iMyArray(intElement))
End Sub
Each time you click the command button it displays the number and value of a randomly chosen element in your array. As you will see, without any loop they are already initialised to zero.
Create a form with a command button.
Dim iMyArray(100) As Integer
Private Sub Command1_Click()
intElement = Int(Rnd() * 100 + 1)
MsgBox (intElement & " = " & iMyArray(intElement))
End Sub
Each time you click the command button it displays the number and value of a randomly chosen element in your array. As you will see, without any loop they are already initialised to zero.
ASKER
i agree that
but i hv set it to some value
this particular array is in some function
and this function is repeatedly called
so instead of putting a big for loop i wanna in a shorter way
get back soon
but i hv set it to some value
this particular array is in some function
and this function is repeatedly called
so instead of putting a big for loop i wanna in a shorter way
get back soon
Then I think that you have encountered a "limitation" of VB. The only thing that I can suggest to help with this then is to move the array definition outside of the function. If you make the array public or at least private to the form then it can be initialised once only and used within one or more functions within the scope of the declaration.
ASKER
ok then.thanks a lot
ASKER
i agree that
but i hv set it to some value
this particular array is in some function
and this function is repeatedly called
so instead of putting a big for loop i wanna in a shorter way
get back soon
but i hv set it to some value
this particular array is in some function
and this function is repeatedly called
so instead of putting a big for loop i wanna in a shorter way
get back soon
The array is defined as a string - does it have to be initialised to the empty string ("") or to a string containing zero ("0") as indicated by your code.
If the former, try the following
Dim myArray() as string
.....
'wher you need to initialise the array, just redim it
Redim myArray(100)
Hope this helps