winformsvb6dialogresult

In VB6 is there something similar to DialogResult from a dialog?


I have a VB6 form with buttons with the text 'Continue' and 'Cancel'. I want to check which one was clicked. In C# every form has a dialog result and I could set it before exiting the form depending on which button was clicked. I don't see this in VB6.

Is there a dialog result? If not what is the best practice for checking the dialog result?


Solution

  • To simulate the .net WinForms behaviour, you will need a helper function in your form's code:

    Public Function ShowDialog() As VbMsgBoxResult
      Me.Show vbModal
      ShowDialog = Iif(Cancelled, vbCancel, vbOk)
      Unload Me
    End Function
    

    The form level Cancelled variable can be set by the button event functions before calling .Hide() or .Close(), or you could have a variable containing the result code directly.