Results 1 to 4 of 4

Thread: does VB have anything like a struct in c++

  1. #1

    Thread Starter
    Member
    Join Date
    Feb 2009
    Posts
    32

    does VB have anything like a struct in c++

    for those that don't code in c++, a struct is like an array that has many different types of values in them(horrible explanition i know)
    for example you could have a struct school and in school you could have number of students, test scores, ect...)

    so anything like that in visual basic?

  2. #2
    VB-aholic & Lovin' It LaVolpe's Avatar
    Join Date
    Oct 2007
    Location
    Beside Waldo
    Posts
    19,541

    Re: does VB have anything like a struct in c++

    I'm not sure what you are asking, but that sounds a lot like a UDT (user-defined type) or a UDT within a UDT
    Code:
    Private Type StudentStruct
         Name As String
         TestScore As Integer
    End Type
    Private Type SchoolStruct
        Count As Long                               ' how many StudentStruct in UDT
        StudentData() As StudentStruct       ' collection of StudentStruct's
    End Type
    
    Dim mySchool As SchoolStruct
    
    Private Sub Command1_Click()
         ReDim mySchool.StudentData(0 to 1)
         mySchool.Count = 2
         With mySchool
              .StudentData(0).Name = "Hans"
              .StudentData(0).TestScore = 88
              .StudentData(1).Name = "LaVolpe"
              .StudentData(1).TestScore = 110  ' ;)
          End With
    
          Dim i As Integer
          For I = 0 To mySchool.Count - 1
              MsgBox mySchool.StudentData(i).Name  & " scored " & mySchool.StudentData(i).TestScore
          Next
    End Sub
    Should you need to resize the array later:
    Code:
    mySchool.Count = mySchool.Count + 1
    ReDim Preserve mySchool.StudentData(0 To mySchool.Count -1)
    Something like that or something else? If something else you might want to describe it a bit better.
    Insomnia is just a byproduct of, "It can't be done"

    Classics Enthusiast? Here's my 1969 Mustang Mach I Fastback. Her sister '67 Coupe has been adopted

    Newbie? Novice? Bored? Spend a few minutes browsing the FAQ section of the forum.
    Read the HitchHiker's Guide to Getting Help on the Forums.
    Here is the list of TAGs you can use to format your posts
    Here are VB6 Help Files online


    {Alpha Image Control} {Memory Leak FAQ} {Unicode Open/Save Dialog} {Resource Image Viewer/Extractor}
    {VB and DPI Tutorial} {Manifest Creator} {UserControl Button Template} {stdPicture Render Usage}

  3. #3

    Thread Starter
    Member
    Join Date
    Feb 2009
    Posts
    32

    Re: does VB have anything like a struct in c++

    Quote Originally Posted by LaVolpe View Post
    I'm not sure what you are asking, but that sounds a lot like a UDT (user-defined type) or a UDT within a UDT
    Code:
    Private Type StudentStruct
         Name As String
         TestScore As Integer
    End Type
    Private Type SchoolStruct
        Count As Long                               ' how many StudentStruct in UDT
        StudentData() As StudentStruct       ' collection of StudentStruct's
    End Type
    
    Dim mySchool As SchoolStruct
    
    Private Sub Command1_Click()
         ReDim mySchool.StudentData(0 to 1)
         mySchool.Count = 2
         With mySchool
              .StudentData(0).Name = "Hans"
              .StudentData(0).TestScore = 88
              .StudentData(1).Name = "LaVolpe"
              .StudentData(1).TestScore = 110  ' ;)
          End With
    
          Dim i As Integer
          For I = 0 To mySchool.Count - 1
              MsgBox mySchool.StudentData(i).Name  & " scored " & mySchool.StudentData(i).TestScore
          Next
    End Sub
    Should you need to resize the array later:
    Code:
    mySchool.Count = mySchool.Count + 1
    ReDim Preserve mySchool.StudentData(0 To mySchool.Count -1)
    Something like that or something else? If something else you might want to describe it a bit better.
    have i ever mentioned i love you?

  4. #4
    VB-aholic & Lovin' It LaVolpe's Avatar
    Join Date
    Oct 2007
    Location
    Beside Waldo
    Posts
    19,541

    Re: does VB have anything like a struct in c++

    Glad I could help. When your posts are resolved, please mark them as such. Use the Thread Tools menu near top of your first posts.
    Insomnia is just a byproduct of, "It can't be done"

    Classics Enthusiast? Here's my 1969 Mustang Mach I Fastback. Her sister '67 Coupe has been adopted

    Newbie? Novice? Bored? Spend a few minutes browsing the FAQ section of the forum.
    Read the HitchHiker's Guide to Getting Help on the Forums.
    Here is the list of TAGs you can use to format your posts
    Here are VB6 Help Files online


    {Alpha Image Control} {Memory Leak FAQ} {Unicode Open/Save Dialog} {Resource Image Viewer/Extractor}
    {VB and DPI Tutorial} {Manifest Creator} {UserControl Button Template} {stdPicture Render Usage}

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