Results 1 to 11 of 11

Thread: [RESOLVED] [VB6] - key event vs message box

  1. #1

    Thread Starter
    PowerPoster joaquim's Avatar
    Join Date
    Apr 2007
    Posts
    3,962

    Resolved [RESOLVED] [VB6] - key event vs message box

    when i use a message box, how can i ignore the key event?
    because if i press 1 key and then the message box is activated. after the message box desapper, the key event continues active.
    how can i avoid these problem?
    Last edited by joaquim; Feb 15th, 2010 at 09:48 AM.
    VB6 2D Sprite control

    To live is difficult, but we do it.

  2. #2
    Freelancer akhileshbc's Avatar
    Join Date
    Jun 2008
    Location
    Trivandrum, Kerala, India
    Posts
    7,652

    Re: [VB6] - key vs message box

    You mean this...???
    Code:
    Option Explicit
    
    Private Sub Form_KeyDown(KeyCode As Integer, Shift As Integer)
       Debug.Print "Before"
       MsgBox "Hello"      '~~~> Display a message box
       Debug.Print "After" '~~~> Works only after the Msgbox is closed (or OK button is pressed)
    End Sub

    If my post was helpful to you, then express your gratitude using Rate this Post.
    And if your problem is SOLVED, then please Mark the Thread as RESOLVED (see it in action - video)
    My system: AMD FX 6100, Gigabyte Motherboard, 8 GB Crossair Vengance, Cooler Master 450W Thunder PSU, 1.4 TB HDD, 18.5" TFT(Wide), Antec V1 Cabinet

    Social Group: VBForums - Developers from India


    Skills: PHP, MySQL, jQuery, VB.Net, Photoshop, CodeIgniter, Bootstrap,...

  3. #3

    Thread Starter
    PowerPoster joaquim's Avatar
    Join Date
    Apr 2007
    Posts
    3,962

    Re: [VB6] - key vs message box

    Quote Originally Posted by akhileshbc View Post
    You mean this...???
    Code:
    Option Explicit
    
    Private Sub Form_KeyDown(KeyCode As Integer, Shift As Integer)
       Debug.Print "Before"
       MsgBox "Hello"      '~~~> Display a message box
       Debug.Print "After" '~~~> Works only after the Msgbox is closed (or OK button is pressed)
    End Sub
    not in these way. the message box is called by another sub. is why i can't resolve it.
    (if you want, i PM you with my project(has 1 ocx file, my Sprite control))
    VB6 2D Sprite control

    To live is difficult, but we do it.

  4. #4
    Freelancer akhileshbc's Avatar
    Join Date
    Jun 2008
    Location
    Trivandrum, Kerala, India
    Posts
    7,652

    Re: [VB6] - key event vs message box

    Can you post that sub part...???

    If my post was helpful to you, then express your gratitude using Rate this Post.
    And if your problem is SOLVED, then please Mark the Thread as RESOLVED (see it in action - video)
    My system: AMD FX 6100, Gigabyte Motherboard, 8 GB Crossair Vengance, Cooler Master 450W Thunder PSU, 1.4 TB HDD, 18.5" TFT(Wide), Antec V1 Cabinet

    Social Group: VBForums - Developers from India


    Skills: PHP, MySQL, jQuery, VB.Net, Photoshop, CodeIgniter, Bootstrap,...

  5. #5

    Thread Starter
    PowerPoster joaquim's Avatar
    Join Date
    Apr 2007
    Posts
    3,962

    Re: [VB6] - key event vs message box

    Quote Originally Posted by akhileshbc View Post
    Can you post that sub part...???
    in colision event(i have a timer in control to test the move event and after the colision event):
    Code:
    If sprPoints(ObjectIndex).Visible = True Then
                sprPoints(ObjectIndex).Visible = False
                lngPoints = lngPoints + 10
                txtPoints.Text = "Points: " & Format(lngPoints, "0000")
                Points = Points + 1
                If Points = lngDiamonds Then
                    txtPoints.Text = "Congratulatious - Points: " & Format(lngPoints, "0000")
                    txtPoints.Width = 3900
                    If MsgBox("Did you want restart the game?", vbYesNo, "Restart the game...") = vbYes Then
                        Call RestartGame
                    Else
                        End
                    End If
                End If
            End If
    VB6 2D Sprite control

    To live is difficult, but we do it.

  6. #6
    Freelancer akhileshbc's Avatar
    Join Date
    Jun 2008
    Location
    Trivandrum, Kerala, India
    Posts
    7,652

    Re: [VB6] - key event vs message box

    Include the line Exit Sub after the msgbox. It will prevent the rest of the code from executing.(If that is not what you want, then please explain it... ) ...

    If my post was helpful to you, then express your gratitude using Rate this Post.
    And if your problem is SOLVED, then please Mark the Thread as RESOLVED (see it in action - video)
    My system: AMD FX 6100, Gigabyte Motherboard, 8 GB Crossair Vengance, Cooler Master 450W Thunder PSU, 1.4 TB HDD, 18.5" TFT(Wide), Antec V1 Cabinet

    Social Group: VBForums - Developers from India


    Skills: PHP, MySQL, jQuery, VB.Net, Photoshop, CodeIgniter, Bootstrap,...

  7. #7

    Thread Starter
    PowerPoster joaquim's Avatar
    Join Date
    Apr 2007
    Posts
    3,962

    Re: [VB6] - key event vs message box

    Quote Originally Posted by akhileshbc View Post
    Include the line Exit Sub after the msgbox. It will prevent the rest of the code from executing.(If that is not what you want, then please explain it... ) ...
    i try use a boolean variable, but without sucess. i activate the varible before the message box for try cancel the keycode variable(in key event). but without sucess
    and i try in these way too:
    Code:
    If Points = lngDiamonds Then
                KeyCode = 0
                Exit Sub
            End If
    anotherthing my keydown event(in my control) has 1ms in interval of the timer
    Last edited by joaquim; Feb 15th, 2010 at 10:25 AM.
    VB6 2D Sprite control

    To live is difficult, but we do it.

  8. #8
    VB-aholic & Lovin' It LaVolpe's Avatar
    Join Date
    Oct 2007
    Location
    Beside Waldo
    Posts
    19,541

    Re: [VB6] - key event vs message box

    If your timer using APIs to monitor the keyboard? If so, disable the timer before displaying the msgbox and re-enable if a new game is about to begin. The timers should probably be disabled after the game is over anyway, no?
    Insomnia is just a byproduct of, "It can't be done"

    Classics Enthusiast? Here's my 1969 Mustang Mach I Fastback. Her sister '67 Coupe has been adopted

    Newbie? Novice? Bored? Spend a few minutes browsing the FAQ section of the forum.
    Read the HitchHiker's Guide to Getting Help on the Forums.
    Here is the list of TAGs you can use to format your posts
    Here are VB6 Help Files online


    {Alpha Image Control} {Memory Leak FAQ} {Unicode Open/Save Dialog} {Resource Image Viewer/Extractor}
    {VB and DPI Tutorial} {Manifest Creator} {UserControl Button Template} {stdPicture Render Usage}

  9. #9

    Thread Starter
    PowerPoster joaquim's Avatar
    Join Date
    Apr 2007
    Posts
    3,962

    Re: [VB6] - key event vs message box

    Quote Originally Posted by LaVolpe View Post
    If your timer using APIs to monitor the keyboard? If so, disable the timer before displaying the msgbox and re-enable if a new game is about to begin. The timers should probably be disabled after the game is over anyway, no?
    hi LaVolte
    by some reason i can't use my api timer control, but i remember(by you) that i can use the code instead the control
    the variable, before msgbox that i can use is poinst compared by lngdiamonds, but still not working.
    (can i send to you my project, by pm you(i have 1 ocx file)?)
    thanks
    VB6 2D Sprite control

    To live is difficult, but we do it.

  10. #10
    VB-aholic & Lovin' It LaVolpe's Avatar
    Join Date
    Oct 2007
    Location
    Beside Waldo
    Posts
    19,541

    Re: [VB6] - key event vs message box

    We shouldn't need to view a complex ocx. What do you mean exactly by the following statement:
    anotherthing my keydown event(in my control) has 1ms in interval of the timer
    That is where I think the problem is. You shouldn't be monitoring the keyboard with timers/APIs while displaying message boxes or when the game terminates. Keep this in mind too. In IDE, MsgBoxes pause timers until the msgbox closes. When compiled, this is not true, the timers will not pause.
    Insomnia is just a byproduct of, "It can't be done"

    Classics Enthusiast? Here's my 1969 Mustang Mach I Fastback. Her sister '67 Coupe has been adopted

    Newbie? Novice? Bored? Spend a few minutes browsing the FAQ section of the forum.
    Read the HitchHiker's Guide to Getting Help on the Forums.
    Here is the list of TAGs you can use to format your posts
    Here are VB6 Help Files online


    {Alpha Image Control} {Memory Leak FAQ} {Unicode Open/Save Dialog} {Resource Image Viewer/Extractor}
    {VB and DPI Tutorial} {Manifest Creator} {UserControl Button Template} {stdPicture Render Usage}

  11. #11

    Thread Starter
    PowerPoster joaquim's Avatar
    Join Date
    Apr 2007
    Posts
    3,962

    Re: [VB6] - key event vs message box

    Quote Originally Posted by LaVolpe View Post
    We shouldn't need to view a complex ocx. What do you mean exactly by the following statement:

    That is where I think the problem is. You shouldn't be monitoring the keyboard with timers/APIs while displaying message boxes or when the game terminates. Keep this in mind too. In IDE, MsgBoxes pause timers until the msgbox closes. When compiled, this is not true, the timers will not pause.
    finaly i resolve the problem... and yes, i give up from the messagebox and i build 1 form for work like messagebox. and resolve my problem
    thanks
    VB6 2D Sprite control

    To live is difficult, but we do it.

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