【发布时间】:2016-07-17 22:49:58
【问题描述】:
我收到此错误消息:表达式是一个值,因此不能成为赋值的目标
对于这个代码
MsgBox("Do you really wish to delete " & txtLayerDelete.Text & "?", MsgBoxStyle.YesNo) = MsgBoxResult.Yes
txtLayerDelete 位于用户控件上。
【问题讨论】:
标签: .net vb.net messagebox
我收到此错误消息:表达式是一个值,因此不能成为赋值的目标
对于这个代码
MsgBox("Do you really wish to delete " & txtLayerDelete.Text & "?", MsgBoxStyle.YesNo) = MsgBoxResult.Yes
txtLayerDelete 位于用户控件上。
【问题讨论】:
标签: .net vb.net messagebox
试试这个方法。请注意,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
【讨论】:
您已尝试分配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
【讨论】:
你没有使用方法返回值,我的朋友。
应该是:
`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
欢迎您:)
【讨论】:
好的,既然每个人都向您展示了如何使用 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
如果您对我提供给您的代码有疑问,请告诉我 :)
【讨论】: