我试图理解#If ... #Then

编程入门 行业动态 更新时间:2024-10-22 21:45:06
本文介绍了我试图理解#If ... #Then的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述

我想在调试窗口中测试一些代码... 选项比较数据库 Option Explicit Private Sub Command0_Click() #If Win32然后 MsgBox"嘿!它是WIN32。" #End如果 结束子 私有子Command1_Click() #If Win16然后 MsgBox"嘿!它是WIN16。" #End如果 结束子 我没有走得太远。 A97帮助没有打破它,简化了指令让我掌握它。确切地说,#If指令 呢?而且,Win32和Win16的值来自何处? 它们是内在常量吗?

I would like to test some of this code in the debug window... Option Compare Database Option Explicit Private Sub Command0_Click() #If Win32 Then MsgBox "Hey! It''s WIN32." #End If End Sub Private Sub Command1_Click() #If Win16 Then MsgBox "Hey! It''s WIN16." #End If End Sub I''m not getting very far. A97 Help doesn''t break it down, simplifying the directive for me to grasp it. What, exactly, does #If directive do? And, where do the values for Win32 and Win16 come from? Are they intrinsic constants?

推荐答案

>我走得不远。 A97帮助没有分解,简化了 > I''m not getting very far. A97 Help doesn''t break it down, simplifying 指令让我掌握它。究竟#If指令究竟是什么呢?而且,Win32和Win16的值来自哪里?它们是内在常量吗? the directive for me to grasp it. What, exactly, does #If directive do? And, where do the values for Win32 and Win16 come from? Are they intrinsic constants?

看看这段代码: ================================ 选项比较数据库 选项明确 #Const IWantLateBinding = True #IfantLateBinding然后 将myWord称为对象 #Else 将myWord调暗为Access.Application #End如果 Private Sub Form_Load() #IfantLateBinding然后 设置myWord = CreateObject(" Access.Application") #Else 设置myWord =新的Access.Application #End如果 End Sub ======= ========================= #If ....#Then .. ..#Else ....#End If"构造是条件 编译的一部分。 #Const ....声明是另一部分。 - PBsoft di Gabriele Bertolucci www.pbsoft.it skype:pbsoftsolution

Look at this piece of code: ================================ Option Compare Database Option Explicit #Const IWantLateBinding = True #If IWantLateBinding Then Dim myWord as Object #Else Dim myWord as Access.Application #End If Private Sub Form_Load() #If IWantLateBinding Then Set myWord = CreateObject("Access.Application") #Else Set myWord = New Access.Application #End If End Sub ================================ The "#If....#Then....#Else....#End If" construct is part of "conditional compilation". The "#Const...." declaration is the other part. -- PBsoft di Gabriele Bertolucci www.pbsoft.it skype: pbsoftsolution

#If ... #End如果construct是一个条件编译测试。 看到它效果的最简单方法是创建自己的条件 编译常数。 例如 ''这是条件编译常量。 #Const InDebug = False 函数TestInDebug() #If InDebug然后 MsgBox"我们正在调试" #Else MsgBox我们没有调试 #End如果 结束功能 现在,你可能已经意识到你可以用正常的方式获得相同的效果 如果...结束如果构造但是考虑以下作为常见问题的解决方案问题。 /> 创建对Microsoft Word的引用,然后使用以下代码: - #Const InDebug = True 函数TestInDebug() #If InDebug然后 Dim oWord As Word.Application 设置oWord =新Word.Application #Else 将对象视为对象 设置oWord = CreateObject(" Word.Application") #End如果 ''这个位不需要有条件地编译 用oWord .Visible =真的 。错误确认 结束 设置oWord = Nothing 结束功能 首先要注意的是 #Const InDebug = True ....然后当行 oWord.Quit False ....输入我们得到上下文敏感的下拉菜单,如果另一方面 # Const InDebug = False ....然后我们不会 第二次要注意的是,虽然我们有对Word的引用,但 代码运行得非常愉快,条件编译常量设置为 True或False。如果我们删除对toWord的引用并且条件 编译常量设置为False则代码将运行,如果在另一个 手上我们将条件编译常量设置为True然后我们得到一个 错误用户定义的类型未定义和oWord As Word.Application。 突出显示 在模块中定义条件编译常量使其保持不变 仅在定义的模块中具有范围然而,如果您转到 工具菜单并选择<您的应用程序名称>属性"从菜单中你可以定义条件编译常量(作为分号分隔 列表),它们具有应用程序级别范围。 - Terry Kreft " MLH" < CR ** @ NorthState>在留言中写道 news:5t ******************************** @ 4ax ... The #If... #End If construct is a conditional compilation test. The easiest way to see it''s effect is to create your own conditional compilation constant. e.g. '' This is the conditional compilation constant. #Const InDebug = False Function TestInDebug() #If InDebug Then MsgBox "We''re debugging" #Else MsgBox "We''re not debugging" #End If End Function Now, you probably realise that you can get the same effect with a normal If... End If construct but consider the following as a solution to a common problem. Create a reference to Microsoft Word and then use the following code:- #Const InDebug = True Function TestInDebug() #If InDebug Then Dim oWord As Word.Application Set oWord = New Word.Application #Else Dim oWord As Object Set oWord = CreateObject("Word.Application") #End If '' This bit doesn''t need to conditionally compile With oWord .Visible = True .Quit False End With Set oWord = Nothing End Function The first thing to notice is if #Const InDebug = True .... then when the line oWord.Quit False .... is typed we get context sensitive dropdowns, if on the other hand #Const InDebug = False .... then we don''t The second thing to notice is that while we have the reference to Word the code runs quite happily with the conditional compilation constant set to True or False. If we remove the reference toWord and the conditional compilation constant is set to False then the code will run, if on the other hand we set the conditional compilation constant to True then we get an error "User-defined type not defined" and "oWord As Word.Application" is highlighted Defining a conditional compilation constant in a module makes that constant have scope only in the module it is defined in, if however you go to the Tools menu and choose "<Your Application name> Properties" from the menu you can define conditional compilation constants (as a semi-colon delimited list) which have application level scope. -- Terry Kreft "MLH" <CR**@NorthState> wrote in message news:5t********************************@4ax... 我想在调试窗口中测试一些代码... 选项比较数据库选项明确 #If Win32然后 MsgBox嘿!它是WIN32。 #End如果结束Sub 私人Sub Command1_Click() #If Win16那么 MsgBox"嘿!这是WIN16。 #End如果结束Sub 我没有走得太远。 A97帮助并没有打破它,简化了我掌握它的指令。究竟#If指令究竟是什么呢?而且,Win32和Win16的值来自哪里?它们是内在常量吗? I would like to test some of this code in the debug window... Option Compare Database Option Explicit Private Sub Command0_Click() #If Win32 Then MsgBox "Hey! It''s WIN32." #End If End Sub Private Sub Command1_Click() #If Win16 Then MsgBox "Hey! It''s WIN16." #End If End Sub I''m not getting very far. A97 Help doesn''t break it down, simplifying the directive for me to grasp it. What, exactly, does #If directive do? And, where do the values for Win32 and Win16 come from? Are they intrinsic constants?

谢谢Gabriele的解释和 例子。我有一个带有自己的类模块的表单。 表单只有2个按钮,每个按钮的代码运行 如下所示。我没有理解的是,理解的是,WIN16和WIN32''编译器常量''/ b $ b的值只能在#If的范围内读取 - #Then 构建 - 以及其他任何地方。 Terry Kreft也提供了一个很好的例子。你知道 特里在帖子的评论中提到了什么特定的常见问题 ? Thanks, Gabriele, for the explanation and the example. I have a form with its own class module. The form has only 2 buttons and the code running for each button is shown below. What I didn not understand was that the values of WIN16 and WIN32 ''compiler constants'' can be read ONLY within the confines of an #If - #Then construct - and nowhere else. Terry Kreft also provided a fine example. Do you know what specific common problem Terry was referring to early in his comments on the post?

更多推荐

我试图理解#If ... #Then

本文发布于:2023-11-08 16:01:59,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1569833.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!