Creating an array

  • Thread starter Thread starter Robert Dufour
  • Start date Start date
R

Robert Dufour

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
 
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 said:
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
 
Thanks
Bob
Armin Zingler said:
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
 
Armin,

Is a List Of(item) not nicer?

Cor

Armin Zingler said:
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
 
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
 
:
: 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
 
Back
Top