A UDT provides a way of grouping several variables together under one name. Generally speaking a UDT is handled just like any other variable. UDT's can be nested i.e. one of a UDT's subtypes could be another UDT.
A Class describes an object. A Class can be used in a similar way to a UDT but it can also do a lot more, eg have it's own methods properties etc. A Form is a class.
Here is an example of how you could (but wouldn't) define a team as an object
...and how you might then use it...Code:Option Explicit Public Name As String Public Batting As Integer Public DefRating As Integer Public Position As Integer Private cThrowArm As Integer Public Property Get ThrowArm() As Integer ThrowArm = cThrowArm End Property Public Property Let ThrowArm(value As Integer) If value > 80 Then value = 80 ElseIf value < 10 Then value = 10 End If cThrowArm = value End Property Private Sub Class_Initialize() Debug.Print "I'm alive!" End Sub Private Sub Class_Terminate() Debug.Print "Bye!" End SubNote how Throwarm has some restrictions as to what values can be set to it.Code:Option Explicit Private mTeams() As cTeam Private Sub Form_Load() ReDim mTeams(3) Set mTeams(0) = New cTeam 'creates a new instance of the class With mTeams(0) .Name = "thing" .DefRating = 32 .ThrowArm = 99 End With Set mTeams(1) = mTeams(0) 'creates a second reference the 1st team Debug.Print mTeams(1).DefRating Debug.Print mTeams(1).ThrowArm set mteams(1) = nothing 'destroys said reference End Sub
Classes are a lot slower than UDT's but much more powerful.




Reply With Quote