Results 1 to 8 of 8

Thread: Very Peculiar happenings - help!?

  1. #1

    Thread Starter
    Addicted Member
    Join Date
    Jan 2000
    Location
    Sydney, Australia
    Posts
    196

    Post

    Hello, i have some code that i am working on. I've simplified it greatly below to simulate my problem. If you open up a new project <standard Exe>, place a button and a text box on the form and put the following code in the form code.


    Private Sub Command1_Click()
    MsgBox "click"
    End Sub

    Private Sub Text1_LostFocus()
    MsgBox "lost focus"
    End Sub


    Then if you place the cursor in the text box and click on the button you see "lost focus" and then nothing. What i want <and would expect to see> is "lost focus" and then "click".

    Can anyone help me as to why the "click" event is being lost in this situation? Does the raising of the lostfocus event mean that no other events are triggered?

    I really need to find out why this is happening and what i can do about it so if anyone can help, it would be very appreciated.

    Thanks,

    Mark

  2. #2
    Hyperactive Member Juan Carlos Rey's Avatar
    Join Date
    Aug 1999
    Location
    Mendoza, Argentina
    Posts
    301

    Post

    That is exactly the behaviour I had on mine.

    It seems as if VB can't handle more than one MsgBox at a time.

    Use an indirect method: try to declare a global boolean variable like "FocusLost" and asign it the value "true" in Text1.LostFocus event, and then on Command1.Click event put this code (or something similar):

    -----
    If FocusLost = True Then MsgBox "Lost Focus and Click"
    Else MsgBox "Click Only"
    LostFocus = False 'to reset the variable
    End IF
    -----

    Got the picture? Good Luck!

  3. #3

    Thread Starter
    Addicted Member
    Join Date
    Jan 2000
    Location
    Sydney, Australia
    Posts
    196

    Post

    Yep - I understand what you mean - and that would work. However the code i have attached to both of these events is very large and its not very good to duplicate it <i think t would cause me more problems>. What i would realy like is if i could make the click event happen.

    What i have noticed is that the command1.click event procedure never even gets called. If you put a break point on the procedure and then try it, it never gets called.

    Crazy stuff - somehow the click event is getting lost.

    Still Scratching...

  4. #4
    New Member
    Join Date
    Feb 2000
    Posts
    12

    Post

    That’s not peculiar, that’s a the designed in functionality of a MsgBox, it’s a modal form. This means when a MsgBox appears it must be dismissed by the user before anything else can happen (notice that you can’t move the form or change focus or even end the program until you have clicked OK. The idea is that some important information is being delivered to the user and he must acknowledge it before anything else can happen. If it wasn’t so, then the msgbox could get covered over with other forms and the message would not get through in time.

    Use another reporting method if you need this functionality like a label or a textbox.


  5. #5

    Thread Starter
    Addicted Member
    Join Date
    Jan 2000
    Location
    Sydney, Australia
    Posts
    196

    Post

    Yes - i understand all that about msgboxes being modal, and i agree, but why doesnt the click event (of command1 on form1) happen after you dismiss the msgbox?

    For example, if you take out the msgbox code on the lostfocus event and replace it by any other processing, the click event code will execute, but if the msgbox is in there the click event code will not execute.

    Thats really my query atm.

  6. #6

    Thread Starter
    Addicted Member
    Join Date
    Jan 2000
    Location
    Sydney, Australia
    Posts
    196

    Post

    Oh, by the way - in my original message when I said:

    "What i want <and would expect to see> is "lost focus" and then "click"."

    I meant after the first msgbox is dismissed - not one on top of the other.

    Thnaks

  7. #7
    New Member
    Join Date
    Feb 2000
    Posts
    2

    Post

    Hi,
    The display of the first Magbox is causing your problem.

    Try this :-

    Add a label, and set it to visible=false
    Then change your code to -

    Private Sub Command1_Click()
    MsgBox "click"
    Label1.Visible = False
    Label1.Refresh
    End Sub

    Private Sub Text1_LostFocus()
    ''''MsgBox "lost focus"
    Label1.Caption = "lost focus"
    Label1.Visible = True
    Label1.Refresh
    End Sub

    Rob Crombie

    *********************************************
    Originally posted by funkyd77:
    Hello, i have some code that i am working on. I've simplified it greatly below to simulate my problem. If you open up a new project <standard Exe>, place a button and a text box on the form and put the following code in the form code.


    Private Sub Command1_Click()
    MsgBox "click"
    End Sub

    Private Sub Text1_LostFocus()
    MsgBox "lost focus"
    End Sub


    Then if you place the cursor in the text box and click on the button you see "lost focus" and then nothing. What i want <and would expect to see> is "lost focus" and then "click".

    Can anyone help me as to why the "click" event is being lost in this situation? Does the raising of the lostfocus event mean that no other events are triggered?

    I really need to find out why this is happening and what i can do about it so if anyone can help, it would be very appreciated.

    Thanks,

    Mark

  8. #8
    New Member
    Join Date
    Feb 2000
    Posts
    12

    Post

    The click is fired off into cyber space ;-) My best thought on that is the model form (the MsgBox) gets the event (not the button on the form but the form itself) Since the MsgBox form doesn’t act on the click, then it’s gone. The next click in the process is on the OK button of the MsgBox and then there are no clicks left.

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