MsgBox always return "no" regardless of what the user click
I am using VS2005 and have a messagebox inside of an event that does not work properly. The code is below:
If Microsoft.VisualBasic.MsgBox("Do you want to save your changes", MsgBoxStyle.YesNo) = MsgBoxResult.NoThen
ExitSubEndIfThe problem is regardless of whether the user clicks Yes or No, it always returns No. If I add another MsgBox in the code immediately before the if statement, then the if statement will always work properly. (see code below)
Microsoft.VisualBasic.MsgBox("Dummy MsgBox")
If Microsoft.VisualBasic.MsgBox("Do you want to save your changes", MsgBoxStyle.YesNo) = MsgBoxResult.NoThen
ExitSubEndIfI can't figure out what is wrong here, or why its doing this. I use the same code in other event routines and it works fine. Can anyone help me figure out what is going on here? Any pointers on where to look or how to trap the problem inside the system? I'm at a complete loss to explain it, and its frustrating me to no end.
Thanks,
Susan
[1948 byte] By [
Susan2] at [2007-12-23]
The following seems to work just fine.....
Can you provide some more code around how your using this, console, windows application and does this occur in all projects you create or just this one.
You know that you can leave off the Bold item as msgbox is part of the core language.
Public Class Form1
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
If Microsoft.VisualBasic.MsgBox("Do you want to save your changes", MsgBoxStyle.YesNo) = MsgBoxResult.No Then
Me.Button1.Text = "No"
Else
Me.Button1.Text = "Yes"
End If
End Sub
End Class
Is there anything about this machine we should know - did it have a beta of visual studio installed, or a previous version of visual studio 2003
I have no idea why it doesn't work for you, but maybe you can try to use the MessageBox class of the System.Windows.Forms namespace instead of using the Microsoft.VisualBasic namespace
If
System.Windows.Forms.MessageBox.Show("test", "test", System.Windows.Forms.MessageBoxButtons.YesNo) = System.Windows.Forms.DialogResult.No ThenExit SubEnd IfThank you for your response. I have a windows application. The issue does not occur in other projects, and as a matter of fact, I use the exact same code other places in my application and it works fine. Its just in this one event handler. Enclosed is the complete code:
Private Sub RepositoryItemLookUpEdit1_EditValueChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles RepositoryItemLookUpEdit1.EditValueChanged'' Declare local variables'Dim objPart As PartsDim objPartRev As PartRevsDim objTemplate As TemplatesDim cm As CurrencyManagerDim response As MsgBoxResultDim intResponse As Integer'' Get the current PartRev we are working with'objPart = GetCurrentPart()
If objPart Is Nothing Then Exit Sub 'No Part objectobjPartRev = objPart.PartRevs(0)
If objPartRev Is Nothing Then Exit Sub 'No PartRev'' Get the currency manager for the objParts collection now so we can refresh it later'cm = PartsNavigator.BindingContext(PartsNavigator.DataSource)
'' If there is already a Process prompt to overwrite it first'If Not objPartRev.ProcessItems Is Nothing ThenIf objPartRev.ProcessItems.Count > 0 Then'Microsoft.VisualBasic.MsgBox("You are about to overwrite the existing process.", MsgBoxStyle.Information, "ShopTrack")response = Microsoft.VisualBasic.MsgBox(
"Are you sure you want to overwrite the existing process?", MsgBoxStyle.YesNo, "ShopTrack")If response = MsgBoxResult.No ThenExit SubEnd IfEnd IfEnd If'' Get the ProcessTemplate Selected'objTemplate = RepositoryItemLookUpEdit1.GetDataSourceRowByKeyValue(
CType(sender, DevExpress.XtraEditors.BaseEdit).EditValue)'' Call the shared method to remove the old process and add the new process from the template (objPartRev passed by reference)'ObjectBase.CopyToProcess(objTemplate, objPartRev)
'' Mark the part as changed now'Part_Changed()
'' Refresh the CurrencyManager now'cm.Refresh()
'' Done'End Sub
I am using DevExpress controls, but again this does not happen with other event handlers, even of the same class. DexExpress support has no idea either.
Any help would be greatly appreciated!
Thanks,
Susan
Sven,
Thanks for the suggestion. I tried it but it made no difference. The wierd thing is the same code works elsewhere in my code, just not in this event handler. I am using DevExpress controls, and I contacted them about it and they are stumped as well (and can't reproduce it).
It's still a problem for me if you have any other suggestions, I would like to hear them.
Thanks,
Susan
I'll just give something in here!
If you want to you can use something like the following, which i have used in all my applications:
If MsgBox("Question Here", [yesno option], "title") = # then
else
end if
The following values are what you would use for the # (number
):
Yes = 6
No = 7
Cancel = 2 (when using yesnocancel option)
If you want to do it a bit differently set the answer to a string and test the string!
Try using an intermetiate variable - it'll probably point to the error: you will be able to see what the return value actually is. Also you dont by any chance happen to have mcafee antivrius software on this machine.
This has been creating numerous problems with messagebox functionality.
I substituted the following code:
If MsgBox("Are you sure you want to overwrite the existing process?", MsgBoxStyle.YesNo, "ShopTrack") = 7 Then
Exit SubEnd IfI msgbox call always returns 7 (No) regardless of whether I click Yes or No. It's really weird (and frustrating) problem that only happens in this event handler.
Any other suggestions would be greatly appreciated!
Thanks,
Susan
I am using McAfee Internet Security Suite 8. I disabled all services and re-ran my tests with the same result. The really wierd part is that this code works elsewhere in my code, it's just in this event handler.
Thanks,
Susan
I implemented the following code to capture the return value from my messagebox:
intResponse = MsgBox(
"Are you sure you want to overwrite the existing process?", MsgBoxStyle.YesNo, "ShopTrack")
MsgBox("The previous messagebox returned the following code: " & intResponse)
Regardless of whether I click Yes or No, the return value is always 7 (no).
I can't figure this out.
Thanks,
Susan
hei, i'm just learning vb.net atm, & came across your post as i have the same problem.
> Dim MsnLoadup As Boolean = False> MsgBox("content of var MsnLoadup is : " & MsgBox("Do you want to start up MSN", MsgBoxStyle.YesNo))
This would always return "6" for YES click, & "7" for NO click. Which is abit confusing, as i read in a vb text book that, for Boolean types, "0" represents False, and "-1" (or any other non negative number) represents True.
That is the correct behavior. The resturn value of an MessageBox (or any other Dialog for that matter) is not a boolean value, but a System.Windows.Forms.DialogResult Enum member (http://msdn2.microsoft.com/en-us/library/system.windows.forms.dialogresult.aspx).
A messagebox can return other values than yes/no (Abort, Retry, Cancel, Ignore, OK)
So you should always compare the value with the enum value
Susan,
Just out of curiosity. Did that MCAfee patch that spotty suggested fix this issue? We use MCAfee here too.