store several strings

  • Thread starter Thread starter Maileen
  • Start date Start date
M

Maileen

Hi,

I would like to do something like in C++.
I would like to store several strings, integer,... in something which
should be like a vector, or list.

ex :
"line1","test",5
"line2","good",91
"line3","bad",41

how can i do this in VB.NET ?

thx,
Maileen
 
Hello Maileen,

I'd create a class like the following to represent the data.

Public Class MyData
Public Sub New(ByVal DataOne As String, ByVal DataTwo As String, ByVal
DataThree As Integer)
_DataOne = DataOne
_DataTwo = DataTwo
_DataThree = DataThree
End Sub

Private _DataOne As String
Public Property DataOne As String
Get
Return _DataOne
End Get
Set (ByVal Value As String)
_DataOne = Value
End Set
End Property

Private _DataTwo As String
Public Property DataTwo As String
Get
Return _DataTwo
End Get
Set (ByVal Value As String)
_DataTwo = Value
End Set
End Property

Private _DataThree As Integer
Public Property DataThree As Integer
Get
Return _DataThree
End Get
Set (ByVal Value As Integer)
_DataThree = Value
End Set
End Property
End Class

And then, just dump the object to ArrayList. When you want to use the list,
just do For Each data As MyData In MyArrayList and then, you'll be good to
go.
 
The Datatable offers an elegant feature rich solution. It contains Row and
Column objects that are easy to code and navigate.

'Declare a datarow
Dim dr As DataRow
'Declare, instantiate a datatable
Dim dt As New DataTable()
'Add Columns to the datatable
dt.Columns.Add("ItemKey", Type.GetType("System.Int32"))
dt.Columns.Add("ItemDescr", Type.GetType("System.String"))
'Declare and set an array of datacolumns to set as primary key (just
the first col in this case)
Dim pk() As DataColumn = {dt.Columns(0)}
dt.PrimaryKey = pk
'Instantiate a datarow using the structure of the datatable
dr = dt.NewRow
'Set the field values in the datarow
dr.Item("ItemKey") = 1
dr.Item("ItemDescr") = "New Item Described"
'Add the row to the datatable
dt.Rows.Add(dr)
'For illustration purposes, create a second datarow
Dim dr2 As DataRow
'To get a single row in the datatable, use method dt.rows.find(pk
value)
dr2 = dt.Rows.Find(1)
MessageBox.Show(dr2.Item(1))

www.charlesfarriersoftware.com
 
A less code and memory intesive method would be to simply create a value
type (Structure keyword) and then use it in an Array, ArrayList, Collection
or Hastable.

Robby
 
Maileen said:
I would like to do something like in C++.
I would like to store several strings, integer,... in something which
should be like a vector, or list.

ex :
"line1","test",5
"line2","good",91
"line3","bad",41

how can i do this in VB.NET ?

You can use a class or structure for storing the "records", and then use an
array (or an arraylist, for example) to build a list of items:

\\\
Public Structure Item
Public Bla As String
Public Goo As String
Public Number As String
End Structure
..
..
..
Dim Items(10) As Item
....
///
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Back
Top