Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What do the hash signs in #if, #else, #end if mean?

I'm writing code to check 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 in use.

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

The code seems to work in test scenarios so I am planning to adapt it for my purposes. I'm having trouble understanding some of the syntax.

#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 don't get the significance of the '#' symbol.

Another example:

hdlFile = FreeFile  Open strPath For Binary As #hdlFile  strXl = Space(LOF(hdlFile))  Get 1, , strXl  Close #hdlFile 

It is a pain to google because it is so vague.

like image 241
Splatgore Avatar asked Jun 12 '11 23:06

Splatgore


People also ask

What is the hash symbol used for?

The symbol # is known variously in English-speaking regions as the number sign, hash, or pound sign. The symbol has historically been used for a wide range of purposes including the designation of an ordinal number and as a ligatured abbreviation for pounds avoirdupois – having been derived from the now-rare ℔.

Does the hash go before or after the number?

It is usually used just before an actual numeral or number, and is sometimes known as the pound sign.

What is the name of the hashtag symbol?

And it isn't the “number sign” or the “pound sign,” as it was called back in the #DarkAges before Twitter. The technical term for a hashtag is “octothorp,” according to the OED; octo, in reference to the eight points in the figure, and Thorpe, OED says cryptically, from “the surname Thorpe.” Whatever that means.


2 Answers

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

like image 116
Chris Hutchinson Avatar answered Oct 02 '22 17:10

Chris Hutchinson


The hash indicates that it's a directive. Used for literally including or excluding code from compilation.

http://msdn.microsoft.com/en-us/library/7ah135z7.aspx

whoops that's for vb.net isn't it. Same concept I think.

like image 34
Joshua Evensen Avatar answered Oct 02 '22 16:10

Joshua Evensen