Navigacija
Lista poslednjih: 16, 32, 64, 128 poruka.

Run Time Error 361 Can't Load or unload this object

[es] :: Visual Basic 6 :: Run Time Error 361 Can't Load or unload this object

[ Pregleda: 1244 | Odgovora: 5 ] > FB > Twit

Postavi temu Odgovori

Autor

Pretraga teme: Traži
Markiranje Štampanje RSS

vidonk
Slobodan Vidovic
Niksic

Član broj: 192156
Poruke: 354
109.72.104.*



+9 Profil

icon Run Time Error 361 Can't Load or unload this object13.05.2020. u 18:03 - pre 47 meseci
Pokušavam da napravim igru memorije ali mi dava sledeću grešku

Code:

Run Time Error 361 Can't Load or unload this object


I naznačen je kod

Code:

Load btnChoice(intNextNumber)


A evo ga i cijeli kod

Code:

Option Explicit

'Variable to Check Playing Turn
    Private boolFirstChoice As Boolean

'Variable For Previous Index Chosen
    Private intFirstChoice As Integer

'Variable For Comparing Choices
    Private astrChoice(1 To 2) As String

'Variable For Keeping Pictures Visable
    Private aboolVisablePositions(1 To 8) As Boolean

'Note: Take Note Of The Properties On The Button And Image Boxes

Private Sub Form_Load()

'Declare
    Dim intNextNumber As Integer 'Loop


'Load 8 Buttins And 8 Image Boxes
    For intNextNumber = 1 To 8
        Load btnChoice(intNextNumber)
        Load imgPicture(intNextNumber)
    Next

'Move The Buttons And Image Boxes
    Call MoveControls(btnChoice)
    Call MoveControls(imgPicture)

'Make All Buttons Visable
    For intNextNumber = 1 To 8
    btnChoice(intNextNumber).Visable = True
    Next

'Set The Randomize Generator
    Randomize

'Declare Temporary
    Dim aintRandomNumber(1 To 8) As Integer

'Get Random Numbers
    Call GetRandomNumbers(aintRandomNumber)

'Load The Pictures

    For intNextNumber = 1 To 8
        Select Case aintRandomNumber(intNextNumber)
            Case 1, 2 'Santa
                imgPicture(intNextNumber).Picture = _
                    LoadPicture(App.Path & "\Santa.jpg")
                'Set Tag
                 imgPicture(intNextNumber).Tag = "Santa"
            Case 3, 4 'Gifts
                imgPicture(intNextNumber).Picture = _
                    LoadPicture(App.Path & "\Gifts.jpg")
                'Set Tag
                 imgPicture(intNextNumber).Tag = "Gifts"
            Case 5, 6 'Rudolph
                imgPicture(intNextNumber).Picture = _
                    LoadPicture(App.Path & "\Rudolph.jpg")
                'Set Tag
                 imgPicture(intNextNumber).Tag = "Rudoplph"
            Case 7, 8 'ChristmasTree
                imgPicture(intNextNumber).Picture = _
                    LoadPicture(App.Path & "\ChristmasTree.jpg")
                'Set Tag
                 imgPicture(intNextNumber).Tag = "ChristmasTree"
         End Select
    Next

End Sub
                 

Private Sub MoveControls(objControl As Object)

'Move Controls
    objControl(1).Move 8, 8
    objControl(2).Move 168, 8
    objControl(3).Move 328, 8
    objControl(4).Move 488, 8
    objControl(5).Move 8, 160
    objControl(6).Move 168, 160
    objControl(7).Move 328, 160
    objControl(8).Move 488, 160

End Sub

Private Sub GetRandomNumbers(aintRandomNumber() As Integer)

' Pick A Random Nuber 1 Trough 8
    aintRandomNumber(1) = CInt((Rnd * 7) + 1)

'Pick A Different Number
    Do Until aintRandomNumber(2) <> aintRandomNumber(1) _
    And aintRandomNumber(2) <> 0
        aintRandomNumber(2) = CInt((Rnd * 7) + 1)
    Loop

'Pick A Different Number
    Do Until aintRandomNumber(3) <> aintRandomNumber(2) _
    And aintRandomNumber(3) <> aintRandomNumber(1) _
    And aintRandomNumber(3) <> 0
    aintRandomNumber(3) = CInt((Rnd * 7) + 1)

'Pick A Different Number
    Do Until aintRandomNumber(4) <> aintRandomNumber(3) _
    And aintRandomNumber(4) <> aintRandomNumber(2) _
    And aintRandomNumber(4) <> aintRandomNumber(1) _
    And aintRandomNumber(4) <> 0
        aintRandomNumber(4) = CInt((Rnd * 7) + 1)
    Loop

'Pick A Different Number
    Do Until aintRandomNumber(5) <> aintRandomNumber(4) _
    And aintRandomNumber(5) <> aintRandomNumber(3) _
    And aintRandomNumber(5) <> aintRandomNumber(2) _
    And aintRandomNumber(5) <> aintRandomNumber(1) _
    And aintRandomNumber(5) <> 0
        aintRandomNumber(5) = CInt((Rnd * 7) + 1)
    Loop

'Pick A Different Number
    Do Until aintRandomNumber(6) <> aintRandomNumber(5) _
    And aintRandomNumber(6) <> aintRandomNumber(4) _
    And aintRandomNumber(6) <> aintRandomNumber(3) _
    And aintRandomNumber(6) <> aintRandomNumber(2) _
    And aintRandomNumber(6) <> aintRandomNumber(1) _
    And aintRandomNumber(6) <> 0
        aintRandomNumber(6) = CInt((Rnd * 7) + 1)
    Loop

'Pick A Different Number
    Do Until aintRandomNumber(7) <> aintRandomNumber(6) _
    And aintRandomNumber(7) <> aintRandomNumber(5) _
    And aintRandomNumber(7) <> aintRandomNumber(4) _
    And aintRandomNumber(7) <> aintRandomNumber(3) _
    And aintRandomNumber(7) <> aintRandomNumber(2) _
    And aintRandomNumber(7) <> aintRandomNumber(1) _
    And aintRandomNumber(7) <> 0
        aintRandomNumber(7) = CInt((Rnd * 7) + 1)
    Loop

'Pick A Different Number
    Do Until aintRandomNumber(8) <> aintRandomNumber(7) _
    And aintRandomNumber(8) <> aintRandomNumber(6) _
    And aintRandomNumber(8) <> aintRandomNumber(5) _
    And aintRandomNumber(8) <> aintRandomNumber(4) _
    And aintRandomNumber(8) <> aintRandomNumber(3) _
    And aintRandomNumber(8) <> aintRandomNumber(2) _
    And aintRandomNumber(8) <> aintRandomNumber(1) _
    And aintRandomNumber(8) <> 0
        aintRandomNumber(8) = CInt((Rnd * 7) + 1)
    Loop

End Sub

Private Sub btnChoice_Click(Index As Integer)

'Check Turn
    If boolFirstChoice = False Then
        astrChoices(1) = imgPicture(Index).Tag
        intFirstChoice = Index
        boolFirstChoice = True
    Else
        astrChoices(2) = imgPicture(Index).Tag
        boolFirstChoice = False
    End If

'Visable Image Behind Button
    btnChoice(Index).Vasable = False
    imgPixture(Index).Visable = True

'Replay  For Second Choice

    If boolFirstChoice = False Then
        'MsgBox The Player
        If astrChoice(1) = astrChoice(2) Then
        aboolVisablePositions(intFirstChoice) = True
        aboolVisablePositions(Index) = True
            MsgBox "Matched"
        Else
            MsgBox "Not matched"
        End If
        'Undo Choice
        Call UndoChoice
    End If

'If All Positions Are Visable Exit Program
    If AllPostionsVisable = True Then
        MsgBox "Game done"
        End
    End If
End Sub

Private Sub UndoChoice()

'Declare
    Dim intNextNumber As Integer

'Show All Buttons
    For intNextNumber = 1 To 8
        If btnChoice(intNextNumber).Visable = False _
        And aboolVisablePostions(intNextNumber) = False Then
            btnChoice(intNextNumber).Visable = True
            imgPixture(intNextNumber).Visable = False
        End If
    Next

End Sub

Private Function AllPositionsVisable() As Boolean

'Declare
    Dim intNextNumber As Integer
'Check All positions
    For intNextNumber = 1 To 8
        If aboolVisablePosition(intNextNumber) = False Then
            AllPositionsVisable = False
            Exit Function
        End If
    Next
'Return
    AllPositionsVisable = True
End Function


'Declare
    Dim intNextNumber As Integer
Replay
'Check All positions
    For intNextNumber = 1 To 8
        If aboolVisablePostions(intNextNumber) = False Then
            AllPositionsVisable = False
            Exit Function
        End If
    Next
'Return Function
    AllPositionsVisable = True

End Function

Private Sub Form_Unload(Cancel As Integer)

'Empty Form Memory
    Set frmMemoryGame = Nothing
End Sub



Signaure Hamer Dev .inc
 
Odgovor na temu

bokinet

Član broj: 29844
Poruke: 574



+50 Profil

icon Re: Run Time Error 361 Can't Load or unload this object13.05.2020. u 20:27 - pre 47 meseci
- Verovatno sto vec postoji ucitana kontrola tj. objekat
- Pre ucitavanja proveriti da li kontrola tj. objekat sa index-om vec postoji.
- Ako postoji onda je iskoristiti ili je ukloniti sa unload mycontrol(index) ako nije potrebna vise ili kako vec sta je potrebno.
 
Odgovor na temu

vidonk
Slobodan Vidovic
Niksic

Član broj: 192156
Poruke: 354
109.72.104.*



+9 Profil

icon Re: Run Time Error 361 Can't Load or unload this object13.05.2020. u 21:57 - pre 47 meseci
Citat:
bokinet: - Verovatno sto vec postoji ucitana kontrola tj. objekat
- Pre ucitavanja proveriti da li kontrola tj. objekat sa index-om vec postoji.
- Ako postoji onda je iskoristiti ili je ukloniti sa unload mycontrol(index) ako nije potrebna vise ili kako vec sta je potrebno.


Nemam iskustva sa VB-om možeš li da napišeš primjer koda kako da uradim to što si naveo ?
Signaure Hamer Dev .inc
 
Odgovor na temu

bokinet

Član broj: 29844
Poruke: 574



+50 Profil

icon Re: Run Time Error 361 Can't Load or unload this object14.05.2020. u 08:14 - pre 47 meseci

Code:


' On Form
' Add one TextBox control and set 'Index' property to 0
' Add one CommandButton control
' Add bellow code
' and Run (F5)

Option Explicit

Private Sub Form_Load()

   ' Load controls on form's load event
   LoadTextCtls
    
End Sub

Private Sub Command1_Click()

   ' Load controls on command1's click event
   LoadTextCtls

End Sub

Private Function CtlExistsByIndex(ByRef ThisControl As Variant, ByVal ThisIndex As Integer) As Boolean
    
    On Error GoTo ErrHandler
    
    ' If index >=0 and index < total items of control then
    If (ThisIndex >= 0) And (ThisIndex < ThisControl.Count) Then
    
        ' Return value
        CtlExistsByIndex = True
        
    Else
        
        ' Return value
        CtlExistsByIndex = False
    
    End If
    
Exit Function
ErrHandler:
    ' Raise Error
    Err.Raise Err.Number, "CtlExistsByIndex()", Err.Description
End Function

Private Sub LoadTextCtls()
    
    ' Array starts from 0 not from 1
    ' Load 10 TextBox controls
    ' By loading 10 more TextBox controls then in total will be 11 TextBox controls in control array and index value range will be [0...10]
    
    Dim i As Integer
    
    On Error GoTo ErrHandler
    
    For i = 1 To 10

        ' If control already exists then unload it before create it
        If CtlExistsByIndex(Text1, i) = True Then Unload Text1(i)
        
        ' Load control
        Load Text1(i)
        
        With Text1(i)
            
            ' Make control visible
            .Visible = True
            
            ' Set control position (left, top)
            .Move Text1(i).Left, Text1(0).Top + (i * (.Height + 60))
            
        End With
        
        ' Assign some foo text
        Text1(i).Text = Text1(0).Name & " index: " & i

    Next
    
Exit Sub
ErrHandler:
    ' Show message
    MsgBox Err.Number & " - " & Err.Description, vbCritical, "Error in LoadTextCtls"
End Sub

 
Odgovor na temu

vidonk
Slobodan Vidovic
Niksic

Član broj: 192156
Poruke: 354
109.72.104.*



+9 Profil

icon Re: Run Time Error 361 Can't Load or unload this object14.05.2020. u 12:43 - pre 47 meseci
Imao sam pravopisinh grešaka u kodu to sam ispravio i sad mi daje

Code:

Compile error
Variable not defined


I naznačen je kod

Code:

If AllPostionsVisible = True Then

Signaure Hamer Dev .inc
 
Odgovor na temu

bokinet

Član broj: 29844
Poruke: 574



+50 Profil

icon Re: Run Time Error 361 Can't Load or unload this object14.05.2020. u 12:58 - pre 47 meseci
Promenljiva nije definisana :)

Kada se koristi 'Option Explicit' na pocetku modula/dela gde se pise kod to znaci da je obavezno deklarisanje/definisanje svake promenljive pre nego sto se zapocne njeno koriscenje u ostatku dela koda.

VB6 takodje ako tip promenljive nije naveden vec samo ime ili ako uopste nije deklarisana promenljiva, tretira promenljivu kao Variant tip promenljive sto opet moze da bude problematicno iz vise uglova.

O tipovima promenljivih u VB6 predlazem da se malo procita HELP ili uzme neka knjiga ili pak malo google i nadju vb6 help i e-knjige.

Code:


... negde u kodu

' Ovo fali u zavisnosti opseg dostupnosti promenljive (vidljivost)

Dim AllPostionsVisible  As Boolean

ili

Public AllPostionsVisible  As Boolean

ili

Global AllPostionsVisible  As Boolean

...

' Onda tek sledi negde u kodu
If AllPostionsVisible = True Then ...  [ElseIf] ... [Else] ... End If

 
Odgovor na temu

[es] :: Visual Basic 6 :: Run Time Error 361 Can't Load or unload this object

[ Pregleda: 1244 | Odgovora: 5 ] > FB > Twit

Postavi temu Odgovori

Navigacija
Lista poslednjih: 16, 32, 64, 128 poruka.