Slide show

[BasicVbscript][slideshow]

VBScript - Syntax


VBScript - Syntax

Syntax Of VBScript
Syntax Of VBScript



    Your First VBScript is
        Let us write a VBScript to print out "Hello script kiddie".
<html>
    <body>
        <script language="vbscript" type="text/vbscript">
               document.write("Hello script kiddie!")
        </script>
    </body>
</html>


                In the above example, we called a function document.write, which writes a string into the HTML document. This function can be used to write text, HTML or both. So, above code will display following result:

Hello script kiddie!

  • Whitespace and Line Breaks :
                 VBScript ignores spaces, tabs and newlines that appear within VBScript programs.
                 Because one can use spaces, tabs and newlines freely within the program so you are free to format and indent your programs in a neat and consistent way that makes the code easy to read and understand.
  • Formatting :

                VBScript is based on Microsoft's Visual Basic. Unlike JavaScript, no statement terminators such as semicolon is used to terminate a particular statement.

  • Single Line Syntax :

                Colons are used when two or more lines of VBScript ought to be written in a single line. Hence, in VBScript, Colons act as a line separator.

<script language="vbscript" type="text/vbscript">
      var1 = 10 : var2 = 20
</script>

  • Multiple Line Syntax :
                When a statement in VBScript is lengthy and if user wishes to break it into multiple lines, then the user has to use underscore "_".
                 This improves the readability of the code. The following example illustrates how to work with multiple lines.


<script language="vbscript" type="text/vbscript">
  var1 = 10
  var2 = 20
  Sum = var1 + var2 
  document.write("The Sum of two numbers"&_
  "var1 and var2 is " & Sum)
</script>



  • Reserved Words :

                The following list shows the reserved words in VBscripting. These reserved words SHOULD NOT be used as a constant or variable or any other identifier names.

 Loop
 LSet
 Me
 Mod
ParamArray
 Or
 Next
 Preserve
 ReDim
 Not
 Nothing
 Null
 On
Currency
  New
 Optional
 Private
 Rem
 Resume
 RSet
 Select
 Set
 Shared
 Single
 Static
 Stop
 Then
 To 
 True
 Type
 And
 Boolean
 As
 ByRef
 Byte
 Call
 Case
 Class
 Const
Option
 Debug
 Dim
 Do
 Double
 Else
 End
 EndIf
 Enum
 Eqv
 Event
 Exit
 False
 Empty
 ElseIf
 False
 For
 Function
 Get
SendKeys
 Imp
If 
 Implements
 Integer
 Is
Let
 Like
 Long
 TypeOf 
 Until
Variant 
 Wend
 With
  GoTo
 Randomize
 Explicit
 Option 
 ExecuteGlobal
 Erase
 Msgbox
 Execute
Xor 
 Public
 RaiseEvent
 Sub
 ByVal
 Each
 False
 In
 While
 Eval
        
  • Case Sensitivity :

                VBScript is a case-insensitive language. This means that language keywords, variables, function names and any other identifiers need NOT be typed with a consistent capitalization of letters.
                So identifiers int_counter, INT_Counter and INT_COUNTER have the same meaning within VBScript.

  • Comments in VBScript :

                Comments are used to document the program logic and the user information with which other programmers can seamlessly work on the same code in future.
                It can include information such as developed by, modified by and it can also include incorporated logic. Comments are ignored by the interpreter while execution.


                Comments in VBScript are denoted by two methods.

1. Any statement that starts with a Single Quote (‘) is treated as comment. Following is the example:


<script language="vbscript" type="text/vbscript">
<!—
  ' This Script is invoked after successful login
  ' Written by : Script Kiddie
  ' Return Value : True / False
//- >
</script>


No comments:

Basic Vbscript

[BasicVbscript][stack]

Advanced Vbscript

[BasicVbscript][grids]

Example

[BasicVbscript][btop]