Reputation:
I get this error message: expression is a value and therefore cannot be the target of an assignment
For this code
MsgBox("Do you really wish to delete " & txtLayerDelete.Text & "?", MsgBoxStyle.YesNo) = MsgBoxResult.Yes
txtLayerDelete is on a UserControl.
Upvotes: 2
Views: 111
Reputation: 996
Ok, since everyone has shown you how to complete your task with an IF Statement
, I will show you how I would do it.
Personally I prefer to use the CASE statement
as I think it looks a lot more cleaner.
Select Case MsgBox("Do you really want to delete " & txtLayerDelete.Text & "?", MsgBoxStyle.YesNo)
Case MsgBoxResult.Yes
''DELETES
Case MsgBoxResult.No
''NOTHING
End Select
If you have an issues with the code I have provided you with, let me know :)
Upvotes: 0
Reputation: 149
You aren't using the methods return value, my friend.
It should be:
`Dim dialogDel = MsgBox("Do you really wish to delete " & txtLayerDelete.Text & "?", MsgBoxStyle.YesNo)`
If dialogDel = DialogResult.Yes Then
'Yes code.
Else
'No code
End If
Your welcome :)
Upvotes: 0
Reputation: 70728
You have tried to assign the MsgBox
and are not using the method's return value.
MsgBox("Do you really wish to delete " & txtLayerDelete.Text & "?", MsgBoxStyle.YesNo)
Would be displaying the message box to your user, this method returns a MsgBoxResult
object which you should use, as shown below.
Dim delete = MsgBox("Do you really wish to delete " & txtLayerDelete.Text & "?", MsgBoxStyle.YesNo)
If delete = MsgBoxResult.Yes Then
'Your logic
End If
Alternative you can just add an If statement and do:
If MsgBox("Do you really wish to delete?", MsgBoxStyle.YesNo) = MsgBoxResult.Yes Then
End If
As an additional note the MsgBox function appears to be outdated, you should try and use MessageBox.Show
.
Dim delete = MessageBox.Show("Should this item be deleted", "Form Title", MessageBoxButtons.YesNo)
If delete = DialogResult.Yes Then
End If
Upvotes: 0
Reputation: 11773
Try it this way. Note that MsgBox and MessageBox return a result that is an enumerated value. MsgBox was replaced with MessageBox
Dim result As DialogResult = MessageBox.Show("Do you really wish to delete " & txtLayerDelete.Text & "?", , MessageBoxButtons.YesNo)
If result = Windows.Forms.DialogResult.Yes Then
End If
Upvotes: 1