#if,#else,#end if ...哈希符号在VBA中是什么意思? [英] #if, #else, #end if ... what do the hash signs mean in VBA?

查看:1011
本文介绍了#if,#else,#end if ...哈希符号在VBA中是什么意思?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在编写一些代码,它将检查一个文件是否可以从SharePoint中检出,如果不是,请提醒用户并告诉他们该文件是由其他人使用的,以及谁它正在使用。



我在这个网站遇到了一段代码: http://www.xcelfiles.com/IsFileOpen.html#anchor_37



代码本身很好,似乎在测试场景,所以我计划适应我的目的,但我无法理解一些使用的语法,因为我从来没有看到过这样的一样。

 #如果不是VBA6然后

'// Xl97

对于i = j - 1到1步骤-1

如果Mid(strXl,i,1)= Chr(0)然后退出

下一个

i = i + 1

#Else

'// Xl2000 +

i = InStrRev(strXl,strFlag1,j)+ Len(strFlag1)

#End如果

我明白代码的作用,但是我不知道'#'符号的含义是什么?



另一个例子是:

  hdlFile = FreeFile 

打开strPath对于二进制为#hdlFile

strXl =空格(LOF(hdlFile))

获取1,,strXl

关闭#hdlFile

我确定这是一个非常明显的答案,但它是一个的东西,这是一个痛苦的对接谷歌,因为它是如此模糊。 :(



非常感谢,



Splat

解决方案

哈希符号表示一个预处理器命令,它们是在编译之前处理的命令,主要生成动态/条件代码,这些类型的命令经常被使用在诸如C / C ++之类的语言中管理跨平台编程技术常见的用法是检查特定环境或平台(即VBA,Windows,MacOSX等),然后实现平台特定的代码。 >

http://en.wikipedia.org/wiki/Preprocessor


I'm writing some code which will check to see if a file is available to be checked out of SharePoint and, if it isn't, alert the user and tell them that the file is in use by someone else and who has it is in use by.

I came across a piece of code at this site: http://www.xcelfiles.com/IsFileOpen.html#anchor_37

The code itself is pretty good and seems to work in test scenarios so I am planning to adapt it for my purposes but I'm having trouble understanding some of the syntax being used because I've never seen the likes of it before.

#If Not VBA6 Then

'// Xl97

For i = j - 1 To 1 Step -1

    If Mid(strXl, i, 1) = Chr(0) Then Exit For

Next

i = i + 1

#Else

'// Xl2000+

i = InStrRev(strXl, strFlag1, j) + Len(strFlag1)

#End If

I understand what the code does but I just don't get what the significance of the '#' symbol is?

Another example of its use is :

hdlFile = FreeFile

Open strPath For Binary As #hdlFile

strXl = Space(LOF(hdlFile))

Get 1, , strXl

Close #hdlFile

I'm sure there is a really obvious answer to this but it is one of things that is a pain in the butt to google because it is so vague. :(

Many thanks,

Splat

解决方案

The hash symbols represent a preprocessor command, which are commands that are processed prior to compilation, essentially producing dynamic / conditional code. These types of commands are often used in languages such as C/C++ to manage cross-platform programming techniques. A common usage is to check for a particular environment or platform (ie. VBA, Windows, MacOSX, etc), and then implement platform-specific code.

http://en.wikipedia.org/wiki/Preprocessor

这篇关于#if,#else,#end if ...哈希符号在VBA中是什么意思?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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