迷惑的vb.net问题肯请老师给予解释
PrintDialog1.ShowDialog() = Windows.Forms.DialogResult.Cancel
这样写就提示:“表达式是一个值,因此不能作为赋值目标”
写成:
if PrintDialog1.ShowDialog() = Windows.Forms.DialogResult.Cancel then
endif
这样就没有问题,不会出现上面的提示。
请问这是为什么,我的基础很烂,虽不影响编程,但是迫切想问明是这怎么回事。if then的写法怎么就把语言的错误消除了~~~
[最优解释]
Dim bEqual As Boolean = (PrintDialog1.ShowDialog() = Windows.Forms.DialogResult.Cancel)
If bEqual Then
...
End If
这样也可以。
在VB中,赋值和判断运算符都是等于号,这里不是赋值,而是判断。如果等号左右相等,这个表达式返回True,否则是False
[其他解释]
if (PrintDialog1.ShowDialog() = Windows.Forms.DialogResult.Cancel )
[其他解释]
PrintDialog1.ShowDialog() = Windows.Forms.DialogResult.Cancel
这是赋值