|
-
Jul 14th, 2004, 02:36 PM
#1
Thread Starter
Frenzied Member
custom.custom
Been far too long since I've worked with VB (Although I've never done this) and I've heard of how to do this before, but I don't remember. I want to have a variable named item with several different variables underneath it (If I remember correctly this has something to do with enumerations) so I can have like item.number = 3 and item.description = 4
not really needed per say, just makes my coding look cleaner, for my own sake.
Any help on how to do that??
Government is another way to say better…than…you.
It’s like ice but no pick, a murder charge that won’t stick,
it’s like a whole other world where you can smell the food,
but you can’t touch the silverware.
Huh, what luck. Fascism you can vote for.
Humph, isn’t that sweet?
And we’re all gonna die some day, because that’s the American way
-Stone Sour
-
Jul 14th, 2004, 02:38 PM
#2
Hyperactive Member
do you mean an enum?
VB Code:
Private Enum TEST
Jack = 1
Bob
Sally
James
etc
End Enum
or perhaps a collection
-
Jul 14th, 2004, 02:57 PM
#3
Thread Starter
Frenzied Member
That's exactly what I was looking for, thank you 
edit: any way to make this into an array??
So I could have test(0).sally?? or not??
Government is another way to say better…than…you.
It’s like ice but no pick, a murder charge that won’t stick,
it’s like a whole other world where you can smell the food,
but you can’t touch the silverware.
Huh, what luck. Fascism you can vote for.
Humph, isn’t that sweet?
And we’re all gonna die some day, because that’s the American way
-Stone Sour
-
Jul 14th, 2004, 03:58 PM
#4
The picture isn't missing
Originally posted by Skitchen8
That's exactly what I was looking for, thank you 
edit: any way to make this into an array??
So I could have test(0).sally?? or not??
Huh? How would you want it to work if it was in an array?
Remember, if someone's post was not helpful, you can always rate their post negatively  .
-
Jul 14th, 2004, 04:33 PM
#5
You don't want an Enum you want a user defined type. Enum's are basically constants.
VB Code:
Public Type Item
Number as Integer
Description as String
End Type
'declare a variable using your user defined type
Dim udtItem as Item
'obviously for an array use
Dim udtItems(10) as Item
udtItems(0).Number = 1
udtItems(0).Description = 1
-
Jul 15th, 2004, 03:03 AM
#6
I prefer collections and a class as they give you more options and make your code much easier to maintain:
In a class module called clsUser:
VB Code:
Option Explicit
Private mstrUsername As String
Private mstrPassword As String
Public Property Let Username(ByVal Value As String)
mstrUsername = Value
End property
Public Property Get Username() As String
Username = mstrUsername
End Property
Public Property Let Password(ByVal Value As String)
mstrPassword = Value
End property
Public Property Get Password() As String
Password = mstrPassword
End Property
Then in your form you would do:
VB Code:
Option Explicit
Private mcolItems As Collection
Private Sub Form_Load()
Set mcolItems = New Collection
AddUsers
End Sub
Private Sub AddUsers()
Dim objUser As clsUser
Set objUser = New clsUser
objUser.Username = "Woof"
objUser.Password = "Badger"
mcolItems.Add objUser
Set objUser = Nothing
Set objUser = New clsUser
objUser.Username = "SmallFish"
objUser.Password = "Sausage"
mcolItems.Add objUser
Set objUser = Nothing
End Sub
Private Sub Command1_Click()
Dim objUser As clsUser
Set objUser = mcolItems.Item(1)
MsgBox objUser.Username
Set objUser = Nothing
End Sub
Hope that helps.
Woof
-
Jul 17th, 2004, 09:23 PM
#7
Thread Starter
Frenzied Member
Originally posted by brucevde
You don't want an Enum you want a user defined type. Enum's are basically constants.
VB Code:
Public Type Item
Number as Integer
Description as String
End Type
'declare a variable using your user defined type
Dim udtItem as Item
'obviously for an array use
Dim udtItems(10) as Item
udtItems(0).Number = 1
udtItems(0).Description = 1
That appears to be exactly what I want, thank you to all who posted. 
-Eric
Government is another way to say better…than…you.
It’s like ice but no pick, a murder charge that won’t stick,
it’s like a whole other world where you can smell the food,
but you can’t touch the silverware.
Huh, what luck. Fascism you can vote for.
Humph, isn’t that sweet?
And we’re all gonna die some day, because that’s the American way
-Stone Sour
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
|