如题,当我点击下一个cell准备输入数字时,怎么判断刚才输入的哪个是否在范围内。
Private Sub MSFlexGrid1_LeaveCell()
Dim ts As Single
ts = Val(MSFlexGrid1.TextMatrix(MSFlexGrid1.Row, MSFlexGrid1.Col))
If MSFlexGrid1.Row = 2 Then
If ts <= 0 Or ts > 3600 Then
MsgBox "范围:0 - 3600 秒", vbExclamation, "注意"
End If
Else
If MSFlexGrid1.Row = 3 Then
If ts < 190 Or ts > 700 Then
MsgBox "范围:190 - 700nm", vbExclamation, "注意"
End If
End If
End If
End Sub
我这样写 但是不行。
Private Sub MSFlexGrid1_LeaveCell()
Dim ts As Single
ts = Val(MSFlexGrid1.TextMatrix(MSFlexGrid1.Row, MSFlexGrid1.Col))
If MSFlexGrid1.Row = 2 Then
If ts <= 0 Or ts > 3600 Then
MsgBox "范围:0 - 3600 秒", vbExclamation, "注意"
End If
Else
If MSFlexGrid1.Row = 3 Then
If ts < 190 Or ts > 700 Then
MsgBox "范围:190 - 700nm", vbExclamation, "注意"
End If
End If
End If
End Sub
我这样写 但是不行。
exit sub
(如果不用enter确认,在文本框的lostfocus事件中判断吧,不过不推荐)
Private Sub MSFlexGrid1_Click()
With MSFlexGrid1
Text1.Visible = True
Text1.Move .ColPos(.Col), .RowPos(.Row), .ColWidth(.Col), .RowHeight(.Row)
Text1.BackColor = &HC0FFC0
Text1.Text = ""
If .TextMatrix(.Row, .Col) = "" Then
Text1.Text = ""
Else
Text1.Text = .TextMatrix(.Row, .Col)
End If
Text1.SelLength = Len(Text1.Text)
Text1.SetFocus
End With
End SubPrivate Sub Text1_KeyPress(KeyAscii As Integer)
If KeyAscii <> 13 Then Exit Sub
If Text1.BackColor = &HC0FFC0 Then
Text1.Visible = False
MSFlexGrid1.SetFocus
'数据是否合法,这里判断
'……略
MSFlexGrid1.Text = Text1.Text
End If
End Sub