Results 1 to 7 of 7

Thread: custom.custom

  1. #1

    Thread Starter
    Frenzied Member Skitchen8's Avatar
    Join Date
    Feb 2001
    Location
    Binghamotn, NY
    Posts
    1,943

    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

  2. #2
    Hyperactive Member
    Join Date
    Sep 2002
    Location
    Devon, UK
    Posts
    311
    do you mean an enum?

    VB Code:
    1. Private Enum TEST
    2.     Jack = 1
    3.     Bob
    4.     Sally
    5.     James
    6.     etc
    7. End Enum

    or perhaps a collection
    Sam.

  3. #3

    Thread Starter
    Frenzied Member Skitchen8's Avatar
    Join Date
    Feb 2001
    Location
    Binghamotn, NY
    Posts
    1,943
    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

  4. #4
    The picture isn't missing BuggyProgrammer's Avatar
    Join Date
    Oct 2000
    Location
    Vancouver, Canada
    Posts
    5,217
    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 .

  5. #5
    PowerPoster
    Join Date
    Oct 2002
    Location
    British Columbia
    Posts
    9,758
    You don't want an Enum you want a user defined type. Enum's are basically constants.

    VB Code:
    1. Public Type Item
    2.   Number as Integer
    3.   Description as String
    4. End Type
    5.  
    6. 'declare a variable using your user defined type
    7. Dim udtItem as Item
    8. 'obviously for an array use
    9. Dim udtItems(10) as Item
    10.  
    11. udtItems(0).Number = 1
    12. udtItems(0).Description = 1

  6. #6
    Super Moderator Wokawidget's Avatar
    Join Date
    Nov 2001
    Location
    Headingly Occupation: Classified
    Posts
    9,632
    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:
    1. Option Explicit
    2.  
    3. Private mstrUsername As String
    4. Private mstrPassword As String
    5.  
    6. Public Property Let Username(ByVal Value As String)
    7.    mstrUsername = Value
    8. End property
    9.  
    10. Public Property Get Username() As String
    11.    Username = mstrUsername
    12. End Property
    13.  
    14. Public Property Let Password(ByVal Value As String)
    15.    mstrPassword = Value
    16. End property
    17.  
    18. Public Property Get Password() As String
    19.    Password = mstrPassword
    20. End Property
    Then in your form you would do:
    VB Code:
    1. Option Explicit
    2.  
    3. Private mcolItems As Collection
    4.  
    5. Private Sub Form_Load()
    6.    Set mcolItems = New Collection
    7.    AddUsers
    8. End Sub
    9.  
    10. Private Sub AddUsers()
    11. Dim objUser As clsUser
    12.    Set objUser = New clsUser
    13.    objUser.Username = "Woof"
    14.    objUser.Password = "Badger"
    15.    mcolItems.Add objUser
    16.    Set objUser = Nothing
    17.  
    18.    Set objUser = New clsUser
    19.    objUser.Username = "SmallFish"
    20.    objUser.Password = "Sausage"
    21.    mcolItems.Add objUser
    22.    Set objUser = Nothing
    23. End Sub
    24.  
    25. Private Sub Command1_Click()
    26. Dim objUser As clsUser
    27.    Set objUser = mcolItems.Item(1)
    28.    MsgBox objUser.Username
    29.    Set objUser = Nothing
    30. End Sub
    Hope that helps.

    Woof

  7. #7

    Thread Starter
    Frenzied Member Skitchen8's Avatar
    Join Date
    Feb 2001
    Location
    Binghamotn, NY
    Posts
    1,943
    Originally posted by brucevde
    You don't want an Enum you want a user defined type. Enum's are basically constants.

    VB Code:
    1. Public Type Item
    2.   Number as Integer
    3.   Description as String
    4. End Type
    5.  
    6. 'declare a variable using your user defined type
    7. Dim udtItem as Item
    8. 'obviously for an array use
    9. Dim udtItems(10) as Item
    10.  
    11. udtItems(0).Number = 1
    12. 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
  •  



Click Here to Expand Forum to Full Width