Results 1 to 4 of 4

Thread: Pausing the code while waiting for an input

  1. #1

    Thread Starter
    Junior Member deiva's Avatar
    Join Date
    Mar 2000
    Location
    Penang, Malaysia
    Posts
    29
    I desperately need some help with this problem I have.

    The scenario is:-
    - there are 2 forms - frmOne and frmTwo
    - frmOne is the main form & frmOne calls frmTwo when needed
    - frmTwo requires the user to input a string

    Now, when a button is clicked in frmOne, some code is executed and frmTwo is called. However, there is more code in Button_Click (of frmOne) after frmTwo is loaded. I need to somehow pause this code after frmTwo is loaded. I want the user to input the string in frmTwo and when frmTwo is unloaded, I want the remaining code in Button_Click (in frmOne) to continue executing. Below is what I mean.

    'In frmOne
    Private Sub Button_Click()
    Code
    Code
    Code

    frmTwo.Show ' Load and display frmTwo while
    frmOne.Hide ' frmOne is temporarily hidden

    Code } I would like to stop this
    Code } code from being executed until
    Code } frmTwo is unloaded and frmOne gets control.
    End Sub


    'In frmTwo
    Private Sub Ok_Click()
    frmOne.Tag = txtName.Value
    frmOne.Show
    Unload frmTwo
    End Sub

    Is there anyway I can pause the remaining code and stop it from executing until frmTwo gets the string from the user and returns the control to frmOne.

    Please help.

    For background info, the situation is such that I could use InputBox() but I do not want the Cancel button to be there. So, I have made a simple form with a textbox and an Ok button. This is frmTwo.

  2. #2
    Frenzied Member Buzby's Avatar
    Join Date
    Jan 1999
    Location
    UK
    Posts
    1,670
    Do this..


    ..form one code...

    FormOne.Hide
    FormTwo.Show 1
    FormOne.Show

    ..continue formone code ...


    By putting a 1 after the Show for FormTwo it forces the form to be displayed modally (ie, no other forms can do anything whilst this form is on screen). Therefore the code beyond it will not run until the formTwo is closed.

    'Buzby'
    Visual Basic Developer
    "I'm moving to Theory. Everything works there."

  3. #3
    Lively Member Ishamel's Avatar
    Join Date
    Nov 1999
    Location
    Edinburgh, Scotland
    Posts
    112
    Try openning Form2 as Modal.

    Code:
    Form2.Show vbModal
    When the Show displays a modeless form, subsequent code is executed as it's encountered.

    When Show displays a modal form, no subsequent code is executed until the form is hidden or unloaded.

    Hope this helps.

    [Edited by Ishamel on 03-21-2000 at 08:51 AM]

  4. #4

    Thread Starter
    Junior Member deiva's Avatar
    Join Date
    Mar 2000
    Location
    Penang, Malaysia
    Posts
    29

    Thank you

    Just wanted to thank both of you. I am making a game at them moment. I have only seen it on the Psion Revo. I am sure it is available for the PC somewhere, but I thought it would be more of a challenge if I tried to do it myself.

    If you want a copy do let me know. It should be completed within the next two days. My e-mail address is [email protected]. Please do not have extremely high expectations of the game. I am just a novice programmer. You could even give me tips on how to improve.

    Once again, thank you.

    Best wishes,
    Deiva

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