Re: Having problems creating class with array

Tech-Archive recommends: Fix windows errors by optimizing your registry




"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


.



Relevant Pages

  • Re: Drop Primary Key with SQL/VBA
    ... > constraint there still is the primary key on that field. ... Public Sub CreateTable() ... Dim strSQL As String ...
    (microsoft.public.access.queries)
  • Re: Drop Primary Key with SQL/VBA
    ... >> constraint there still is the primary key on that field. ... > Public Sub CreateTable() ... > Dim strSQL As String ... > then open new tblCustomer in design view, ...
    (microsoft.public.access.queries)
  • Re: modeling either/or relationship...
    ... So, a net can be constrained either by layer,net class (and constraint ... I'm looking for a database design tool that, when doing that subcategory relationship, creates code that enforces the constraint that an object can belong to only one subcategory. ... root has a type field and each sub has a type field too and a constraint forcing the sub type to be of a particular value. ...
    (comp.databases.theory)