473,386 Members | 1,715 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,386 software developers and data experts.

store several strings

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
Nov 21 '05 #1
4 1179
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.
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

Nov 21 '05 #2
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
"Maileen" wrote:
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

Nov 21 '05 #3

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" <no****@email.com> wrote in message
news:es**************@TK2MSFTNGP10.phx.gbl...
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

Nov 21 '05 #4
"Maileen" <no****@email.com> schrieb:
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
....
///

--
M S Herfried K. Wagner
M V P <URL:http://dotnet.mvps.org/>
V B <URL:http://dotnet.mvps.org/dotnet/faqs/>

Nov 21 '05 #5

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

7
by: news.hku.hk | last post by:
is there any way to make a loop to store strings?? e.g. abc.txt contains 3 lines i.e. this is line 1. this is line 2. this is line 3. i want to create a loop that can make the three strings...
7
by: Jenny | last post by:
Hi, I have a class foo which will construct some objects in my code. some of the objects store int values into the data deque, while others store float values to the deque. template <class...
12
by: arkobose | last post by:
my earlier post titled: "How to input strings of any lengths into arrays of type: char *array ?" seems to have created a confusion. therefore i paraphrase my problem below. consider the...
1
by: Kenny ODell | last post by:
I am struggling a bit with XML, even as I wade through endless help files and several books. I thought it would be useful to toss my particular needs to the group to see what you think is the best...
4
by: iwdu15 | last post by:
quick question for anyone who can help...im trying to mak a program that will take an entered username and store a list of teams they chose from a list and save that, to be called later. does...
5
by: Guadala Harry | last post by:
What are my options for *securely* storing/retrieving the ID and password used by an ASP.NET application for accessing a SQL Server (using SQL Server authentication)? Please note that this ID and...
17
by: Davíð Þórisson | last post by:
now in my web I have some global variables to be used in many different subpages, in the old ASP I simply loaded a variables.asp file into memory using the eval() function. Now I'd like to use XML...
2
by: Torben Laursen | last post by:
I handle errors in my code by using my own exception class that takes a number as argument to the constructor, and that number puts a string into the exception class. The user can then catch the...
3
by: M.-A. Lemburg | last post by:
On 2008-08-07 20:41, Laszlo Nagy wrote: 1 It also very fast at dumping/loading lists, tuples, dictionaries, floats, etc. -- Marc-Andre Lemburg eGenix.com
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.