在VB和VB.NET程序中判断当前是否运行于开发环境中
'方法一:
Private Function IsIDE() As Boolean
Static bInIDE Boolean
bInIDE = Not bInIDE
If bInIDE Then
Debug.Assert IsIDE() Or True
IsIDE = End If
Function
Sub Form_Load()
MsgBox IsIDE
Sub
方法二: 有时我们需要判断正在运行的程序是处于开发环境下(调试模式),还是正常运行状态(已编译后).以前看到个VB6的判断方式: Public Function IsDebugMode() As Boolean IsDebugMode = False On Error Resume Next Debug.Print 1 / 0 If Err.Number <> 0 Then IsDebugMode = True End If End Function
Dim o As Object = Nothing Try Debug.Print(o.Name) Return False Catch ex As Exception Return True End Try 在这段代码中,定义了一个对象变量,并赋值为空,因此,o.Name会产生一个System.NullReferenceException的异常 (编辑:李大同) 【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容! |