CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 4 of 4
  1. #1
    Join Date
    Aug 2004
    Location
    Iowa
    Posts
    64

    How to know which button pressed when a form closes

    Forgive me I am sure this is really easy, but I do not know VB at all, and I got stuck with a program.

    I am showing a form by calling this...

    Form1.Show 1

    This opens another "window" which collects data from the user, then the user can either hit the OK or CANCEL button. How does the calling function know what button the user pressed?

    I assume that you could do something like this...
    ButtonPressed = Form1.Show 1

    but you can not.

    Can any one help me answer this easy question?


    Thanks a lot, I appricate it.
    --------------------------------------------
    Whats in Iowa.... Corn and Code...

  2. #2
    Join Date
    Nov 2002
    Posts
    278

    Re: How to know which button pressed when a form closes

    Form1.ActiveControl.Name

  3. #3
    Join Date
    Feb 2007
    Location
    Finland
    Posts
    10

    Re: How to know which button pressed when a form closes

    Well it should be easy my friend, but I neither understood the question nor the reply post

  4. #4
    Join Date
    Aug 2006
    Posts
    145

    Re: How to know which button pressed when a form closes

    you need to wrap the opening and closing of the form in a Public function within it.

    e.g. in Form1, I have:
    Code:
    Private lRet As Long
    
    Public Function ShowForm() As Long
        Me.Show vbModal
        ShowForm = lRet
        Unload Me
    End Function
    
    Private Sub Command1_Click()
        lRet = 1
        Me.Hide
    End Sub
    
    Private Sub Command2_Click()
        lRet = 2
        Me.Hide
    End Sub
    in the calling form I have:
    Code:
    Private Sub Command1_Click()
        Debug.Print Form2.ShowForm
    End Sub

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

Featured