Blow is some comment for my Vb script learning, for convenience of future review:
1. Always dim the variables with option explicit. If not so, some spelling errors in variable evaluation may cause strange result when script running. Safty is No.1 haha
name="Hege"
i=200
dim names(2)
names(0)="Tove"
names(1)="Jani"
names(2)="Stale"
dim table(4, 6)
2.Procedure
Sub:
Sub mysub()
some statements
End Sub
or
Sub mysub(argument1,argument2)
some statements
End Sub
Function:
Function myfunction()
some statements
myfunction=some value
End Function
or
Function myfunction(argument1,argument2)
some statements
myfunction=some value
End Function
Call a Sub or Function Procedure:
Call function:
name = findname()
Call Sub:
Call MyProc(argument)
or
MyProc argument
3.Condictional Statement
if i=10 Then msgbox "Hello"
if i=10 Then
msgbox "Hello"
i = i+1
end If
if i=10 then
msgbox "Hello"
else
msgbox "Goodbye"
end If
if payment="Cash" then
msgbox "You are going to pay cash!"
elseif payment="Visa" then
msgbox "You are going to pay with visa."
elseif payment="AmEx" then
msgbox "You are going to pay with American Express."
else
msgbox "Unknown method of payment."
end If
select case payment
case "Cash"
msgbox "You are going to pay cash"
case "Visa"
msgbox "You are going to pay with visa"
case "AmEx"
msgbox "You are going to pay with American Express"
case Else
msgbox "Unknown method of payment"
end select
4.Looping Statements
For i=1 to 10
some code
Next
For i=2 To 10 Step 2
some code
Next
You can exit a For...Next statement with the Exit For keyword.
For Each x in cars
document.write(x & "
")
Next
Do While i>10
some code
Loop
If i equals 9, the code inside the loop above will never be executed.
Do
some code
Loop While i>10
The code inside this loop will be executed at least one time, even if i is less than 10.
Do Until i=10
some code
Loop
If i equals 10, the code inside the loop will never be executed.
Do
some code
Loop Until i=10
The code inside this loop will be executed at least one time, even if i is equal to 10.
You can exit a Do...Loop statement with the Exit Do keyword.
Do Until i=10
i=i-1
If i<10 Then Exit Do Loop
5.Function reference
see http://www.w3schools.com/Vbscript/vbscript_ref_functions.asp
Monday, March 9, 2009
VB script journey START
Since there is no much things to do these days, I'll digging into VB script in preparing of my future tasks! May god bless!
Subscribe to:
Comments (Atom)