Log in

View Full Version : Ordinal positions in a Structure?



mud2
10-12-2007, 09:07 PM
I have a Structure:
Type Film_Data
ID As String
Notes As String
Location As String
End Type
Dim This_Film_Data As Film_Data

Sub Set_Film_Data()
With This_Film_Data
.ID = 123456
.Notes = "Moonstone, Waves, Rose"
.Location = "Box1"
End With

I want to refer to the Film_Data members by thier position in the type. can I ?
This_Film_Data(1) generates an error..."...looking for an arrat..." ??

OBP
10-13-2007, 05:32 AM
Try This_Film_Data.field(1)

mud2
10-13-2007, 08:46 AM
It looks intuitive, but doesn"work: "...not Recognized..."

Oorang
10-13-2007, 09:07 AM
For types, you just use the name:

MsgBox This_Film_Data.Notes

If you want to use numbers you are going to have to go to arrays or build your own collection class.

OBP
10-13-2007, 02:38 PM
Oorang, you can use numbers.
Mud2, sorry it is Fields(n) not Field(n)
My memory was playing tricks on me.
See the Access Visual Basic Help topics on the
DAO Tables and Fields Collections.

Oorang
10-13-2007, 03:53 PM
OBP you can only use numbers if you declare an array of the type or you include arrays in your type definition.
Example1:
Type Film_Data
ID As String
Notes As String
Location As String
End Type
Dim foo() as Film_Data
MsgBox Foo(1).Notes
Example2
Type Film_Data
ID() As String
Notes() As String
Location() As String
End Type
Dim foo as Film_Data
MsgBox Foo.Notes(1)