• Log in or sign up for an account here: https://www.sythe.org/login

One dimensional array

  • Thread starter Thread starter tcraw9
  • Start date Start date
T

tcraw9

Guest
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.
 
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.
 
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.
 
Member of the Month Winner
Sythe's 10th Anniversary
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.
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.
 
Back
Top