Adblock breaks this site

One dimensional array

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

  1. tcraw9

    tcraw9 Guest

    Referrals:
    0
    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.
     
  2. Welshy

    Welshy Guest

    Referrals:
    0
    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.
     
  3. tcraw9

    tcraw9 Guest

    Referrals:
    0
    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.
     
  4. Swan

    Swan When They Cry...
    Retired Global Moderator

    Joined:
    Jan 23, 2007
    Posts:
    4,957
    Referrals:
    0
    Sythe Gold:
    0
    Sythe's 10th Anniversary Member of the Month Winner
    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) >


 
 
Adblock breaks this site