当前位置:编程学习 > VB >>

关于赋值异常的检测

如果把字符串付给int型,会产生错误,而导致程序崩溃,我们在程序中如何检测,并提醒使用者,不然程序崩溃呢? --------------------编程问答--------------------

Option Explicit

Private Sub Command1_Click()
    Dim intP As Integer
    Dim bolP As Boolean
    bolP = IsNumeric(Text1.Text)
    If bolP Then
        intP = CInt(Text1.Text)
    Else
        MsgBox "Text1ÖеÄÄÚÈݲ»ÊÇÊý×Ö"
    End If
End Sub

--------------------编程问答--------------------
'检查是否为数值型:
if not isnumeric(aa) then
    msgbox "非数值型!",48,"提示"
end if
'检查是否为日期型:
if not isdate(aa) then
    msgbox "非日期型!",48,"提示"
end if
--------------------编程问答-------------------- 哦,谢谢了,没想到还有这函数。
--------------------编程问答--------------------
引用 3 楼 braveforyou 的回复:
哦,谢谢了,没想到还有这函数。
........................... --------------------编程问答-------------------- 顶 
引用 2 楼 leftie 的回复:
VB code
'检查是否为数值型:
if not isnumeric(aa) then
    msgbox "非数值型!",48,"提示"
end if
'检查是否为日期型:
if not isdate(aa) then
    msgbox "非日期型!",48,"提示"
end if
补充:VB ,  VBA
CopyRight © 2012 站长网 编程知识问答 www.zzzyk.com All Rights Reserved
部份技术文章来自网络,