Dim response As String
response = MessageBox.Show("Are you sure you want to exit?", "Warning", MessageBoxButtons.YesNo, MessageBoxIcon.Exclamation)

If response = 6 Then
End
ElseIf response = 7 Then
Me.Close()
End If

Above is the code to exit a form. When i exit my form a message box appears telling me if i want to exit. I can either chose Yes or No. What i can't understand from the above code what does the number 6 and seven represent actually.

Hi

Number 6 and 7 are returned values from a message box to show the response of the user, so that it can be compared and action can be taken appropriately. So if NO is slected the returned value is 7 and YES is 6 and so on. this enables you to check if the user clicked no or yes so that you can take action accordingly. For more returned values please refer to following msdn site and go to return value section

http://msdn.microsoft.com/en-us/library/139z2azd(VS.80).aspx

HTH

Regards
Sarah

dats really useful...thanks...

Dim response As String
response = MessageBox.Show("Are you sure you want to exit?", "Warning", MessageBoxButtons.YesNo, MessageBoxIcon.Exclamation)

If response = 6 Then
End
ElseIf response = 7 Then
Me.Close()
End If

To understand quickly here's a similar code for your future reference:

Dim msgAnswer as MsgBoxResult


msgAnswer = MsgBox ("Are your sure you want to Exit?",MsgBoxStye.YesNo,"Warning")

If msgAnswer = MsgBoxResult.Yes Then
End
Elseif msgAnswer = MsgBoxResult.No Then
Me.Close
End If

Dim msgAnswer as MsgBoxResult

msgAnswer = MsgBox ("Are your sure you want to Exit?",MsgBoxStye.YesNo,"Warning")

If msgAnswer = MsgBoxResult.Yes Then
End
Elseif msgAnswer = MsgBoxResult.No Then
Me.Close
End If

Here's the same code a bit more in VB.NET style than VB6 style

Dim msgAnswer As Windows.Forms.DialogResult

msgAnswer = MessageBox.Show("Are your sure you want to Exit?", "Warning", MessageBoxButtons.YesNoCancel, MessageBoxIcon.Question)

If msgAnswer = Windows.Forms.DialogResult.Yes Then
  End
ElseIf msgAnswer = Windows.Forms.DialogResult.No Then
  Me.Close()
End If
Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.