|
-
Mar 26th, 2004, 11:49 PM
#1
Thread Starter
Fanatic Member
uhh... total begginer question *RESLVED*
I feel sorta... emberresed asking this but umm....
well, with arrays... is there any way to put in datamanualy rather then having to do each spot at a time? Like you can in C++...
instead of
myArray(0) = ..
myArray(1) = ..
i want to do
myArray() = {"1","2"... "50"}
how can i do this?
Last edited by invitro; Mar 27th, 2004 at 12:48 AM.
ok, so... windows takes 1 minute to search for a file on my PC yet google.com takes 1 second to search the entire internet? 
-
Mar 27th, 2004, 12:27 AM
#2
Yes, you may do that in VB as well. Also array could be populated dynamically.
VB Code:
Private Sub Command1_Click()
Dim arNumbers(9) As Integer
Dim arNumbers2() As Integer
Dim vNumbers As Variant
Dim i%
ReDim arNumbers2(0)
For i = 0 To 9
arNumbers(i) = i
arNumbers2(UBound(arNumbers2)) = i
If i < 9 Then
ReDim Preserve arNumbers2(UBound(arNumbers2) + 1)
End If
Next i
'OR
vNumbers = Array(0, 1, 2, 3, 4, 5, 6, 7, 8, 9)
For i = 0 To 9
Debug.Print arNumbers(i)
Debug.Print arNumbers2(i)
Debug.Print vNumbers(i)
Next i
End Sub
-
Mar 27th, 2004, 12:31 AM
#3
Thread Starter
Fanatic Member
interesting... i could populate it dynamicaly if the values were constants going from 1 - whatever... however i was thinking of populating it with letters and such
I see that you are using a variant, then making the array object... how does the array object know what kind of an array it is?
eg, if i wanted it to be a string, byte, or int array... how would it know the difference? I guess bytes could be stored as int and then converted...
just curious
ok, so... windows takes 1 minute to search for a file on my PC yet google.com takes 1 second to search the entire internet? 
-
Mar 27th, 2004, 12:40 AM
#4
If you don't know the type then simply don't specify it ...
VB Code:
Private Sub Command1_Click()
Dim arTest()
Dim i%
ReDim arTest(0)
For i = 0 To 9
If i Mod 2 = 0 Then
arTest(UBound(arTest)) = i
Else
arTest(UBound(arTest)) = Chr(i + 65)
End If
If i < 9 Then
ReDim Preserve arTest(UBound(arTest) + 1)
End If
Next i
For i = 0 To 9
Debug.Print arTest(i)
Next i
End Sub
-
Mar 27th, 2004, 12:42 AM
#5
Thread Starter
Fanatic Member
ahh cool thanks, that answers my question! i feel much better now... totaly forgot about the Array() object!
thanks again
ok, so... windows takes 1 minute to search for a file on my PC yet google.com takes 1 second to search the entire internet? 
-
Mar 27th, 2004, 12:49 AM
#6
Not at all ...
One more thing to clarify: Array() is not an object - it's a function then returns a variant containing an array.
-
Mar 27th, 2004, 01:05 AM
#7
Thread Starter
Fanatic Member
Ahhh right right, use it in javascript all the time... not use to VB using variants
thanks!!!
ok, so... windows takes 1 minute to search for a file on my PC yet google.com takes 1 second to search the entire internet? 
-
Mar 27th, 2004, 09:15 AM
#8
Just be carefull with variants in VB development - not always reasonable (consuming alot more memory).
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
|