|
-
Mar 9th, 2008, 03:30 PM
#1
Thread Starter
Junior Member
last Question [About this]
Alright, I basicly have my project done. I got it to spam 2 textboxes, each 5 times, then switching to the other.
Now the problem is, when I press F4, the program doesnt seem to stop. it just keeps spamming. heres the code, can any1 tell me whats wrong.
Code:
Private Declare Function GetKeyPress Lib "user32" Alias "GetAsyncKeyState" (ByVal key As Long) As Integer
Dim intCtr As Integer
Dim intCbr As Integer
Private Sub Timer1_Timer()
If GetKeyPress(vbKeyF3) Then
intCtr = 0
intCbr = 0
Timer3.Enabled = True
If GetKeyPress(vbKeyF5) Then
intCtr = 0
intCbr = 0
Timer3.Enabled = False
End If
End If
End Sub
Private Sub Timer2_Timer()
intCbr = intCbr + 1
'Special Cant tell Code -_-
If intCbr = 5 Then
Timer2.Enabled = False
intCbr = 0
Timer3.Enabled = True
End If
End Sub
Private Sub Timer3_Timer()
intCtr = intCtr + 1
'Special Cant tell Code -_-
If intCtr = 5 Then
Timer3.Enabled = False
intCtr = 0
Timer2.Enabled = True
End If
End Sub
-
Mar 10th, 2008, 02:59 AM
#2
Re: last Question [About this]
I don't see any code watching for a "F4" key press, so not sure what you expect to happen? If you want to exit a program TRY using Alt+F4.
-
Mar 10th, 2008, 07:01 AM
#3
Thread Starter
Junior Member
Re: last Question [About this]
I meant F5. sorry for the misspell. Anyways when I press F5 it doesnt stop.
-
Mar 10th, 2008, 07:14 AM
#4
Re: last Question [About this]
Are you running this from the IDE?
If so, that might be because F5 is the shortcut for Start.
-
Mar 10th, 2008, 12:05 PM
#5
Thread Starter
Junior Member
Re: last Question [About this]
Ive had no problems with this on my last version of the program tbh. I tried F4 to F8 also, none of them worked, its something with the code, but I cant figure out what it is =(.
-
Mar 14th, 2008, 02:43 AM
#6
Thread Starter
Junior Member
Re: last Question [About this]
Bump^ Plz people I need some help with this, Ive been looking at this for quite some time and I just cant figure out what my error in the code is, but its there definitely.
To explain it more clearly:
I tried everything from F4 to F12, so it cant be that Im pressing the wrong shortcut or anything.
It worked before but since the code is different this time seeing as there are more things added I cant figure out whats wrong.
So plz, some1 fix my code.
-
Mar 14th, 2008, 05:22 AM
#7
Re: last Question [About this]
 Originally Posted by Hertebeest
Code:
Private Sub Timer1_Timer()
If GetKeyPress(vbKeyF3) Then
intCtr = 0
intCbr = 0
Timer3.Enabled = True
If GetKeyPress(vbKeyF5) Then
intCtr = 0
intCbr = 0
Timer3.Enabled = False
End If
End If
End Sub
This part of your code will never work if you press F5, because the second If sits inside the first If. It may only work if you press F3 then followed by F5.
Coding Practice: Try to indent properly it will be easier to see as above.
Try to change it like this:
Code:
Private Sub Timer1_Timer()
If GetKeyPress(vbKeyF3) Then
intCtr = 0
intCbr = 0
Timer3.Enabled = True
ElseIf GetKeyPress(vbKeyF5) Then
intCtr = 0
intCbr = 0
Timer3.Enabled = False
End If
End Sub
-
Mar 15th, 2008, 01:07 PM
#8
Thread Starter
Junior Member
Re: last Question [About this]
Thx mate, it works perfectly now <3 =D
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|