Coding With Fun
Home Docker Django Node.js Articles Python pip guide FAQ Policy

VBScript program


May 13, 2021 VBScript


Table of contents


VBScript program


VBScript can use two programs:

  • Sub-program
  • The function program

VBScript sub-program

A sub-program is a single sentence of a statement block with a particular function written as a separate program, giving a specific name.

Sub-programs:

  • is a series of statements encapsulated in Sub and End Sub statements
  • You can do something, but does not return a value
  • Can be with parameters
Sub mysub()
some statements
End Sub

Or

Sub mysub(argument1,argument2)
some statements
End Sub

Instances (IE only)

Sub mysub()
document.write("I was written by a sub procedure")
End Sub

Try it out . . .


VBScript function program

Function program:

  • is a series of statements encapsulated in Function and End Function statements
  • Something can be done, and returns the value
  • You can have parameters that are passed to you through a program call.
  • If there are no arguments, there must be empty parentheses ()
  • You can return a value by assigning a value to the function program name
Function myfunction()
some statements
myfunction= some value
End Function

Or

Function myfunction(argument1,argument2)
some statements
myfunction= some value
End Function

Instances (IE only)

function myfunction()
myfunction=Date()
end function

Try it out . . .


Call the program

This simple function program is called to calculate the number of two parameters:

Instances (IE only)

Function myfunction(a,b)
myfunction=a+b
End Function

document.write(myfunction(5,9))

Try it out . . .

The function "myfunction" returns the values "a" and "b" of the . The return here is 14.

When you call a program, you can use the Call statement as follows:

Call MyProc(argument)

Alternatively, you can omit the Call statement as follows:

MyProc argument