Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

vba: what does the pound sign (#) mean before variable [duplicate]

Tags:

excel

vba

I am writing code to read lines from a text file and I came across this method:

Dim FileNum As Integer
Dim DataLine As String

FileNum = FreeFile()
Open "Filename" For Input As #FileNum

I understand that when # is placed after a variable it denotes it as a double but what does it mean when it is placed before the variable, as in Open "Filename" For Input As #FileNum?

like image 449
Mike Davies Avatar asked Feb 20 '17 12:02

Mike Davies


People also ask

What does pound sign mean in VBA?

The pound is defining which filestream you want to use.

What does #if mean in VBA?

The Microsoft Excel IF-THEN-ELSE statement can only be used in VBA code. It executes one set of code if a specified condition evaluates to TRUE, or another set of code if it evaluates to FALSE. The IF-THEN-ELSE statement is a built-in function in Excel that is categorized as a Logical Function.

What does Colon do in VBA?

In Visual Basic, the separator character is the colon ( : ). Use separators when you want to include multiple statements on a single line instead of separate lines. This saves space and improves the readability of your code.

How do I use symbols in excel VBA?

When you are in the Insert->Symbol Dialog and you select the symbol you want to insert, you'll see at the bottom of the Dialog the hexadecimal character code of the symbol. You can use the codes to write the characters in strings or directly in cells.


1 Answers

The # (for "number") is there since the old times. VB6 just supports it. It does nothing execution wise. It used to assist readability and make the language more natural-like. Speak out loud:

Open "1.txt" For Input As 1

vs.

Open "1.txt" For Input As #1

Reference:- What does a hash do to a variable in VB?

like image 79
arunjos007 Avatar answered Sep 30 '22 22:09

arunjos007