5

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?

Mike Webb
  • 8,855
  • 18
  • 78
  • 111

2 Answers2

6

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.

Deanna
  • 23,876
  • 7
  • 71
  • 156
0

In VB6 a dialog generally returns an integer value, which may correspond to vbYes, vbNo, vbCancel, etc. See this article for details: http://www.vb6.us/tutorials/understanding-msgbox-command-visual-basic

http://www.code-vb.com/fragments/Dialogs.htm#Msgbox OK-Cancel

You'll have to specify it on your form if you've created the form yourself.

The last answer in this post has a hint that may help: http://www.xtremevbtalk.com/archive/index.php/t-306663.html

David
  • 72,686
  • 18
  • 132
  • 173