473,466 Members | 1,456 Online
Bytes | Software Development & Data Engineering Community
Create Post

Home Posts Topics Members FAQ

Creating an array

I need an array with two columns, values in column 1 are datetime and in
column 2 they are numeric with up to two decimal places.

What's the Dim statement to create this?

Any help is greatly appreciated.

Bob
Jan 22 '07 #1
13 1079
If you want to have the 2 data types preserved use an ArrayList object or a
Collection object, rather than a simple single-type array.
"Robert Dufour" <bd*****@sgiims.comwrote in message
news:ev**************@TK2MSFTNGP05.phx.gbl...
>I need an array with two columns, values in column 1 are datetime and in
column 2 they are numeric with up to two decimal places.

What's the Dim statement to create this?

Any help is greatly appreciated.

Bob


Jan 22 '07 #2
"Robert Dufour" <bd*****@sgiims.comschrieb
I need an array with two columns, values in column 1 are datetime
and in column 2 they are numeric with up to two decimal places.

What's the Dim statement to create this?

Any help is greatly appreciated.
structure Item
public v1 as date
public v2 as decimal
end structure

'...
dim items(17) as item

items(0).v1 = date.now
items(0).v2 = 17.34

with items(1)
.v1 = date.now
.v2 = 17.34
end with
Armin
Jan 23 '07 #3
Thanks
Bob
"Armin Zingler" <az*******@freenet.dewrote in message
news:uG**************@TK2MSFTNGP04.phx.gbl...
"Robert Dufour" <bd*****@sgiims.comschrieb
>I need an array with two columns, values in column 1 are datetime
and in column 2 they are numeric with up to two decimal places.

What's the Dim statement to create this?

Any help is greatly appreciated.

structure Item
public v1 as date
public v2 as decimal
end structure

'...
dim items(17) as item

items(0).v1 = date.now
items(0).v2 = 17.34

with items(1)
.v1 = date.now
.v2 = 17.34
end with
Armin

Jan 23 '07 #4
Armin,

Is a List Of(item) not nicer?

Cor

"Armin Zingler" <az*******@freenet.deschreef in bericht
news:uG**************@TK2MSFTNGP04.phx.gbl...
"Robert Dufour" <bd*****@sgiims.comschrieb
>I need an array with two columns, values in column 1 are datetime
and in column 2 they are numeric with up to two decimal places.

What's the Dim statement to create this?

Any help is greatly appreciated.

structure Item
public v1 as date
public v2 as decimal
end structure

'...
dim items(17) as item

items(0).v1 = date.now
items(0).v2 = 17.34

with items(1)
.v1 = date.now
.v2 = 17.34
end with
Armin

Jan 23 '07 #5
Hi Cor,

well, he asked for an array, I gave him an array. ;-)

You're right with VB 2005, but as Item is a structure (it doesn't have to
be), it's more complicated if you use it with the generic List. You can not
simply write

items(0).v1 = ...
items(0).v2 = ...

you would have to write

dim i as item

i.v1=..
i.v2=..

items(0) = i

Armin
"Cor Ligthert [MVP]" <no************@planet.nlschrieb
Armin,

Is a List Of(item) not nicer?

Cor

"Armin Zingler" <az*******@freenet.deschreef in bericht
news:uG**************@TK2MSFTNGP04.phx.gbl...
"Robert Dufour" <bd*****@sgiims.comschrieb
I need an array with two columns, values in column 1 are
datetime and in column 2 they are numeric with up to two decimal
places.
>
What's the Dim statement to create this?
>
Any help is greatly appreciated.
structure Item
public v1 as date
public v2 as decimal
end structure

'...
dim items(17) as item

items(0).v1 = date.now
items(0).v2 = 17.34

with items(1)
.v1 = date.now
.v2 = 17.34
end with
Armin

Jan 23 '07 #6

"Robert Dufour" <bd*****@sgiims.comwrote in message
news:ev**************@TK2MSFTNGP05.phx.gbl...
:
: I need an array with two columns, values in column 1 are datetime
: and in column 2 they are numeric with up to two decimal places.
:
: What's the Dim statement to create this?
:
: Any help is greatly appreciated.
:
: Bob
Just for the sake of a little diversity...

===========================================
Option Strict On

Imports Microsoft.VisualBasic
Imports System
Imports System.Collections.Generic

Public Module [module]
public sub main
Dim dictionary As New Dictionary(Of DateTime, Decimal)
With dictionary
.Add(Date.Now, 12.34D)
.Add(#1/2/2007#, 5678910.11D)
End With

Dim kvp As KeyValuePair(Of Date, Decimal)
For Each kvp In dictionary
Console.WriteLine("Key={0}, Value={1}", _
kvp.Key, kvp.Value)
Next
End sub
End Module
===========================================
Ralf
--
--
----------------------------------------------------------
* ^~^ ^~^ *
* _ {~ ~} {~ ~} _ *
* /_``>*< >*<''_\ *
* (\--_)++) (++(_--/) *
----------------------------------------------------------
There are no advanced students in Aikido - there are only
competent beginners. There are no advanced techniques -
only the correct application of basic principles.
Jan 23 '07 #7


"Armin Zingler" <az*******@freenet.dewrote in message
news:ud*************@TK2MSFTNGP06.phx.gbl...
Hi Cor,

well, he asked for an array, I gave him an array. ;-)

You're right with VB 2005, but as Item is a structure (it doesn't have to
be), it's more complicated if you use it with the generic List. You can
not
simply write

items(0).v1 = ...
items(0).v2 = ...

you would have to write

dim i as item

i.v1=..
i.v2=..

items(0) = i

Armin
"Cor Ligthert [MVP]" <no************@planet.nlschrieb
>Armin,

Is a List Of(item) not nicer?

Cor

"Armin Zingler" <az*******@freenet.deschreef in bericht
news:uG**************@TK2MSFTNGP04.phx.gbl...
"Robert Dufour" <bd*****@sgiims.comschrieb
I need an array with two columns, values in column 1 are
datetime and in column 2 they are numeric with up to two decimal
places.

What's the Dim statement to create this?

Any help is greatly appreciated.

structure Item
public v1 as date
public v2 as decimal
end structure

'...
dim items(17) as item

items(0).v1 = date.now
items(0).v2 = 17.34

with items(1)
.v1 = date.now
.v2 = 17.34
end with
Armin

In which case you can just add a constructor to the structure that took 2
parameters, the names of the properties to set. Then you could just use:

items(0) = New Item(someDate, someDecimal)

:)

HTH,
Mythran
Jan 23 '07 #8
"Mythran" <ki********@hotmail.comschrieb
You're right with VB 2005, but as Item is a structure (it doesn't
have to
be), it's more complicated if you use it with the generic List.
You can
not
simply write

items(0).v1 = ...
items(0).v2 = ...

you would have to write

dim i as item

i.v1=..
i.v2=..

items(0) = i

In which case you can just add a constructor to the structure that
took 2
parameters, the names of the properties to set. Then you could just
use:

items(0) = New Item(someDate, someDecimal)

:)

Right, but my example doesn't create a new item.
Armin
Jan 23 '07 #9


"Armin Zingler" <az*******@freenet.dewrote in message
news:ud**************@TK2MSFTNGP04.phx.gbl...
"Mythran" <ki********@hotmail.comschrieb
You're right with VB 2005, but as Item is a structure (it doesn't
have to
be), it's more complicated if you use it with the generic List.
You can
not
simply write

items(0).v1 = ...
items(0).v2 = ...

you would have to write

dim i as item

i.v1=..
i.v2=..

items(0) = i

In which case you can just add a constructor to the structure that
took 2
parameters, the names of the properties to set. Then you could just
use:

items(0) = New Item(someDate, someDecimal)

:)


Right, but my example doesn't create a new item.
Armin
Umm, yeah it did :0

Dim i As Item

is the same as

Dim i As Item = New Item()

where Item is a structure....

:)

Mythran
Jan 23 '07 #10
"Mythran" <ki********@hotmail.comschrieb
>

"Armin Zingler" <az*******@freenet.dewrote in message
news:ud**************@TK2MSFTNGP04.phx.gbl...
"Mythran" <ki********@hotmail.comschrieb
You're right with VB 2005, but as Item is a structure (it
doesn't have to
be), it's more complicated if you use it with the generic
List. You can
not
simply write

items(0).v1 = ...
items(0).v2 = ...

you would have to write

dim i as item

i.v1=..
i.v2=..

items(0) = i

>
In which case you can just add a constructor to the structure
that took 2
parameters, the names of the properties to set. Then you could
just use:
>
items(0) = New Item(someDate, someDecimal)
>
:)

Right, but my example doesn't create a new item.
Armin

Umm, yeah it did :0

Dim i As Item

is the same as

Dim i As Item = New Item()

where Item is a structure....

:)
[After many revisions...]

Yes and no. :-)

My List has as many items as before, so I didn't create a new item.

I am referring to the logical level. I only wanted to show that you can not
simply write

items(0).field = ...

but you have to a) declare a variable b) set the field values c) put the
item in the list. That's why I call it more complicated. That the existence
of the additional declaration of variable i also means the implicit creation
of a new object can not be prevented, but the code's purpose is still
/changing/ an existing item. If I wanted to create a /new/ one I would have
to write Items.Add.
Talking about instances, we know that it is never possible to really change
the item in the List, and we neither get the same object back from the List
that we added, nor the object we add is stored in the list. It is always a
copy because it is a value type.
In other words, if somebody wants to know how to change an item in the List,
I would still answer

dim i as item

i.v1=..
i.v2=..

items(0) = i

On a logical level this is the required change whereas on a "physical" level
it's the creation of (at least) one new object. So, we both are right. :-)
Armin

Jan 23 '07 #11
Mythran,

You know Armin from the past. This will probably a long thread.

However mostly all threads Armin is involved in are very good to search for
later when they are ready.

Success,

:-)

Cor

"Mythran" <ki********@hotmail.comschreef in bericht
news:%2****************@TK2MSFTNGP02.phx.gbl...
>

"Armin Zingler" <az*******@freenet.dewrote in message
news:ud**************@TK2MSFTNGP04.phx.gbl...
>"Mythran" <ki********@hotmail.comschrieb
>You're right with VB 2005, but as Item is a structure (it doesn't
have to
be), it's more complicated if you use it with the generic List.
You can
not
simply write

items(0).v1 = ...
items(0).v2 = ...

you would have to write

dim i as item

i.v1=..
i.v2=..

items(0) = i
In which case you can just add a constructor to the structure that
took 2
parameters, the names of the properties to set. Then you could just
use:

items(0) = New Item(someDate, someDecimal)

:)


Right, but my example doesn't create a new item.
Armin

Umm, yeah it did :0

Dim i As Item

is the same as

Dim i As Item = New Item()

where Item is a structure....

:)

Mythran


Jan 23 '07 #12
"Cor Ligthert [MVP]" <no************@planet.nlschrieb
Mythran,

You know Armin from the past. This will probably a long thread.
Heeey, I didn't know I'm mainly responsible for long threads. ;-) I'm only
(still) not able to say what I want to say briefly. ;-(

Armin

Jan 23 '07 #13
Armin,

After sending this, I got the idea that you would read it as you did. I
wanted to say that you mostly investigate very good what you are writing
(after a quick start).

:-)

Cor

"Armin Zingler" <az*******@freenet.deschreef in bericht
news:%2****************@TK2MSFTNGP06.phx.gbl...
"Cor Ligthert [MVP]" <no************@planet.nlschrieb
>Mythran,

You know Armin from the past. This will probably a long thread.

Heeey, I didn't know I'm mainly responsible for long threads. ;-) I'm only
(still) not able to say what I want to say briefly. ;-(

Armin

Jan 23 '07 #14

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

Similar topics

5
by: Keiron Waites | last post by:
<script language="JavaScript" type="text/javascript"> <!-- var array1 = new Array(); var array1i = new Array(); array1 = array1i; alert(array1); // --> </script>
20
by: svend | last post by:
I'm messing with some code here... Lets say I have this array: a1 = ; And I apply slice(0) on it, to create a copy: a2 = a1.slice(0); But this isn't a true copy. If I go a1 = 42, and then...
7
by: kaul | last post by:
i want to create a 2-d array containg r rows and c columns by dynamic memory allocation in a single statement so that i will be able to access the ith and jth index as say arr how is that...
5
by: Chris | last post by:
Hi, to create an array of 2 objects (e.g. of type '__gc class Airplane') I need to do : Airplane * arrAirplanes __gc = new Airplane* __gc; arrAirplanes = new Airplane("N12344"); arrAirplanes...
5
by: jwgoerlich | last post by:
Hello, I need to create a 1 GB Byte array in memory. I can create it on a Win2000 system. On a Win2003 system, the application throws a System.OutOfMemoryException error. Both are running the...
38
by: djhulme | last post by:
Hi, I'm using GCC. Please could you tell me, what is the maximum number of array elements that I can create in C, i.e. char* anArray = (char*) calloc( ??MAX?? , sizeof(char) ) ; I've...
8
by: ctiggerf | last post by:
I was hopeing someone could help me out here. Been stumped on this one all day. This function 1. Checks uploaded files. 2. Creates two resized images from each (a full size, and a...
13
by: Justcallmedrago | last post by:
How would you declare and assign a variable inside a function THAT HAS THE NAME OF A PARAMETER YOU PASSED example: when you call createvariable("myvariable") it will declare the variable...
11
by: Matthew Wells | last post by:
Hello. I have figured out how to create an instance of an object only knowing the type by string. string sName = "MyClassName"; Type t = Type.GetType(sName); Object objNew =...
2
by: oswald.harry | last post by:
hi i am reading a set of jpeg files(RGB) and extracts the pixel values as longs.i want to create a 2d array with numof rows=numof images and numof cols=numof pixels in each image.ie each row of...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
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
tracyyun
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...
0
agi2029
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,...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...
0
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...
0
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The...
0
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 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.