Debug Mode In VB 6?

前端 未结 4 1006
南方客
南方客 2021-02-18 13:33

How can I do something similar to the following C code in VB 6?

#ifdef _DEBUG_
    // do things
#else
    // do other things
#end if
4条回答
  •  情深已故
    2021-02-18 13:57

    Cody has told you about conditional compilation. I'd like to add that if you want different behaviour when debugging on the IDE (e.g. turn off your own error handling so that the IDE traps errors) you don't need conditional compilation. You can detect the IDE at runtime like this.

    On Error Resume Next 
    Debug.Print 1/0 
    If Err=0 then 
      'Compiled Binary 
    Else 
      'in the IDE 
    End if
    

    This works because Debug.Print is omitted in the compiled EXE.

    • EDIT Remember to turn off On Error Resume Next !
    • EDIT You can wrap the check in a function like this (thanks CraigJ)

提交回复
热议问题