VB.NET- Enter values in an array

1

I'm making a one-dimensional array of size N (this value is entered by the user in a textbox) in Visual Basic.net. Now I want to enter the numbers to the arrangement but I can not find anywhere to do it from a textbox or a window appears and go asking for the numbers according to the size that was assigned to the arrangement.

Can someone give me an example of how to enter the values and store them and then do an operation with them?

This is the only thing I found on the internet on the subject, I applied it to what I need but it does not work:

    Private Sub Button2_Click(sender As Object, e As EventArgs) Handles 
    Button2.Click
    Dim N As Integer
    Dim V(N)
    Dim i As Integer

    Console.WriteLine("Ingrese los valores para V")
    For i = 0 To V.Length
        V(i) = Console.ReadLine
    Next i
End Sub
    
asked by Iraida Mercedes 02.05.2017 в 18:21
source

1 answer

1

The creation of Array would be as follows:

Dim tamanio As Integer = 20
Dim array(tamanio) As String 

To insert values in Array simply use:

array(posicion) = valor 

Example:

array(3) = 45

You can help with a InputBox to go asking for the different values of the array according to the size of it:

For cont As Integer = 0 To tamanio - 1
    array(cont) = InputBox("Introduce valor", "Introduce valor para Array", "")
Next

To show the result in a dialog with all the elements of array you can put:

MessageBox.Show(String.Join(".", array))
    
answered by 02.05.2017 / 18:31
source