Re: Having problems creating class with array
- From: "Larry Serflaten" <serflaten@xxxxxxxxxxxxxx>
- Date: Fri, 26 Oct 2007 13:32:26 -0500
"the_tool_man" <john_manly@xxxxxxxxxxxxx> wrote
I am just learning about classes, and have created a simple class,
The relevant code follows:
Public secSection(1 To intMaxSections) As Section
Sub Main()
'Initialize empty constraint
'Initialize empty section with empty constraints
'Set all sections to empty
'Set first section to default
secSection(1).Start = 0#
secSection(1).Finish = 360#
If your class needs initialization, then use the Class_Initialization event
to set your variables.
For the Constraint classs that would be:
Private Sub Class_Initialize()
Derivative = 99
End Sub
For the Section class that would be:
Private Sub Class_Initialize()
Dim idx As Long
Start = 361
For idx = 1 To intMaxConstraints
Set Constraint(idx) = New Constraint
Next
End Sub
Your main code would then just have to initialize the array and show
the results:
Option Explicit
Public secSection(1 To intMaxSections) As Section
Sub Main()
Dim intIndex As Long
' Init array
For intIndex = 1 To intMaxSections
Set secSection(intIndex) = New Section
Next
'Set first section to default
secSection(1).Start = 0#
secSection(1).Finish = 360#
' Check results
Debug.Print "Section 1:"
Debug.Print " Start: " + Format(secSection(1).Start, strFormat)
Debug.Print " End: " + Format(secSection(1).Finish, strFormat)
Debug.Print " Constraints:"
For intIndex1 = 1 To intMaxConstraints
Debug.Print " " & Str(intIndex1), _
" Der: " & Str(secSection(1).Constraint(intIndex1).Derivative) & _
" Pos: " & Format(secSection(1).Constraint(intIndex1).Position) & _
" Val: " & Format(secSection(1).Constraint(intIndex1).Value)
Next
End Sub
.
- References:
- Having problems creating class with array
- From: the_tool_man
- Having problems creating class with array
- Prev by Date: Re: PDF output
- Next by Date: Re: Implementing a TLB
- Previous by thread: Re: Having problems creating class with array
- Next by thread: Re: Having problems creating class with array
- Index(es):
Relevant Pages
|