Sunday, March 10, 2013

A Quick VBScript Tutorial

Option explicit
 Dim x, i

 i = 10

 x="Hello World"
 Wscript.Echo x

 'subroutine cannot return value like function returning void

 ' calling function which returns date
 Wscript.Echo myfunc()

 ' if then elseif else
 if i=10 then
 i = i+1
 elseif i = 12 then
 Msgbox ("i is 12")

 Msgbox("came to else")

 end if

' select case
Select case i
 case 11
Msgbox "i is 11"
case 20
Msgbox "i is 20"
case else
Msgbox "default case"
End Select

' for loop
For i= 0 To 5 step 1
Wscript.Echo "hello for loop"

 'Msgbox x

 ' subroutine
 sub mysub()
Wscript.echo "This is mysub()"
 end sub

 ' function which returns date
 function myfunc()
myfunc= Date()
 end function

No comments: