Private Sub Text1_LostFocus() s = Text1.Text s1 = Split(s, "-") If UBound(s1) <> 1 Then MsgBox "输入格式不对!": Exit Sub If IsNumeric(s1(0)) = False Or IsNumeric(s1(1)) = False Or Val(s1(0)) < 1 Or Val(s1(1)) < 1 Then MsgBox "输入格式不对!": Exit Sub If InStr(s1(0), ".") <> 0 Or InStr(s1(1), ".") <> 0 Then MsgBox "输入格式不对!": Exit Sub End Sub
放两个文本框,点第二个文本框,让第一个失去焦点
Private Function ISlegal(vText As String) As Boolean On Error Resume Next Dim boolYN As Boolean If InStr(1, vText, "-") = 0 Then boolYN = False Else If (IsNumeric(Left(vText, InStr(1, vText, "-") - 1)) = False Or _ Val(Left(vText, InStr(1, vText, "-") - 1)) <= 0) _ Or (IsNumeric(Mid(vText, InStr(1, vText, "-") + 1)) = False Or _ Val(Left(vText, InStr(1, vText, "-") - 1)) <= 0) Then boolYN = False Else boolYN = True End If End If ISlegal = boolYN End Function…… If ISlegal(Trim(Text1.Text)) = False Then MsgBox "输入不合法" Exit Sub End If
private function Check_String_Style(byval strTemp as string ) as boolean dim strArr() as string dim i as longstrArr = split(strTemp,"-") if len(strArr(0)) = 0 then '不满足 else if isnumeric(strArr(0) then else '不满足 end if end if if len(strArr(1)) = 0 then '不满足 else if isnumeric(strArr(1) then else '不满足 end if end if end function
s = Text1.Text
s1 = Split(s, "-")
If UBound(s1) <> 1 Then MsgBox "输入格式不对!": Exit Sub
If IsNumeric(s1(0)) = False Or IsNumeric(s1(1)) = False Or Val(s1(0)) < 1 Or Val(s1(1)) < 1 Then MsgBox "输入格式不对!": Exit Sub
If InStr(s1(0), ".") <> 0 Or InStr(s1(1), ".") <> 0 Then MsgBox "输入格式不对!": Exit Sub
End Sub
放两个文本框,点第二个文本框,让第一个失去焦点
Private Function ISlegal(vText As String) As Boolean
On Error Resume Next
Dim boolYN As Boolean
If InStr(1, vText, "-") = 0 Then
boolYN = False
Else
If (IsNumeric(Left(vText, InStr(1, vText, "-") - 1)) = False Or _
Val(Left(vText, InStr(1, vText, "-") - 1)) <= 0) _
Or (IsNumeric(Mid(vText, InStr(1, vText, "-") + 1)) = False Or _
Val(Left(vText, InStr(1, vText, "-") - 1)) <= 0) Then boolYN = False
Else
boolYN = True
End If
End If
ISlegal = boolYN
End Function……
If ISlegal(Trim(Text1.Text)) = False Then
MsgBox "输入不合法"
Exit Sub
End If
IsNumeric(Left(vText, InStr(1, vText, "-") - 1)) = False Or (instr(1, vText,".")>0)
private function Check_String_Style(byval strTemp as string ) as boolean
dim strArr() as string
dim i as longstrArr = split(strTemp,"-")
if len(strArr(0)) = 0 then
'不满足
else
if isnumeric(strArr(0) then
else
'不满足
end if
end if
if len(strArr(1)) = 0 then
'不满足
else
if isnumeric(strArr(1) then
else
'不满足
end if
end if
end function