Get the Meaning of Unfamiliar Symbols in Code

  • My new project is to modify an application developed by a consultant who is currently in India, i.e. unavailable. I've looked at all the existing code and I'm OK with it, with the exception of a couple of symbols as shown below. Since the function they're in is relatively short, I've copied it in its entirety in the interest of context.



    The mystery characters are the crosshatch in the line . . .


    Code
    Open sFile For Input As #nSourceFile


    . . .and the dollar sign in the next line down.


    Code
    sText = Input$(LOF(1), 1)


    I've literally scoured the internet, including MSDN of course, and came up with zilch in VBA code. A lot of you folks have been at this a lot longer than I have, so I'm hoping one of you has come across at least one of these symbols and can tell me what they mean. If so, I'll appreciate it greatly.

  • Re: Get the Meaning of Unfamiliar Symbols in Code


    The pound (#) sign usually means 'number' and here indicates that input is to come from the File Handle associated with the variable nSourceFile. You can have multiple files open so that identifies which file.


    Not sure about the latest versions, but all functions in VBA used to have 2 variants, your example of InputBox could be written as InputBox$ or just InputBox. The $ version returns a string, the 'plain' version returns a Variant.


    More things for you to read about.

  • Re: Get the Meaning of Unfamiliar Symbols in Code


    Thanks. Your # explanation makes sense because the app opens 5 different source workbooks. But I'm wondering why anything is needed in addition to nSourceFile being tied to the variable FreeFile (i.e., the next available workbook). Here's MSDN's FreeFile example which doesn't use any symbols, although I guess you could only have those 5 workbooks open:


    Code
    [COLOR=blue]Dim[/COLOR] [COLOR=blue]count[/COLOR] [COLOR=blue]As[/COLOR] [COLOR=blue]Integer[/COLOR] 
    [COLOR=blue]Dim[/COLOR] fileNumber [COLOR=blue]As[/COLOR] [COLOR=blue]Integer[/COLOR] 
    [COLOR=blue]For[/COLOR] [COLOR=blue]count[/COLOR] = 1 [COLOR=blue]To[/COLOR] 5   
       fileNumber = FreeFile()
       FileOpen(fileNumber, [COLOR=#A31515]"TEST"[/COLOR] & [COLOR=blue]count[/COLOR] & [COLOR=#A31515]".TXT"[/COLOR], OpenMode.Output)
       PrintLine(fileNumber, [COLOR=#A31515]"This is a sample."[/COLOR])
       FileClose(fileNumber)
    [COLOR=blue]Next[/COLOR]


    As for the dollar sign, you could just use a conversion function to figure out what the data type should be.


    It must have been a while since using those symbols was a common practice because I Googled every variation I could think of and came up empty, including MDSN.

  • Re: Get the Meaning of Unfamiliar Symbols in Code


    Not sure what happened to the code sample in that reply. Here's the second attempt and it's been previewed.


    Code
    Dim count As Integer 
    Dim fileNumber As Integer 
    For count = 1 To 5   
       fileNumber = FreeFile()
       FileOpen(fileNumber, "TEST" & count & ".TXT", OpenMode.Output)
       PrintLine(fileNumber, "This is a sample.")
       FileClose(fileNumber)
    Next
  • Re: Get the Meaning of Unfamiliar Symbols in Code


    Yes, you are right - both were compulsory in earlier versions of Basic and Visual Basic, but always optional in VBA. They remain to preserve backwards compatibility.


    However the pound is useful to indicate visually that this refers to a file handle so helps comprehension when reading code; and why add in another conversion (to a real string) when vba can do it natively, and faster..?

  • Re: Get the Meaning of Unfamiliar Symbols in Code


    Quote

    They remain to preserve backwards compatibility.


    The dollar sign ($) also serves the purpose of explicit type conversion, (Grimes0332 touched on this in a previous post) which although would have no noticeable impact on today's computers is actually slightly faster than implicit type conversion.


    Code
    '// Explicitly returns a string type
    x = Left$("testing", 4)
    MsgBox x
    
    
    '// Returns a variant
    x = Left("testing", 4)
    '// Which is then implicitly converted to a string
    MsgBox x
  • Re: Get the Meaning of Unfamiliar Symbols in Code


    I'd also get rid of that 'consultant' - tell him to save his money and stay in India. The code is, to put it politely, rubbish;.especially if multiple files are opened. While it will probably work as expected, it has a wonderful logic bomb that is going to cause big tears sometime.

  • Re: Get the Meaning of Unfamiliar Symbols in Code


    Quote from Grimes0332;773006

    I'd also get rid of that 'consultant' - tell him to save his money and stay in India. The code is, to put it politely, rubbish;.especially if multiple files are opened. While it will probably work as expected, it has a wonderful logic bomb that is going to cause big tears sometime.


    Aaaaaand this is why we need 'like' buttons :cool:

  • Re: Get the Meaning of Unfamiliar Symbols in Code


    Thanks so much for enlightening me fellas. I knew this was the best hope of finding someone who had the information I needed. Of course, it's a little intimidating to realize something I thought of as so obscure was common knowledge to this crowd.

  • Re: Get the Meaning of Unfamiliar Symbols in Code


    Quote from skepticologist;772999

    Here's MSDN's FreeFile example which doesn't use any symbols


    Yes, but that's VB.Net not VBA.

    Rory
    Theory is when you know something, but it doesn’t work. Practice is when something works, but you don’t know why. Programmers combine theory and practice: nothing works and they don’t know why

Participate now!

Don’t have an account yet? Register yourself now and be a part of our community!