Reputation: 171
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 :) !
Upvotes: 0
Views: 1835
Reputation: 29006
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
Upvotes: 2