Results 1 to 8 of 8

Thread: uhh... total begginer question *RESLVED*

  1. #1

    Thread Starter
    Fanatic Member invitro's Avatar
    Join Date
    Jan 2000
    Location
    Outside your window
    Posts
    547

    Thumbs down 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?

  2. #2
    PowerPoster RhinoBull's Avatar
    Join Date
    Mar 2004
    Location
    New Amsterdam
    Posts
    24,132
    Yes, you may do that in VB as well. Also array could be populated dynamically.
    VB Code:
    1. Private Sub Command1_Click()
    2. Dim arNumbers(9) As Integer
    3. Dim arNumbers2() As Integer
    4. Dim vNumbers As Variant
    5. Dim i%
    6.  
    7.     ReDim arNumbers2(0)
    8.     For i = 0 To 9
    9.         arNumbers(i) = i
    10.         arNumbers2(UBound(arNumbers2)) = i
    11.         If i < 9 Then
    12.             ReDim Preserve arNumbers2(UBound(arNumbers2) + 1)
    13.         End If
    14.     Next i
    15.     'OR
    16.     vNumbers = Array(0, 1, 2, 3, 4, 5, 6, 7, 8, 9)
    17.     For i = 0 To 9
    18.         Debug.Print arNumbers(i)
    19.         Debug.Print arNumbers2(i)
    20.         Debug.Print vNumbers(i)
    21.     Next i
    22.  
    23. End Sub

  3. #3

    Thread Starter
    Fanatic Member invitro's Avatar
    Join Date
    Jan 2000
    Location
    Outside your window
    Posts
    547
    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?

  4. #4
    PowerPoster RhinoBull's Avatar
    Join Date
    Mar 2004
    Location
    New Amsterdam
    Posts
    24,132
    If you don't know the type then simply don't specify it ...
    VB Code:
    1. Private Sub Command1_Click()
    2. Dim arTest()
    3. Dim i%
    4.  
    5.     ReDim arTest(0)
    6.     For i = 0 To 9
    7.         If i Mod 2 = 0 Then
    8.             arTest(UBound(arTest)) = i
    9.         Else
    10.             arTest(UBound(arTest)) = Chr(i + 65)
    11.         End If
    12.         If i < 9 Then
    13.             ReDim Preserve arTest(UBound(arTest) + 1)
    14.         End If
    15.     Next i
    16.     For i = 0 To 9
    17.         Debug.Print arTest(i)
    18.     Next i
    19.  
    20. End Sub

  5. #5

    Thread Starter
    Fanatic Member invitro's Avatar
    Join Date
    Jan 2000
    Location
    Outside your window
    Posts
    547
    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?

  6. #6
    PowerPoster RhinoBull's Avatar
    Join Date
    Mar 2004
    Location
    New Amsterdam
    Posts
    24,132
    Not at all ...
    One more thing to clarify: Array() is not an object - it's a function then returns a variant containing an array.

  7. #7

    Thread Starter
    Fanatic Member invitro's Avatar
    Join Date
    Jan 2000
    Location
    Outside your window
    Posts
    547
    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?

  8. #8
    PowerPoster RhinoBull's Avatar
    Join Date
    Mar 2004
    Location
    New Amsterdam
    Posts
    24,132
    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
  •  



Click Here to Expand Forum to Full Width