Option Explicit
It specifies VB Script to make sure that a variable is declared before it is defined.
So, the following statement will throw an error:-
Option Explicit
a = 100
It should be written as:-
Option Explicit
Dim a 'Declaring the variable.
a = 100
Syntax of 'If' statement -
'To find greatest of 3 numbers.
a = 100
b = 200
c = 300
If a>b and b>c Then
print "a is greatest."
elseif b>c Then
print "b is greatest."
else
print "c is greatest."
End If
While Loop Syntax -
While i<10
print i
i = i + 1 'If this line is missed then program will go in an infinite loop.
Wend
For Loop Syntax -
For x = 1 To 10 Step 1 'Step 1'- means the value of x will increment by 1 in each iteration.
print x
Next
To get numbers in reverse order,
For x = 10 To 1 Step -1
print x
Next
Debugging
Shortcut key - F8.
Breakpoints are used to debug a given section of code to analyze the values/state of variables at that point. At the Breakpoint, when the execution is stopped, we can see the value of a variable in Local Variables tab. Or, we can select a variable and Add to Watch to see its value in Watch section.
At the Breakpoint, when the execution is stopped, if we click F10, then the execution goes line by line. And, if we click F5, then the execution will go on normally.
Nested For Loop -
'To print tables from 1 to 20.
For tableNum = 1 To 20 Step 1
print "Table for " & tableNum
For x = 1 to 10 Step 1
print tableNum & "*"& x & "=" & tableNum*x
Next
Next
This completes the VBScript Fundas required to proceed with the course.
Link to the next module: Module#3: Arrays, Functions, Sub-routines and Objects in VB Script
==================***********************=====================
It specifies VB Script to make sure that a variable is declared before it is defined.
So, the following statement will throw an error:-
Option Explicit
a = 100
It should be written as:-
Option Explicit
Dim a 'Declaring the variable.
a = 100
Syntax of 'If' statement -
'To find greatest of 3 numbers.
a = 100
b = 200
c = 300
If a>b and b>c Then
print "a is greatest."
elseif b>c Then
print "b is greatest."
else
print "c is greatest."
End If
While Loop Syntax -
While i<10
print i
i = i + 1 'If this line is missed then program will go in an infinite loop.
Wend
For Loop Syntax -
For x = 1 To 10 Step 1 'Step 1'- means the value of x will increment by 1 in each iteration.
print x
Next
To get numbers in reverse order,
For x = 10 To 1 Step -1
print x
Next
Debugging
Shortcut key - F8.
Breakpoints are used to debug a given section of code to analyze the values/state of variables at that point. At the Breakpoint, when the execution is stopped, we can see the value of a variable in Local Variables tab. Or, we can select a variable and Add to Watch to see its value in Watch section.
At the Breakpoint, when the execution is stopped, if we click F10, then the execution goes line by line. And, if we click F5, then the execution will go on normally.
Nested For Loop -
'To print tables from 1 to 20.
For tableNum = 1 To 20 Step 1
print "Table for " & tableNum
For x = 1 to 10 Step 1
print tableNum & "*"& x & "=" & tableNum*x
Next
Next
This completes the VBScript Fundas required to proceed with the course.
Link to the next module: Module#3: Arrays, Functions, Sub-routines and Objects in VB Script
==================***********************=====================
No comments:
Post a Comment