|
-
Aug 14th, 2008, 01:19 PM
#1
Thread Starter
Fanatic Member
Collection?
I have individual objects that have multiple variables.
Eg. ObjName, XPosition, YPosition, ObjAngle
I think it may be a collection that I need to use but I don't know how to use one. Hoping someone can give me an example.
Looking at MSDN is a collection only 2D? Ie one variable, one listing?
Basically I want a "table" to lookup. One variable, with a list of attributes to that variable.
Previously I've created a bunch of 2d arrays but as you can't redim preserve the first part of the 2d array it's hard to add extra data.
Might be wrong in what I'm saying but hoping someone can point me in the right direction.
-
Aug 14th, 2008, 01:46 PM
#2
Re: Collection?
Are you by any chance refering to ENUM?
A good exercise for the Heart is to bend down and help another up...
Please Mark your Thread " Resolved", if the query is solved
MyGear:
★ CPU ★ Ryzen 5 5800X
★ GPU ★ NVIDIA GeForce RTX 3080 TI Founder Edition
★ RAM ★ G. Skill Trident Z RGB 32GB 3600MHz
★ MB ★ ASUS TUF GAMING X570 (WI-FI) ATX Gaming
★ Storage ★ SSD SB-ROCKET-1TB + SEAGATE 2TB Barracuda IHD
★ Cooling ★ NOCTUA NH-D15 CHROMAX BLACK 140mm + 10 of Noctua NF-F12 PWM
★ PSU ★ ANTEC HCG-1000-EXTREME 1000 Watt 80 Plus Gold Fully Modular PSU
★ Case ★ LIAN LI PC-O11 DYNAMIC XL ROG (BLACK) (G99.O11DXL-X)
★ Monitor ★ LG Ultragear 27" 240Hz Gaming Monitor
★ Keyboard ★ TVS Electronics Gold Keyboard
★ Mouse ★ Logitech G502 Hero
-
Aug 14th, 2008, 02:04 PM
#3
Re: Collection?
A Collection is just a list (1D, just like MyArray(10) is), and is not what you want.
koolsid is on the right lines, but I don't think an Enum is what you are after - I think you want a User Defined Type (UDT), which would be something like this:
Code:
'in the Declarations section
Type MyObject
ObjName as String
XPosition as Integer
YPosition as Integer
ObjAngle as Single
End Type
'whereever you want to declare the variable(s)
Dim SingleObject as MyObject
'to use the variable(s)
SingleObject.ObjName = "sid"
SingleObject.XPosition = 0
SingleObject.YPosition = 2
SingleObject.ObjAngle = 0
You can also create/use an array, just as you would with any other data type - and as you only need the array to be 1D, you can ReDim Preserve if needed.
-
Aug 14th, 2008, 02:41 PM
#4
Thread Starter
Fanatic Member
Re: Collection?
Si,
Hello again. Seems to be what I need but how do I define the UDT as an array? Might be correct but the following doesn't seem to autoprompt as vb normally does. Hard to explain what I'm talking about though.
vb Code:
'in the Declarations section
Type MyObject
ObjName() As String
XPosition() As Integer
YPosition() As Integer
ObjAngle() As Single
End Type
'whereever you want to declare the variable(s)
Dim SingleObject As MyObject
'to use the variable(s)
SingleObject.ObjName(i) = "sid"
SingleObject.XPosition(i) = 0
SingleObject.YPosition(i) = 2
SingleObject.ObjAngle(i) = 0
-
Aug 14th, 2008, 04:46 PM
#5
Re: Collection?
What you did is valid, but not what you wanted - that creates a structure containing arrays, rather than an array containing a structure.
Use the Type declaration as I showed, and change the other parts like this:
Code:
Dim ArrayOfObject() as MyObject
ReDim ArrayOfObject(0) as MyObject
ArrayOfObject(0).ObjName = "sid"
ArrayOfObject(0).XPosition = 0
ArrayOfObject(0).YPosition = 2
ArrayOfObject(0).ObjAngle = 0
You could also use a With block, eg:
Code:
With ArrayOfObject(0)
.ObjName = "sid"
.XPosition = 0
.YPosition = 2
.ObjAngle = 0
End With
-
Aug 14th, 2008, 09:39 PM
#6
Thread Starter
Fanatic Member
Re: Collection?
Thankyou. Made things so much easier and simpler!!
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|