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?
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.
Re: does VB have anything like a struct in c++
Quote:
Originally Posted by
LaVolpe
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?
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.