I would like to store the array like as following
arItem(0,0)= "APPLE" <-- string
arItem(0,1)=30 <-- no of item , integer
arItem(1,0) = "ORANGE"
arItem(1,1) = 16
.....ETC
From the help , i know I can use arItem.setvalue("APPLE",0,0)... ETC
However, I don't know how to declare such array
Please help ~ 4 1276
Agnes,
Have you tried:
Dim arItem(9,1) As Object
arItem(0,0)= "APPLE" <-- string
arItem(0,1)=30 <-- no of item , integer
arItem(1,0) = "ORANGE"
arItem(1,1) = 16
...
arItem(9,0)= "Banana"
arItem(9,1)=30
However seeing as each row appears to be an object. I would consider
creating an array of Objects instead.
Something like:
Public Class Item
Private Readonly m_name As String
Private m_ount As Integer
Public Sub New(name As String, count As Integer)
m_name = name
m_count = count
End Sub
Public ReadOnly Property Name As string
Get
Return m_Name
End Get
End Property
Public Property Count As Integer
Get
Return m_count
End Get
Set(value As Integer)
m_count = value
End Set
End Property
...
End Class
Dim arItem(9) As Item
arItem(0) = New Item("Apple", 30)
arItem(1) = New Item("Orange", 16)
...
arItem(9) = New Item("Banana", 30)
Note, because Item is defined to be a class you need to initialize each row
of the array as I have done above. Once each row is initialized, you can use
the properties of Item to get at its values:
' sell an apple
arItem(0).Count -= 1
Hope this helps
Jay
"Agnes" <ag***@dynamictech.com.hk> wrote in message
news:uE**************@TK2MSFTNGP12.phx.gbl... I would like to store the array like as following arItem(0,0)= "APPLE" <-- string arItem(0,1)=30 <-- no of item , integer arItem(1,0) = "ORANGE" arItem(1,1) = 16 ....ETC From the help , i know I can use arItem.setvalue("APPLE",0,0)... ETC However, I don't know how to declare such array Please help ~
Agnes,
You have so often worked with a datatable. When an array get more dimensions
than that one is in my opinion one of the easiest one.
\\\
dim dt as new datatable
dt.columns.add("Fruit", gettype(system.string))
dt.columns.add("Value", gettype(system.Int32))
dim dr as datarow = dt.newrow
dr("Fruit") = "APPLE"
dr("Value")=30
dt.rows.add(dr)
dt.rows.add(dt.newrow)
dt.rows(1)(0) = "ORANGE"
dt.rows(1)(1) = 16
dt.rows.add(dt.newrow)
dt.rows(2).itemarray = new object() {"Citrus",20}
///
Etc in the way you like
I hope this helps?
Cor
"Agnes" <ag***@dynamictech.com.hk> I would like to store the array like as following arItem(0,0)= "APPLE" <-- string arItem(0,1)=30 <-- no of item , integer arItem(1,0) = "ORANGE" arItem(1,1) = 16 ....ETC From the help , i know I can use arItem.setvalue("APPLE",0,0)... ETC However, I don't know how to declare such array Please help ~
"Agnes" <ag***@dynamictech.com.hk> schrieb: I would like to store the array like as following arItem(0,0)= "APPLE" <-- string arItem(0,1)=30 <-- no of item , integer arItem(1,0) = "ORANGE" arItem(1,1) = 16 ....ETC From the help , i know I can use arItem.setvalue("APPLE",0,0)... ETC However, I don't know how to declare such array
Instead of using a 2-dimensional array here, I would use a 1-dimensional
array of instances of a class/structure:
\\\
Public Structure Item
Public Name As String
Public Number As Integer
End Structure
..
..
..
Dim a(90) As Item
For i As Integer = 0 To a.Length - 1
a(i).Name = ...
a(i).Number = ...
Next i
///
Notice that this is a very basic sample, if you are storing more data for
each object, consider using a class, and add properties instead of providing
direct access to the fields holding the attributes' values.
--
M S Herfried K. Wagner
M V P <URL:http://dotnet.mvps.org/>
V B <URL:http://dotnet.mvps.org/dotnet/faqs/>
Thanks All.
Dear Herfried K. Wanger,
I never know I can use 'structure' to do that , I learn one more new
thing. Thanks again
"Herfried K. Wagner [MVP]" <hi***************@gmx.at> ???
news:uT*************@TK2MSFTNGP12.phx.gbl ???... "Agnes" <ag***@dynamictech.com.hk> schrieb:I would like to store the array like as following arItem(0,0)= "APPLE" <-- string arItem(0,1)=30 <-- no of item , integer arItem(1,0) = "ORANGE" arItem(1,1) = 16 ....ETC From the help , i know I can use arItem.setvalue("APPLE",0,0)... ETC However, I don't know how to declare such array
Instead of using a 2-dimensional array here, I would use a 1-dimensional array of instances of a class/structure:
\\\ Public Structure Item Public Name As String Public Number As Integer End Structure . . . Dim a(90) As Item For i As Integer = 0 To a.Length - 1 a(i).Name = ... a(i).Number = ... Next i ///
Notice that this is a very basic sample, if you are storing more data for each object, consider using a class, and add properties instead of
providing direct access to the fields holding the attributes' values.
-- M S Herfried K. Wagner M V P <URL:http://dotnet.mvps.org/> V B <URL:http://dotnet.mvps.org/dotnet/faqs/> This thread has been closed and replies have been disabled. Please start a new discussion. Similar topics |
by: Michael Kirchner |
last post by:
Hi everybody
The output of my multiple dimension array is quite confusing.
Im declaring an array, store some values in it and then I save the array
in a session variable. On an other page I...
|
by: James |
last post by:
Hi,
I am new to C++. I want to directly create a dynamic two-dimension
double array, i.e. double pp. I found the "new" is only for
one-dimension array, i.e. double *p = new p. How to
"new" a...
|
by: Adam Hartshorne |
last post by:
The input to a function of a 3rd party library I want to use requires a
double**, which is a multi-dimension array of doubles.
I have looked on the net etc and seen several ways of supposedly...
|
by: Bill Sun |
last post by:
Hi, All
I have a conventional question, How to create a 3 dimension array by C
language.
I see some declare like this:
int *** array;
int value;
array = create3Darray(m,n,l);
|
by: tg |
last post by:
How can I sort a two-dimension array on the first dimension in the array?
If there's not a way to do it, how can I return the values of the first
dimension so that I can sort the values myself...
| |
by: MattB |
last post by:
I have an one dimensional array being created from a delimited list using
string.split. Now I'd like to take that array and add another dimension and
manually put a value in there based on the...
|
by: Nathan Sokalski |
last post by:
I have a multidimensional array declared as the following:
Dim guesses(14, 5) As Integer
I want to assign all values in a specific dimension to another array
declared as follows:
|
by: Jackson |
last post by:
I have something that is stumping me. I am trying to initialize a 3
dimensional string array with the code below, but it wont compile. Can anyone
explain what Im doing wrong?????????????? Im...
|
by: Martin Pöpping |
last post by:
Hello,
I want to iterate the second dimension of a 2-dim-array.
Let´s say I have an array:
double myArray and a given index: int i.
Assume my index is given in want to iterate my array...
|
by: dennis.sam |
last post by:
Hi,
Is there away to define a multi-dimensional array with respect to the
number of dimensions the array has? For example, given a user spec of
"a b c d", I want to create a 4 dimensional array...
|
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,...
| |
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...
|
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,...
|
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: tracyyun |
last post by:
Dear forum friends,
With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
|
by: agi2029 |
last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
|
by: conductexam |
last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and...
| |
by: 6302768590 |
last post by:
Hai team
i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated ...
|
by: muto222 |
last post by:
How can i add a mobile payment intergratation into php mysql website.
| |