3

When assigning the freefile return in VBA for excel to an integer, why do all future calls referencing this integer require a hashtag symbol before the variable?

For example:

Dim fileName As String, textData As String, textRow As String, fileNo As Integer
fileName = "C:\test.txt"
fileNo = FreeFile 'Get first free file number  
textData ="Hello World!"
Open fileName For Output As #fileNo
Write #fileNo, textData
Close #fileNo

Why does the variable fileNo have to be reference as #fileNo? Is this another way of type declaration like I found here?

Use of symbol # (hash) in VBA Macro

Thanks!

braX
  • 11,506
  • 5
  • 20
  • 33

1 Answers1

2

Like many features which exist in VBA, such as GoSub...Return, While...Wend and optional line numbering, this syntax is a holdover from the various implementations of BASIC. Here is an example of it used in QBasic.

jsheeran
  • 2,912
  • 2
  • 17
  • 32