If col = 2 Or col = 5 Or col = 6 Or col = 7 Then Cancel = True 这句代码用清晰思路 怎么实现?
Select Case col Case 1, 2, 3, 4, 5 MsgBox "1,2,3,4,5" Case 6, 7, 8, 9, 0 MsgBox "6,7,8,9,0" Case Else MsgBox "OTHER" End Select
If col = 2 Or col = 5 Or col = 6 Or col = 7 Then Cancel = True 这句多清晰呀!col等于2,5,6,7中任意一个时,Cancel=True
If col = 2 Or (col >= 5 and col <= 7) Then Cancel = True
If col = 2 Or Abs(col - 6) <= 1 Then Cancel = True
如果功能是这样的话。 ''''''''''''''''''''''''''''''''''''''''''''''''' If col = 2 Or col = 5 Or col = 6 Or col = 7 Then Cancel = True Else Cancel = False End If ''''''''''''''''''''''''''''''''''''''''''''''''' 也可这样写。 ''''''''''''''''''''''''''''''''''''''''''''''''' Cancel = (col = 2 Or col = 5 Or col = 6 Or col = 7) '''''''''''''''''''''''''''''''''''''''''''''''''不过这种方式没有“If col = 2 Or col = 5 Or col = 6 Or col = 7 Then Cancel = True”方式好。。
if col in(2,5,6,7) then cancel=true
'全局或静态数组 dim value(10) as bool value(2) = true value(5) = true value(6) = true value(7) = true然后判断如下写法 cancel = value(col)
最短的来了: Cancel = (col = 2) Or (col = 5) Or (col = 6) Or (col = 7) 不止最短,还是最快的. 逻辑表达式赋值根本就不需要用IF来判断.
Cancel = (col = 2) Or (col = 5) Or (col = 6) Or (col = 7) -------------- 这种写法最好了,就是可读性差些。
如果col不超过10那么: If instr("2567",col) Then Cancel = True
Quot: WallesCai(沧海明月一度,西风残阳无悔.) ( ) 信誉:107 Blog 2006-12-10 0:03:14 得分: 0
最短的来了: Cancel = (col = 2) Or (col = 5) Or (col = 6) Or (col = 7) 不止最短,还是最快的. 逻辑表达式赋值根本就不需要用IF来判断. 楼主只是说 If col = 2 Or col = 5 Or col = 6 Or col = 7 Then Cancel = True 并没有else Cancel = False
怎么实现?
Case 1, 2, 3, 4, 5
MsgBox "1,2,3,4,5"
Case 6, 7, 8, 9, 0
MsgBox "6,7,8,9,0"
Case Else
MsgBox "OTHER"
End Select
这句多清晰呀!col等于2,5,6,7中任意一个时,Cancel=True
'''''''''''''''''''''''''''''''''''''''''''''''''
If col = 2 Or col = 5 Or col = 6 Or col = 7 Then
Cancel = True
Else
Cancel = False
End If
'''''''''''''''''''''''''''''''''''''''''''''''''
也可这样写。
'''''''''''''''''''''''''''''''''''''''''''''''''
Cancel = (col = 2 Or col = 5 Or col = 6 Or col = 7)
'''''''''''''''''''''''''''''''''''''''''''''''''不过这种方式没有“If col = 2 Or col = 5 Or col = 6 Or col = 7 Then Cancel = True”方式好。。
dim value(10) as bool
value(2) = true
value(5) = true
value(6) = true
value(7) = true然后判断如下写法
cancel = value(col)
Cancel = (col = 2) Or (col = 5) Or (col = 6) Or (col = 7)
不止最短,还是最快的.
逻辑表达式赋值根本就不需要用IF来判断.
--------------
这种写法最好了,就是可读性差些。
如果col不超过10那么:
If instr("2567",col) Then Cancel = True
要改变思路
要是调换一下思路
只用
8〉col〉3
就可以了,还有更简单的
用 位 AND 比较
要从结构上优化才好
WallesCai(沧海明月一度,西风残阳无悔.) ( ) 信誉:107 Blog 2006-12-10 0:03:14 得分: 0
最短的来了:
Cancel = (col = 2) Or (col = 5) Or (col = 6) Or (col = 7)
不止最短,还是最快的.
逻辑表达式赋值根本就不需要用IF来判断.
楼主只是说
If col = 2 Or col = 5 Or col = 6 Or col = 7 Then Cancel = True
并没有else Cancel = False