How would I declare a structure with....

blueeyes53

Active member
Joined
May 2, 2006
Messages
25
Programming Experience
Beginner
Hi there,
How would I declare a structure with two members to store each record from an input file.

The first member should be a date, and the second a single precision number.
Also I need to declare a dynamic array of structures.

Anyone could help?
Blueeyes53:confused:
 
VB.NET:
Private Structure MyStructure
        dim strDate As String
        dim strName As String
    End Structure
That is the basic structure format. But I don't think you can have a dynamically sized array of structures. Maybe I was doing something wrong, but it wouldn't let me do it when I was trying today.
 
Think you want something like this, could be wrong though :rolleyes:
VB.NET:
Structure MyStructure
Private MyDate as string
Private MyNum as integer
End Structure

Dim MyArrayList as new arraylist
Dim X as MyStructure

Then to add to it

VB.NET:
X.MyDate = 'whatever value here
X.MyNum = 'whatever value here
MyArrayList.Add(X)
 
A structure acn provide the same validation as a class. There is nothing to stop you declaring private variables and public properties in a structure. All the numeric types in VB.NET are structures and they have properties. The main difference between a class and a structure is that a structure is a vaue type and a class is a reference type, although there are other subtle differences too.
 
Back
Top