One dimensional array

Discussion in 'Programming General' started by tcraw9, Jul 22, 2008.

One dimensional array
  1. Unread #1 - Jul 22, 2008 at 10:28 PM
  2. tcraw9
    Referrals:
    0

    tcraw9 Guest

    One dimensional array

    Im new to VB and am having a problem with arrays. I need to store values entered in a text box into a one dimensional array upon clicking an add button. When the values have been added to the array I am to click a separate button designated as the display button on the application and it should display the array within a list box. If anyone could give me any tips on this it would be appreciated.
     
  3. Unread #2 - Jul 23, 2008 at 11:32 AM
  4. Welshy
    Referrals:
    0

    Welshy Guest

    One dimensional array

    This is just a basic example of the idea, but you should be able to shape this into what you want.

    Code:
    Dim sArray() As String = {"This", "is", "my", "beautiful", "array"}
    Me.ListBox1.Items.AddRange(sArray)
    
    I'm new to VB.NET, as I'm used to programming in different languages, but I imagine you would be able to reference each item in the array like so.

    Code:
    sArray(0) ' This
    sArray(1) ' is
    sArray(2) ' my
    sArray(3) ' beautiful
                 ' and so on...
    
    So:

    Code:
    sArray(0) = tbTextbox.Text
    
    If that's not what you mean and I'm totally incorrect, just let me know.
     
  5. Unread #3 - Jul 23, 2008 at 8:12 PM
  6. tcraw9
    Referrals:
    0

    tcraw9 Guest

    One dimensional array

    That is kind of what im looking for, let me try and explain it a little clearer.
    The project specifies that the arrays are to store 10 elements.
    So the code for that would be:
    Dim sarray () as Integer = New Integer (0 to 9) {}
    For the project the user is suppost to be able to add any number(integer) they want into the text box on the form and it will be stored by the array when clicking an add button. Once 10 values have been stored a display button on the for is clicked and the values are presented in a list box. Can this be done without declaring any intializer values.
     
  7. Unread #4 - Jul 24, 2008 at 3:21 AM
  8. Swan
    Joined:
    Jan 23, 2007
    Posts:
    4,957
    Referrals:
    0
    Sythe Gold:
    0
    Sythe's 10th Anniversary Member of the Month Winner

    Swan When They Cry...
    Retired Global Moderator

    One dimensional array

    Ah, I love .Net's classes.

    Even though this is fairly simple, you can "save yourself a headache" and use the System.Collections.ArrayList class ;)

    I haven't worked with Visual Basic for a very long time, so I am unsure how to declare arrays; I use C-based languages a lot. Sorry.
     
< PrivateServer Programming. | Tab Control Add webbrowser (Code, tut) >

Users viewing this thread
1 guest


 
 
Adblock breaks this site