Results 1 to 4 of 4

Thread: How to learn ARRAY please..???

  1. #1

    Thread Starter
    Addicted Member
    Join Date
    Nov 2005
    Posts
    185

    How to learn ARRAY please..???

    Dear Experts,

    I am a VB newbie and just very the beginner...anyone knows the sources to learn ARRAYS please..???..the logic, theory and practicals..??

    Additionally, what is the best source to learn Visual Basic please..???

    Thanks a lot for your help..

    Jennifer

  2. #2
    PowerPoster jcis's Avatar
    Join Date
    Jan 2003
    Location
    Argentina
    Posts
    4,430

    Re: How to learn ARRAY please..???

    In the FAQs Forum you'll find an Arrays Tutorial by EyerMonkey

    Here is

  3. #3
    Fanatic Member paralinx's Avatar
    Join Date
    Jun 2005
    Location
    Michigan
    Posts
    987

    Re: How to learn ARRAY please..???

    The best way of learning visual basic, in my opinion, is being on these forums. If you go through and read some of the posts of code, you will learn a lot more than you would through a book. Because a book may have one expert, but here we have hundreds








    excluding me of course from the experts section

  4. #4
    Elite Hacker Jacob Roman's Avatar
    Join Date
    Aug 2004
    Location
    Miami Beach, FL
    Posts
    5,349

    Re: How to learn ARRAY please..???

    Zach, you don't have to post in these forums like it's an email. Just pretend you are talking like a normal person.

    The best way to learn VB is not so much the tutorials, forums, source code, and books, but mostly coding on your own. It's all about patience, and using logic. That's after you learn the basics of course.

    And to help solve your array problem, arrays are like variables, only they are somewhat like using multiple variables with the same name. Like for example:

    VB Code:
    1. Dim MyArray(9) As Long

    You now have an array called MyArray with 10 elements. Why 10 you ask? Because the elements range from 0 - 9. And if you count them, you will see that there are 10. You use the array like so, after declaring it:

    VB Code:
    1. Private Sub Form_Load()
    2.  
    3.     Dim MyArray(9) As Long
    4.  
    5.     MyArray(0) = 1
    6.     MyArray(1) = 3
    7.     MyArray(2) = 5
    8.  
    9.     MsgBox MyArray(0)
    10.  
    11. End Sub

    Another cool thing you can do to arrays is this:

    VB Code:
    1. Private Sub Form_Load()
    2.  
    3.     Dim MyArray() As Long 'No elements specified
    4.  
    5.     ReDim MyArray(9) As Long 'Now it has 10 elements
    6.  
    7. End Sub

    This comes in handy incase you don't know how many elements your array is gonna get. But this technique can erase all the data that was in your array. Here is what I mean:

    VB Code:
    1. Private Sub Form_Load()
    2.  
    3.     Dim MyArray() As Long 'No elements specified
    4.  
    5.     ReDim MyArray(9) As Long 'Now it has 10 elements
    6.  
    7.     MyArray(0) = 10
    8.  
    9.     ReDim MyArray(5) as Long
    10.  
    11.     MsgBox MyArray(0)
    12.  
    13. End Sub

    The output will be 0, cause it erased the entire array after it has been Redimensioned. So what you can do about this is use ReDim Preserve, so the data doesn't get erased:

    VB Code:
    1. Private Sub Form_Load()
    2.  
    3.     Dim MyArray() As Long 'No elements specified
    4.  
    5.     ReDim MyArray(9) As Long 'Now it has 10 elements
    6.  
    7.     MyArray(0) = 10
    8.  
    9.     ReDim Preserve MyArray(5) as Long 'Data has been preserved
    10.  
    11.     MsgBox MyArray(0)
    12.  
    13. End Sub

    And you should get 10 as a result. Also note that the arrays are linear in memory, and can come in handy working with the memory portion of them once you learn how to work with pointers.

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