0

How can i do a Array with multiple Values in Vb.net ?

I have to add values to an array as like this: MyArray.Add(Article, Pieces, Price) and later I want to split them again like:

Label1.Text= MyArray.Article
Label2.Text= MyArray.Price

Thanks for every Answer :) !

1 Answer 1

2

Do something like this:

    Dim myArray As New ArrayList
    myArray.AddRange("Article,Pieces,Price".Split(","c))
    Label1.Text = myArray(0) 'gives you Article
    Label2.Text = myArray(1) 'gives you Pieces
    Label2.Text = myArray(2) 'gives you Price

Or else you can do this using list of objects also

Class Definition

Public Class book
    Public Article As String
    Public Pieces As Int32
    Public price As Double
End Class

Usage

    Dim BookList As New List(Of book)
    BookList.Add(New book() With {.Article = "someArticle", .Pieces = 12, .price = 20})
    BookList.Add(New book() With {.Article = "someArticle2", .Pieces = 6, .price = 20})
    Label1.Text = BookList(0).Article 'gives you Article name in the 0th index
    Label2.Text = BookList(0).Pieces 'gives you Pieces in the 0th index
    Label2.Text = BookList(0).price  'gives you Price in the 0th index
Sign up to request clarification or add additional context in comments.

3 Comments

Thanks :) How can i echo them with a for each loop ? When i try a simple for each loop then it echo all 2 times .. and only the first entry :o
i don't get your requirement clearly. are you using a console app?
Okey when i try to For Each lol In myArray MsgBox(myArray(0) & myArray(1) & myArray(2)) Next Then i only get eveytime the first Array Index

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.