4

I have some VBScripts I would like to add my explanation to within the code.

Is there some syntax for adding a comment?

user692942
  • 16,398
  • 7
  • 76
  • 175
  • 3
    You know you should do some research before posting, right? Like googling or trying to find the answer in a manual or something first. https://www.google.com/search?q=comment+in+vbscript&oq=comment+in+vbscr&aqs=chrome.2.69i57j69i60j0l3.7904j0j7&client=ms-android-huawei&sourceid=chrome-mobile&ie=UTF-8 – Andreas Jul 07 '19 at 17:20
  • 3
    I use `'///////` on start of lines for important comments and a single `'` for minor comments – Ali Sheikhpour Jul 07 '19 at 17:21
  • 1
    Surprisingly although this is a very basic topic there is no hard and fast answer on [so] for it. Because of this, I've added an answer. – user692942 Jul 11 '19 at 07:03
  • Why did you un-accept my answer, was there something wrong with it? – user692942 Apr 09 '20 at 14:15

1 Answers1

13

How do you comment code in VBScript?

If in doubt, review The Documentation

Taken from Rem Statement
As shown in the syntax section, you can use an apostrophe (') instead of the Rem keyword. If the Rem keyword follows other statements on a line, it must be separated from the statements by a colon. However, when you use an apostrophe, the colon is not required after other statements.

Below is example using both methods

Rem This is a comment
'This is also a comment

Call SomeFunction(SomeValue) : Rem This is an inline comment
Call SomeFunction(SomeValue) 'This is also an inline comment

There is no real reason to use Rem it's just a throw back from BASIC. The apostrophe approach works just as well as it is less intrusive in my opinion but it is entirely user preference.

What about block comments?

VBScript does not support block comments. Each line must start with either Rem or an Apostrophe ' (multiple variations make no syntactical difference).


Useful Links

user692942
  • 16,398
  • 7
  • 76
  • 175