Results 1 to 2 of 2

Thread: Class wont work from module.

  1. #1

    Thread Starter
    New Member
    Join Date
    Oct 2008
    Posts
    4

    Class wont work from module.

    ok. this may be very very hard for me to explain. But please i need help!

    Here is the class file and the functions im dealing with inside of it:
    Code:
    Private Type Structure
        Name As String
        Health As Integer
        DamageToGive As Integer
        Power As Integer
        GridLocation As String
    End Type
    
    Dim Structure() As Structure
    
    Sub StructureCount(Value As Long)
        ReDim Preserve Structure(0 To Value) As Structure
    End Sub
    
    
    Property Get GridLocation(index As Integer, Optional StructureName As String)
        If Len(StructureName) > 0 Then
            For i = 0 To UBound(Structure)
                If Structure(i).Name = StructureName Then
                    GridLocation = Structure(i).GridLocation
                    Exit For
                End If
            Next i
        Else
            GridLocation = Structure(index).GridLocation
        End If
    End Property
    
    Sub SetGridLocation(ClickedIndex As Integer, mLeft As Integer, mDown As Integer, mRow As Integer, index As Integer, Optional StructureName As String)
    Dim BuildArray As String
        If Len(StructureName) > 0 Then
            For i = 0 To UBound(Structure)
                If Structure(i).Name = StructureName Then
                    Structure(i).GridLocation = GetGridLocation(ClickedIndex, mLeft, mDown, mRow)
                End If
            Next i
        Else
                    Structure(index).GridLocation = GetGridLocation(ClickedIndex, mLeft, mDown, mRow) 'SUBSCRIPT OUT OF RANGE FROM BuildIt()
        End If
    End Sub
    Here is the code in the module and the functions im dealing with:
    Code:
    Private Building As New StructureController
    
    Function BuildIt()
    MsgBox Building.GridLocation(0)
    End Function


    here is the code of the main form and the commands im dealing with:
    Code:
    Public Building As New StructureController
    
    Private Sub Form_Load()
    Building.StructureCount 34
    Building.SetGridLocation 1, 2, 8, 15, 1
    MsgBox Building.GridLocation(0)  'THIS WORKS PERFECT!!!!!!
    MsgBox BuildIt() 'SUBSCRIPT OUT OF RANGE!!!!!!!
    End Sub
    ok here is where the problem occurs.
    HOW DO I FIX THIS? PLEASE HELP ME!

  2. #2
    Frenzied Member
    Join Date
    Jun 2006
    Posts
    1,098

    Re: Class wont work from module.

    You have declared the variable Building in two places. The code in your BuildIt function refers to the one declared in the module. The code in Form_Load refers to the one declared in the form. These are two separate instances of your class.

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