VB 6 中的调试模式? [英] Debug Mode In VB 6?

查看:19
本文介绍了VB 6 中的调试模式?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如何在 VB 6 中执行类似于以下 C 代码的操作?

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

#ifdef _DEBUG_
    // do things
#else
    // do other things
#end if

推荐答案

它与您习惯的其他语言几乎相同.语法如下所示:

It's pretty much the same as the other languages that you're used to. The syntax looks like this:

#If DEBUG = 1 Then
    ' Do something
#Else
    ' Do something else
#End If

只要记住语法与 VB 6 中的其他流程控制语句完全相同,就很容易记住,只是编译时条件语句以井号 (#).

It's easy to remember if you just remember that the syntax is exactly the same as the other flow-control statements in VB 6, except that the compile-time conditionals start with a pound sign (#).

诀窍实际上是定义 DEBUG(或其他)常量,因为我很确定默认情况下没有定义.有两种标准的方法:

The trick is actually defining the DEBUG (or whatever) constant because I'm pretty sure that there isn't one defined by default. There are two standard ways of doing it:

  1. 使用 #Const 关键字定义每个源文件顶部的常量.您以这种方式建立的定义在整个源模块中都是有效的.它看起来像:

  1. Use the #Const keyword to define the constant at the top of each source file. The definition that you establish in this way is valid throughout the entire source module. It would look something like:

 #Const DEBUG = 1

  • 在项目的属性中设置常量.这将定义一个在整个项目中都有效的常量(并且可能是您想要的调试"模式指示器).

  • Set the constant in the project's properties. This would define a constant that is valid throughout the entire project (and is probably what you want for a "Debug" mode indicator).

    为此,请在项目属性"对话框的制作"选项卡上的条件编译常量"文本框中输入类似以下内容:

    To do this, enter something like the following in the "Conditional Compilation Constants" textbox on the "Make" tab of the "Project Properties" dialog box:

     DEBUG = 1
    

    您可以在此对话框中定义多个常量,方法是用冒号 (:) 分隔每个常量:

    You can define multiple constants in this dialog by separating each of them with a colon (:):

     DEBUG = 1 : VERSION2 = 1
    

  • 请记住,任何定义的常量都假定为 0.

    Remember that any constant which is not defined is assumed to be 0.

    这篇关于VB 6 中的调试模式?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

    查看全文
    登录 关闭
    扫码关注1秒登录
    发送“验证码”获取 | 15天全站免登陆