PDA

Click to See Complete Forum and Search --> : [RESOLVED] [VB6]about timers in UC


joaquim
Mar 6th, 2009, 12:49 PM
i'm trying build a game with my Sprite... these game has 2 timers, but sprite control has more 3 timers....
when i use my sprite control, using the Top property, it give me an error: "the object doesn't support these property or method" but when i stop 1 timer(in my object, but the problem is that i need it) these message don't appear.... can anyone advice-me?
thanks

LaVolpe
Mar 6th, 2009, 03:20 PM
Can you show us the line(s) of code that is generating the error.

joaquim
Mar 6th, 2009, 03:28 PM
in game is the 2nd "if":
Private Sub sprPlayer_KeyDown(KeyCode As Integer, Shift As Integer)
If (KeyCode = vbKeyP Or KeyCode = vbKeyEscape) Then
frmPausa.Show
End If
If KeyCode = vbKeyUp Then
sprPlayer.Top = sprPlayer.Top - 10
End If
End Sub

in my UC is in timer, because when i desactive the timer the problem got out:
Private Sub tmrNewEvents_Timer()
Dim I As Integer
Dim Name As String
Dim ctlTemp As Control
Dim L1 As Long
Dim L2 As Long
Dim T1 As Long
Dim T2 As Long
Dim H1 As Long
Dim H2 As Long
Dim W1 As Long
Dim W2 As Long
Dim Direction As Direction
On Error Resume Next

If (blnActivateMoveNotMoveEvents = False And blnJoystickActivate = False) Then tmrNewEvents.Enabled = False
If blnActivateMoveNotMoveEvents = True Then
If (lngOldPosX < Extender.Left And lngOldPosY < Extender.Top) Then
DirDirection = DirectionLeftUp
ElseIf (lngOldPosX < Extender.Left And lngOldPosY > Extender.Top) Then
DirDirection = DirectionLeftDown
ElseIf (lngOldPosX > Extender.Left And lngOldPosY < Extender.Top) Then
DirDirection = DirectionRightUp
ElseIf (lngOldPosX > Extender.Left And lngOldPosY > Extender.Top) Then
DirDirection = DirectionRightDown
ElseIf (lngOldPosX < Extender.Left) Then
DirDirection = DirectionLeft
ElseIf (lngOldPosX > Extender.Left) Then
DirDirection = DirectionRight
ElseIf (lngOldPosY < Extender.Top) Then
DirDirection = DirectionUp
ElseIf (lngOldPosX > Extender.Top) Then
DirDirection = DirectionLeftDown
End If
If Extender.Left <> lngOldPosX Or Extender.Top <> lngOldPosY Then
lngOldPosX = Extender.Left
lngOldPosY = Extender.Top
RaiseEvent Move(lngOldPosX, lngOldPosY, DirDirection)
DoEvents
Name = Extender.Name
If Col.Activate = True Then
L1 = Extender.Left + Col.Left
T1 = Extender.Top + Col.Top
W1 = Col.Width
H1 = Col.Height
Else
L1 = lngOldPosX
T1 = lngOldPosY
W1 = Extender.Width
H1 = Extender.Height
End If
For I = 0 To Extender.Container.Controls.Count - 1
If Extender.Container.Controls(I).Name <> Name Then
If TypeName(Extender.Container.Controls(I)) = "Sprite" Then
If Extender.Container.Controls(I).LimColActivate = True Then
L2 = Extender.Container.Controls(I).Left + Extender.Container.Controls(I).LimColLeft
T2 = Extender.Container.Controls(I).Top + Extender.Container.Controls(I).LimColTop
W2 = Extender.Container.Controls(I).LimColWidth
H2 = Extender.Container.Controls(I).LimColHeight
Else
L2 = Extender.Container.Controls(I).Left
T2 = Extender.Container.Controls(I).Top
W2 = Extender.Container.Controls(I).Width
H2 = Extender.Container.Controls(I).Height
End If
If CollisionPrecise(L1, T1, W1, H1, L2, T2, W2, H2) = True Then
RaiseEvent Collision(Extender.Container.Controls(I).Name, IndexControlArray(Extender.Container.Controls(I)), DirDirection)
Exit For
DoEvents
End If
Else
L2 = Extender.Container.Controls(I).Left
T2 = Extender.Container.Controls(I).Top
W2 = Extender.Container.Controls(I).Width
H2 = Extender.Container.Controls(I).Height
If CollisionPrecise(L1, T1, W1, H1, L2, T2, W2, H2) = True Then
RaiseEvent Collision(Extender.Container.Controls(I).Name, IndexControlArray(Extender.Container.Controls(I)), DirDirection)
Exit For
DoEvents
End If
End If
End If
Next I
Else
RaiseEvent NotMove(lngOldPosX, lngOldPosY, DirDirection)
DoEvents
End If
End If
If (blnJoystickActivate = True And StartJoystick(0) = True) Then
Call PollJoystick
If (MYJOYEX.dwXpos = 0 And MYJOYEX.dwYpos = 0) Then
Direction = DirectionLeftUp
ElseIf (MYJOYEX.dwXpos = 0 And MYJOYEX.dwYpos = 65535) Then
Direction = DirectionLeftDown
ElseIf (MYJOYEX.dwXpos = 65535 And MYJOYEX.dwYpos = 0) Then
Direction = DirectionRightUp
ElseIf (MYJOYEX.dwXpos = 65535 And MYJOYEX.dwYpos = 65535) Then
Direction = DirectionRightDown
ElseIf (MYJOYEX.dwXpos = 0) Then
Direction = DirectionLeft
ElseIf (MYJOYEX.dwXpos = 65535) Then
Direction = DirectionRight
ElseIf (MYJOYEX.dwYpos = 0) Then
Direction = DirectionUp
ElseIf (MYJOYEX.dwYpos = 65535) Then
Direction = DirectionDown
Else
Direction = DirectionNone
End If
RaiseEvent Joystick(JoyNum, Direction, lngButton)
DoEvents
End If
End Sub
but in my form teste(where i test these control), i don't recive any error...

LaVolpe
Mar 7th, 2009, 09:29 AM
Is sprPlayer a control in your uc? Or is sprPlayer a dynamic control that you change during runtime? When you get the error, can you debug.print these and show us the result.

Debug.Print (sprPlayer Is Nothing)
Debug.Print TypeName(sprPlayer)

joaquim
Mar 7th, 2009, 09:40 AM
Is sprPlayer a control in your uc? Or is sprPlayer a dynamic control that you change during runtime? When you get the error, can you debug.print these and show us the result.

Debug.Print (sprPlayer Is Nothing)
Debug.Print TypeName(sprPlayer)
the sprPlayer is an instance of my Sprite control.
Debug.Print (sprPlayer Is Nothing)=false
Debug.Print TypeName(sprPlayer)=sprite

joaquim
Mar 7th, 2009, 09:54 AM
see you self...
in Sprite folder is where you must compile the Sprite and put it in CatchDiamonds folder...
then test the game CatchDiamonds... use the Up key...
i'm rebuild the entire game, but now just crash:(
i'm sorry if i give you much work... thanks

LaVolpe
Mar 7th, 2009, 11:31 AM
You might want to update your last posting and include your project also as Zip files. Not everyone uses WinRar.

joaquim
Mar 7th, 2009, 02:38 PM
(help me on these 1 zip file is 900Kb's... i have winzip 9... how can i zip the file with 500Kb(for example) by parts?
thanks)

deathfxu
Mar 9th, 2009, 12:52 PM
Okay, the problem is not with:

If KeyCode = vbKeyUp Then
sprPlayer.Top = sprPlayer.Top - 10
End If

The problem is with the code right before it that you didn't post above. sprPlayer is a picturebox and .Filename is not a valid property of a picturebox. To change the picture in a picturebox, do this:

Private Sub sprPlayer_KeyDown(KeyCode As Integer, Shift As Integer)
If KeyCode = vbKeyP Then
MsgBox "Pause"
End If
If KeyCode = vbKeyEscape Then
End
End If
If KeyCode = vbKeyUp Then
If blnCollisionUp = True Then
If plPlayer = Male Then
'If sprPlayer.FileName <> App.Path & "\Images\Male Player\Stoped\Up.gif" Then sprPlayer.FileName = App.Path & "\Images\Male Player\Stoped\Up.gif"
sprPlayer.Picture = LoadPicture(App.Path & "\Images\Male Player\Stoped\Up.gif")
Else
'If sprPlayer.FileName <> App.Path & "\Images\Female Player\Stoped\Up.gif" Then sprPlayer.FileName = App.Path & "\Images\Female Player\Stoped\Up.gif"
sprPlayer.Picture = LoadPicture(App.Path & "\Images\Female Player\Stoped\Up.gif")
End If
Else
If plPlayer = Male Then
'If sprPlayer.FileName <> App.Path & "\Images\Male Player\Movement\Up.gif" Then sprPlayer.FileName = App.Path & "\Images\Male Player\Movement\Up.gif"
sprPlayer.Picture = LoadPicture(App.Path & "\Images\Male Player\Movement\Up.gif")
Else
'If sprPlayer.FileName <> App.Path & "\Images\Female Player\Movement\Up.gif" Then sprPlayer.FileName = App.Path & "\Images\Female Player\Movement\Up.gif"
sprPlayer.Picture = LoadPicture(App.Path & "\Images\Female Player\Movement\Up.gif")
End If
sprPlayer.Top = sprPlayer.Top - 10
End If
End If
End Sub

Private Sub Form_Load()
picGame.Picture = LoadPicture(App.Path & "\Images\Background\Level1.gif")
plPlayer = Male
blnCollisionDown = False
blnCollisionLeft = False
blnCollisionRight = False
blnCollisionUp = False
picGame.Picture = LoadPicture(App.Path & "\Images\Background\Level1.gif")
If plPlayer = Male Then
'If sprPlayer.Picture <> App.Path & "\Images\Male Player\Stoped\Up.gif" Then sprPlayer.FileName = App.Path & "\Images\Male Player\Stoped\Up.gif"
sprPlayer.Picture = LoadPicture(App.Path & "\Images\Male Player\Stoped\Up.gif")
Else
'If sprPlayer.Picture <> App.Path & "\Images\Female Player\Stoped\Up.gif" Then sprPlayer.FileName = App.Path & "\Images\Female Player\Stoped\Up.gif"
sprPlayer.Picture = LoadPicture(App.Path & "\Images\Female Player\Stoped\Up.gif")
End If
End Sub

To check to see which picture is in the box, you might want to have a variable that is changed every time you load a new picture into the picturebox that will tell you what the last one loaded was.

If you need example code of this, just let me know.

Enjoy. :)

joaquim
Mar 9th, 2009, 03:53 PM
Okay, the problem is not with:

If KeyCode = vbKeyUp Then
sprPlayer.Top = sprPlayer.Top - 10
End If

The problem is with the code right before it that you didn't post above. sprPlayer is a picturebox and .Filename is not a valid property of a picturebox. To change the picture in a picturebox, do this:

Private Sub sprPlayer_KeyDown(KeyCode As Integer, Shift As Integer)
If KeyCode = vbKeyP Then
MsgBox "Pause"
End If
If KeyCode = vbKeyEscape Then
End
End If
If KeyCode = vbKeyUp Then
If blnCollisionUp = True Then
If plPlayer = Male Then
'If sprPlayer.FileName <> App.Path & "\Images\Male Player\Stoped\Up.gif" Then sprPlayer.FileName = App.Path & "\Images\Male Player\Stoped\Up.gif"
sprPlayer.Picture = LoadPicture(App.Path & "\Images\Male Player\Stoped\Up.gif")
Else
'If sprPlayer.FileName <> App.Path & "\Images\Female Player\Stoped\Up.gif" Then sprPlayer.FileName = App.Path & "\Images\Female Player\Stoped\Up.gif"
sprPlayer.Picture = LoadPicture(App.Path & "\Images\Female Player\Stoped\Up.gif")
End If
Else
If plPlayer = Male Then
'If sprPlayer.FileName <> App.Path & "\Images\Male Player\Movement\Up.gif" Then sprPlayer.FileName = App.Path & "\Images\Male Player\Movement\Up.gif"
sprPlayer.Picture = LoadPicture(App.Path & "\Images\Male Player\Movement\Up.gif")
Else
'If sprPlayer.FileName <> App.Path & "\Images\Female Player\Movement\Up.gif" Then sprPlayer.FileName = App.Path & "\Images\Female Player\Movement\Up.gif"
sprPlayer.Picture = LoadPicture(App.Path & "\Images\Female Player\Movement\Up.gif")
End If
sprPlayer.Top = sprPlayer.Top - 10
End If
End If
End Sub

Private Sub Form_Load()
picGame.Picture = LoadPicture(App.Path & "\Images\Background\Level1.gif")
plPlayer = Male
blnCollisionDown = False
blnCollisionLeft = False
blnCollisionRight = False
blnCollisionUp = False
picGame.Picture = LoadPicture(App.Path & "\Images\Background\Level1.gif")
If plPlayer = Male Then
'If sprPlayer.Picture <> App.Path & "\Images\Male Player\Stoped\Up.gif" Then sprPlayer.FileName = App.Path & "\Images\Male Player\Stoped\Up.gif"
sprPlayer.Picture = LoadPicture(App.Path & "\Images\Male Player\Stoped\Up.gif")
Else
'If sprPlayer.Picture <> App.Path & "\Images\Female Player\Stoped\Up.gif" Then sprPlayer.FileName = App.Path & "\Images\Female Player\Stoped\Up.gif"
sprPlayer.Picture = LoadPicture(App.Path & "\Images\Female Player\Stoped\Up.gif")
End If
End Sub

To check to see which picture is in the box, you might want to have a variable that is changed every time you load a new picture into the picturebox that will tell you what the last one loaded was.

If you need example code of this, just let me know.

Enjoy. :)
i'm sorry but isn't a picturebox, it's my sprite control you must compile it(is in *.rar files)... i'm sorry about that....
please compile my sprite control then put in game folder, Catch Dimonds, then run it again and test it... i'm sorry and thanks

deathfxu
Mar 13th, 2009, 06:02 PM
lol. When I opened the project there was a picturebox of the same name in the middle of the form. Sorry man, i'll rerun it.

joaquim
Mar 13th, 2009, 06:11 PM
"lol. When I opened the project there was a picturebox of the same name in the middle of the form."
that's normal, after the error... after you compile my sprite and put it in folder game and run the project and click up key, you will see the error.
try test it putting the MoveNotMove and JoystickActivate true and false(you will see that the error is out)... but i need these properties true.

"Sorry man, i'll rerun it"
that's ok... honestly, thanks for you trying help me;)

deathfxu
Mar 13th, 2009, 06:30 PM
I kept getting an error in the Sprite project when you were trying to set MaskColor to "Null". I changed it to "vbNull", recompiled, ran CatchDiamonds, and when I hit the up key Visual Basic froze, lol.

So this might take a few mins. =P

Edit: "Hard Froze". Like [ctrl]+[pausebreak] didn't even work.

joaquim
Mar 13th, 2009, 06:35 PM
I kept getting an error in the Sprite project when you were trying to set MaskColor to "Null". I changed it to "vbNull", recompiled, ran CatchDiamonds, and when I hit the up key Visual Basic froze, lol.

So this might take a few mins. =P

Edit: "Hard Froze". Like [ctrl]+[pausebreak] didn't even work.
yes... i test(only know) that error... before it don't give me the error:(
i'm confuse with these:(
thanks for help me

deathfxu
Mar 13th, 2009, 07:07 PM
Okay, this program is so massive it's taking me a while to trace it through. Do you know why Sprite.ocx is calling the ShowImage sub like 20 times right when it starts up?

joaquim
Mar 13th, 2009, 07:19 PM
Okay, this program is so massive it's taking me a while to trace it through. Do you know why Sprite.ocx is calling the ShowImage sub like 20 times right when it starts up?
20 times!?!
i think not.... only in some properties...

deathfxu
Mar 13th, 2009, 07:23 PM
Never mind. I just realized that every graphics-related Property Let statement recalls it for each time when you are initializing all the values.

deathfxu
Mar 13th, 2009, 07:33 PM
In the CatchDiamonds project, the sprPlayer_KeyDown is only getting called the first time you press a key, but neither project is getting stuck in an infinite loop.

Which means something may be disabling the event trigger for it.

Still looking.

deathfxu
Mar 13th, 2009, 07:47 PM
FINALLY!!!

Almost 2 hours later.

First change:

Public Property Let FileName(New_FileName As String)
Dim I As Integer
strFileName = New_FileName
tmrAnimation.Enabled = False
If (Dir(strFileName) = "" Or ValidFile(UCase(strFileName)) = False) Then
UserControl.Picture = Nothing
UserControl.MaskPicture = Nothing
UserControl.MaskColor = Null 'Change this to "vbNull"

Then, the usercontrol Sprite.ocx is losing focus after the first keypress. Into the form and all objects on it in _KeyDown I added:

Call sprPlayer_KeyDown(KeyCode, Shift)

And it worked. If you can't duplicate this, lemme know.

deathfxu
Mar 13th, 2009, 07:50 PM
Also, to help debugging, I removed your test project "teste", and added frmLevel1 to the project and set it as the startup object. It allowed me to breakpoint both projects at once.

I can walk you through how to do that also if you don't understand what I mean.

joaquim
Mar 14th, 2009, 06:20 AM
FINALLY!!!

Almost 2 hours later.

First change:

Public Property Let FileName(New_FileName As String)
Dim I As Integer
strFileName = New_FileName
tmrAnimation.Enabled = False
If (Dir(strFileName) = "" Or ValidFile(UCase(strFileName)) = False) Then
UserControl.Picture = Nothing
UserControl.MaskPicture = Nothing
UserControl.MaskColor = Null 'Change this to "vbNull"

Then, the usercontrol Sprite.ocx is losing focus after the first keypress. Into the form and all objects on it in _KeyDown I added:

Call sprPlayer_KeyDown(KeyCode, Shift)

And it worked. If you can't duplicate this, lemme know.
i have 1 question: if the sprPlayer TabIndex property is 0, why it loses the focus?
thanks

joaquim
Mar 14th, 2009, 06:22 AM
Also, to help debugging, I removed your test project "teste", and added frmLevel1 to the project and set it as the startup object. It allowed me to breakpoint both projects at once.

I can walk you through how to do that also if you don't understand what I mean.
if you have the frmLevel1 in Sprite project, how can you compile the OCX file?
thanks

joaquim
Mar 14th, 2009, 08:39 AM
i continue with same problem:(
i'm trying without sucess :(

joaquim
Mar 14th, 2009, 09:19 AM
i found where is the error, but i don't understand it:(
MsgBox "oi"
If Extender.Container.Controls.Count > 1 Then
For I = 0 To Extender.Container.Controls.Count - 1
If Extender.Container.Controls(I).Name <> Name Then
If TypeName(Extender.Container.Controls(I)) = "Sprite" Then
If Extender.Container.Controls(I).LimColActivate = True Then
L2 = Extender.Container.Controls(I).Left + Extender.Container.Controls(I).LimColLeft
T2 = Extender.Container.Controls(I).Top + Extender.Container.Controls(I).LimColTop
W2 = Extender.Container.Controls(I).LimColWidth
H2 = Extender.Container.Controls(I).LimColHeight
Else
L2 = Extender.Container.Controls(I).Left
T2 = Extender.Container.Controls(I).Top
W2 = Extender.Container.Controls(I).Width
H2 = Extender.Container.Controls(I).Height
End If
If CollisionPrecise(L1, T1, W1, H1, L2, T2, W2, H2) = True Then
RaiseEvent Collision(Extender.Container.Controls(I).Name, IndexControlArray(Extender.Container.Controls(I)), DirDirection)
Exit For
DoEvents
End If
Else
L2 = Extender.Container.Controls(I).Left
T2 = Extender.Container.Controls(I).Top
W2 = Extender.Container.Controls(I).Width
H2 = Extender.Container.Controls(I).Height
If CollisionPrecise(L1, T1, W1, H1, L2, T2, W2, H2) = True Then
RaiseEvent Collision(Extender.Container.Controls(I).Name, IndexControlArray(Extender.Container.Controls(I)), DirDirection)
Exit For
DoEvents
End If
End If
End If
Next I
End If
Else
RaiseEvent NotMove(lngOldPosX, lngOldPosY, DirDirection)
DoEvents
End If
End If
the messagebox is showed, but then is give me an error(i use the messagebox for catch the error;))
if i put the messagebox in the If statement, i will recive the error...
what isn't right with these line:
Extender.Container.Controls.Count > 1
????
error message: "these object doesn't support this property or method"
thanks

deathfxu
Mar 15th, 2009, 06:59 PM
i have 1 question: if the sprPlayer TabIndex property is 0, why it loses the focus?
thanks

No. TabIndex changes the order that controls get focus when you press the [tab] key.

deathfxu
Mar 15th, 2009, 07:00 PM
if you have the frmLevel1 in Sprite project, how can you compile the OCX file?
thanks

I wasn't compiling it, I was just running it straight out of the project. :)

deathfxu
Mar 15th, 2009, 07:09 PM
i found where is the error, but i don't understand it:(
the messagebox is showed, but then is give me an error(i use the messagebox for catch the error;))
if i put the messagebox in the If statement, i will recive the error...
what isn't right with these line:
Extender.Container.Controls.Count > 1
????
error message: "these object doesn't support this property or method"
thanks

I didn't get any error here. I left the project on my computer in case you had any problems, and I just went back in and ran it with no problems. I'm tempted to just send the files back to you.

Have you been making other changes?

joaquim
Mar 20th, 2009, 04:17 PM
"I didn't get any error here. I left the project on my computer in case you had any problems, and I just went back in and ran it with no problems. I'm tempted to just send the files back to you."
i belive you don't get the error, but try compile it and try use it in other project... use any key for move it... here you will see it.

"Have you been making other changes?"
yes...
UserControl.Parent.Controls.Count
isn't the same but works fine for it is.... but i'm continue testing