我收到此错误消息:expression是一个值,因此不能作为赋值的目标
对于此代码
MsgBox("Do you really wish to delete " & txtLayerDelete.Text & "?", MsgBoxStyle.YesNo) = MsgBoxResult.Yes
txtLayerDelete位于UserControl上。
答案 0 :(得分:1)
以这种方式试试。请注意,MsgBox和MessageBox返回的结果是枚举值。 MsgBox被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
答案 1 :(得分:0)
您尝试分配MsgBox
并且未使用该方法的返回值。
MsgBox("Do you really wish to delete " & txtLayerDelete.Text & "?", MsgBoxStyle.YesNo)
将向您的用户显示消息框,此方法返回您应该使用的MsgBoxResult
对象,如下所示。
Dim delete = MsgBox("Do you really wish to delete " & txtLayerDelete.Text & "?", MsgBoxStyle.YesNo)
If delete = MsgBoxResult.Yes Then
'Your logic
End If
替代方法您只需添加一个If语句并执行:
If MsgBox("Do you really wish to delete?", MsgBoxStyle.YesNo) = MsgBoxResult.Yes Then
End If
作为附加说明,MsgBox功能似乎已过时,您应该尝试使用MessageBox.Show
。
Dim delete = MessageBox.Show("Should this item be deleted", "Form Title", MessageBoxButtons.YesNo)
If delete = DialogResult.Yes Then
End If
答案 2 :(得分:0)
你没有使用方法返回值,我的朋友。
应该是:
`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
您的欢迎:)
答案 3 :(得分:0)
好的,既然每个人都向您展示了如何使用IF Statement
完成任务,我会告诉您我该怎么做。
就我个人而言,我更喜欢使用CASE statement
认为它看起来更清洁。
Select Case MsgBox("Do you really want to delete " & txtLayerDelete.Text & "?", MsgBoxStyle.YesNo)
Case MsgBoxResult.Yes
''DELETES
Case MsgBoxResult.No
''NOTHING
End Select
如果您对我提供的代码有疑问,请告诉我们:)