Results 1 to 8 of 8

Thread: last Question [About this]

  1. #1

    Thread Starter
    Junior Member
    Join Date
    Oct 2007
    Posts
    18

    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

  2. #2
    VB For Fun Edgemeal's Avatar
    Join Date
    Sep 2006
    Location
    WindowFromPoint
    Posts
    4,255

    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.

  3. #3

    Thread Starter
    Junior Member
    Join Date
    Oct 2007
    Posts
    18

    Re: last Question [About this]

    I meant F5. sorry for the misspell. Anyways when I press F5 it doesnt stop.

  4. #4
    I'm about to be a PowerPoster! Hack's Avatar
    Join Date
    Aug 2001
    Location
    Searching for mendhak
    Posts
    58,333

    Re: last Question [About this]

    Are you running this from the IDE?

    If so, that might be because F5 is the shortcut for Start.

  5. #5

    Thread Starter
    Junior Member
    Join Date
    Oct 2007
    Posts
    18

    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 =(.

  6. #6

    Thread Starter
    Junior Member
    Join Date
    Oct 2007
    Posts
    18

    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.

  7. #7
    Head Hunted anhn's Avatar
    Join Date
    Aug 2007
    Location
    Australia
    Posts
    3,669

    Re: last Question [About this]

    Quote 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
    • Don't forget to use [CODE]your code here[/CODE] when posting code
    • If your question was answered please use Thread Tools to mark your thread [RESOLVED]
    • Don't forget to RATE helpful posts

    • Baby Steps a guided tour
    • IsDigits() and IsNumber() functions • Wichmann-Hill Random() function • >> and << functions for VB • CopyFileByChunk

  8. #8

    Thread Starter
    Junior Member
    Join Date
    Oct 2007
    Posts
    18

    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
  •  



Click Here to Expand Forum to Full Width