Semicolon in a Debug.Print Statement

I had no idea this existed.

Sub testsemicolon()
   
    Dim i As Long
   
    For i = 1 To 5
        Debug.Print i
    Next i
   
    For i = 1 To 5
        Debug.Print i;
    Next i
   
End Sub

It’s right there in the help for the Print # Statement, but I’ve never paid attention to it.

13 Comments

  1. João Pinto says:

    It makes two! I also didn’t knew that this was possible! Learning everyday… :)

  2. Redge says:

    Now that’s a nice tidbit of information. May be help is help after all.

  3. Keith Halford says:

    Interesting. I frequently write text to ASCII files and this could be handy. Although I do like format control one has by building a text string and printing the single item to a line.

  4. fzz says:

    It’s been part of BASIC’s PRINT statement since the original version at Dartmouth College in the mid 1960s.

  5. Rob van Gelder says:

    I’m not sure how I’ll use this, but I’m definitely pleased to have learned it. Thanks!

  6. Mpemba says:

    The comma works too.

    If you are using it, it’s good practice to follow the loop with a simple Debug.Print…

    Mpemba

  7. Patrick says:

    I too had no idea that was there. Very cool.

  8. We learn something every day.

  9. fzz says:

    @Mpemba -

    Yes, commas work too, just as the origial BASIC manual from 1965 says they do. Cudos to MSFT for not changing this, er, basic functionality.

  10. Pete says:

    I used them as a schoolboy in the mid 70s when I started programming in BASIC; and in recent years in VBA.

  11. Rick Rothstein (MVP - Excel) says:

    I am guessing that you never used the Tab or Spc functions then. I am pretty sure suppressing the newline by using a semi-colon was originally introduced (oh so many years ago now) so that one could chain together data along with the crude formatting capabilities offered by the Tab and Spc functions when printing to a file.

  12. fzz says:

    QBASIC had PRINT USING, and I believe I recall BASICA did too, but I don’t believe VBA ever did. PRINT USING was what one used to format printed output in the dark ages of BASIC.

    Quibble: VBA’s print zones are 14 chars while original DTSS BASIC print zones were 15 chars.

  13. Nick says:

    As others haves stated, this has been part of BASIC. So I’m just shocked people are discovering this now. ;-)

Leave a Reply