Sideway
output.to from Sideway





Draft for Information Only

Content

VBScript Procedure Statement
 Class Statement
  Syntax
  Argument
  Remarks
  Requirement
 Property Get Statement
  Syntax
  Argument
  Remarks
  Requirement
 Property Let Statement
  Syntax
  Argument
  Remarks
  Requirement
 Property Set Statement
  Syntax
  Argument
  Remarks
  Requirement
 Examples
 Function Statement
  Syntax
  Argument
  Remarks
  Requirement
 Examples
 Sub Statement
  Syntax
  Argument
  Remarks
  Requirement
 Examples

VBScript Procedure Statement

The procedure statements are .

Class Statement

last updated 2017/11/21

to declares a class by a specified name, as well as a definition of the variables, properties, and methods that comprise the class.

Syntax

Class name
   statements
End Class

Argument

ClassRequired keyword. to indicate the start of Class…End Class.nameRequired. to specify the name of the Class following the standard variable naming conventions.statementsOptional. One or more statements that define the variables, properties, and methods of the Class.End ClassRequired keyword. to indicate the end of Class…End Class.

Remarks

  • Within a Class block, members are declared as either Private or Public using the appropriate declaration statements.
  • Anything declared as Private is visible only within the Class block. Anything declared as Public is visible within the Class block, as well as by code outside the Class block. Anything not explicitly declared as either Private or Public is Public by default.
  • Procedures (either Sub or Function) declared Public within the class block become methods of the class.
  • Public variables serve as properties of the class, as do properties explicitly declared using Property Get, Property Let, and Property Set.
  • Default properties and methods for the class are specified in their declarations using the Default keyword. See the individual declaration statement topics for information on how this keyword is used.
  • Class also supports event, for example, Class_Initialize(), Class_Terminate().

Requirement

5

Property Get Statement

last updated 2017/11/23

to declare, in a Class block, the name, arguments, and code that form the body of a Property procedure that gets (returns) the value of a property.

Syntax

[Public [Default] | Private] Property Get name [(arglist)]
   [statements]
   [[Set] name = expression]
   [Exit Property] 
   [statements]
   [[Set] name = expression]
End Property

Argument

PublicOptional keyword that cannot be used together with Private keyword. Keyword used to indicate that the Property Get procedure is available to all other procedures in all scripts.DefaultOptional keyword that is used only with the Public keyword to indicate that the property defined in Property Get procedure is the default property for the class.PrivateOptional keyword that cannot be used together with Public keyword. Keyword used to Indicate that the Property Get procedure is accessible only to other procedures in the Class block where it is declared.Property GetRequired keyword. To indicate the start of Property Get statement.nameRequired. is used to specify the name of the Property Get procedure following the standard variable naming conventions. However, the name can be the same as a Property Let or Property Set procedure in the same Class block.arglistOptional. to specify the list of variables representing arguments that are passed to the Property Get procedure when it is called. Commas separate multiple variables. However, the name of each argument in a Property Get procedure must be the same as the corresponding argument in a Property Let procedure (if one exists).statementsOptional. Any group of statements to be executed within the body of the Property Get procedure.SetOptional Keyword. Keyword used when assigning an object as the return value of a Property Get procedure.=Optional assignment keyword, but required when the assignment statement name= is specified. to assign the return value of the Property Get procedure.expressionOptional, but required when the assignment statement name= is specified. to specify the return value of the Property Get procedure.Exit PropertyOptional. to cause an immediate exit from a Property Get procedure. Program execution continues with the statement that follows the statement that called the Property Get procedure.End PropertyRequired. to indicate the end of Property Get.

Remarks

  • If not explicitly specified using either Public or Private, Property Get procedures are public by default, that is, they are visible to all other procedures in your script. The value of local variables in a Property Get procedure is not preserved between calls to the procedure.
  • A Property Get procedure cannot be defined inside any other procedure , for example, Function or Property Let.
  • The Exit Property statement causes an immediate exit from a Property Get procedure. Program execution continues with the statement that follows the statement that called the Property Get procedure. Any number of Exit Property statements can appear anywhere in a Property Get procedure.
  • Like a Sub and Property Let procedure, a Property Get procedure is a separate procedure that can take arguments, perform a series of statements, and change the value of its arguments. However, unlike a Sub and Property Let, you can use a Property Get procedure on the right side of an expression in the same way you use a Function or property name when you want to return the value of a property.

Requirement

5

Property Let Statement

last updated 2017/11/23

to declare, in a Class block, the name, arguments, and code that form the body of a Property procedure that assigns (sets) the value of a property.

Syntax

[Public | Private] Property Let name ([arglist,] value)
   [statements]
   [Exit Property] 
   [statements]
End Property

Argument

PublicOptional keyword that cannot be used together with Private keyword. Keyword used to indicate that the Property Let procedure is available to all other procedures in all scripts.PrivateOptional keyword that cannot be used together with Public keyword. Keyword used to Indicate that the Property Let procedure is accessible only to other procedures in the Class block where it is declared.Property GetRequired keyword. To indicate the start of Property Get statement.nameRequired. is used to specify the name of the Property Let procedure following the standard variable naming conventions. However, the name can be the same as a Property Get or Property Set procedure in the same Class block.arglistOptional. to specify the list of variables representing arguments that are passed to the Property Let procedure when it is called. Commas separate multiple variables. However, the name of each argument in a Property Let procedure must be the same as the corresponding argument in a Property Get procedure. In addition, the Property Let procedure will always have one more argument than its corresponding Property Get procedure. That argument is the value being assigned to the property.valueRequired. Variable to contain the value to be assigned to the property. When the procedure is called, this argument appears on the right side of the calling expression.statementsOptional. Any group of statements to be executed within the body of the Property Let procedure.Exit PropertyOptional. to cause an immediate exit from a Property Let procedure. Program execution continues with the statement that follows the statement that called the Property Let procedure.End PropertyRequired. to indicate the end of Property Let.

Remarks

  • If not explicitly specified using either Public or Private, Property Let procedures are public by default, that is, they are visible to all other procedures in your script. The value of local variables in a Property Let procedure is not preserved between calls to the procedure.
  • A Property Let procedure cannot be defined inside any other procedure, for example, Function or Property Get.
  • The Exit Property statement causes an immediate exit from a Property Let procedure. Program execution continues with the statement that follows the statement that called the Property Let procedure. Any number of Exit Property statements can appear anywhere in a Property Let procedure.
  • Every Property Let statement must define at least one argument for the procedure it defines. That argument (or the last argument if there is more than one) contains the actual value to be assigned to the property when the procedure defined by the Property Let statement is invoked. That argument is referred to as value in the preceding syntax.
  • Like a Function and Property Get procedure, a Property Let procedure is a separate procedure that can take arguments, perform a series of statements, and change the value of its arguments. However, unlike a Function and Property Get procedure, both of which return a value, a Property Let procedure can only be used on the left side of a property assignment expression.

Requirement

5

Property Set Statement

last updated 2017/11/23

to declare, in a Class block, the name, arguments, and code that form the body of a Property procedure that sets a reference to an object.

Syntax

[Public | Private] Property Set name([arglist,] reference)
   [statements]
   [Exit Property] 
   [statements]
End Property

Argument

PublicOptional keyword that cannot be used together with Private keyword. Keyword used to indicate that the Property Set procedure is available to all other procedures in all scripts.PrivateOptional keyword that cannot be used together with Public keyword. Keyword used to Indicate that the Property Set procedure is accessible only to other procedures in the Class block where it is declared.Property SetRequired keyword. To indicate the start of Property Set statement.nameRequired. is used to specify the name of the Property Set procedure following the standard variable naming conventions. However, the name can be the same as a Property Get or Property Let procedure in the same Class block.arglistOptional. to specify the list of variables representing arguments that are passed to the Property Set procedure when it is called. Commas separate multiple variables. However, the name of each argument in a Property Set procedure must be the same as the corresponding argument in a Property Get procedure. In addition, the Property Set procedure will always have one more argument than its corresponding Property Get procedure. That argument is the object reference being assigned to the property.referenceRequired. Variable to contain the object reference to be assigned to the property. When the procedure is called, this argument appears on the right side of the object reference assignment.statementsOptional. Any group of statements to be executed within the body of the Property Set procedure.Exit PropertyOptional. to cause an immediate exit from a Property Set procedure. Program execution continues with the statement that follows the statement that called the Property Set procedure.End PropertyRequired. to indicate the end of Property Set.

Remarks

  • If not explicitly specified using either Public or Private, Property Set procedures are public by default, that is, they are visible to all other procedures in your script. The value of local variables in a Property Set procedure is not preserved between calls to the procedure.
  • You can't define a Property Set procedure inside any other procedure, for example, Function or Property Let.
  • The Exit Property statement causes an immediate exit from a Property Set procedure. Program execution continues with the statement that follows the statement that called the Property Set procedure. Any number of Exit Property statements can appear anywhere in a Property Set procedure.
  • Every Property Set statement must define at least one argument for the procedure it defines. That argument (or the last argument if there is more than one) contains the actual object reference for the property when the procedure defined by the Property Set statement is invoked. That argument is referred to as reference in the preceding syntax.
  • Like a Function and Property Get procedure, a Property Set procedure is a separate procedure that can take arguments, perform a series of statements, and change the value of its arguments. However, unlike a Function and Property Get procedure, both of which return a value, a Property Set procedure can only be used on the left side of an object reference assignment (Set statement).

Requirement

5

Examples

Examples of Class Statement, Property Get Statement, Property Let Statement, Property Set Statement

ASP VbScript Command:
<script runat="server" language="VBScript">
Dim vars,strs,cmda
cmda=array("d.xa","d.xb")
Dim ucnt,tmp,i:ucnt=UBound(cmda):If var=1 Then:tmp="":Else:tmp="<b>vars</b>":End If:For i=0 to ucnt:tmp=tmp&"<b>"&rmv_ctrl(cmda(i))&", TypeName</b>":Next:Response.Write "Results on Microsoft Windows 8.1 Pro x64, Microsoft-IIS/8.5, VBScript Version 5.8 of page /sideway/default.asp<br />"&"<i>"&tmp&"</i>"
Function dsp_x:Dim tmp_a,tmp_b,i:If varx=0  Then:Execute vars:End If:If var=1 Then:tmp_a="":Else:tmp_a=rmv_ctrl(vars):End If:For i=0 to ucnt:tmp_b=cmd_b(cmda(i)):if i/2=fix(i/2) Then:tmp_b="<b>"&tmp_b&"</b>":End If:tmp_a=tmp_a&tmp_b:Next:Response.Write "<i>"&tmp_a&"</i>":End Function
Function rmv_ctrl(blk_str):Select Case blk_str:Case chr(0):blk_str="NUL":Case chr(1):blk_str="SOH":Case chr(2):blk_str="STX":Case chr(3):blk_str="ETX":Case chr(4):blk_str="EOT":Case chr(5):blk_str="ENQ":Case chr(6):blk_str="ACK":Case chr(7):blk_str="BEL":Case chr(8):blk_str="BS":Case chr(9):blk_str="HT":Case chr(10):blk_str="LF":Case chr(11):blk_str="VT":Case chr(12):blk_str="FF":Case chr(13):blk_str="CR":Case chr(14):blk_str="SO":Case chr(15):blk_str="SI":Case chr(16):blk_str="DLE":Case chr(17):blk_str="DC1":Case chr(18):blk_str="DC2":Case chr(19):blk_str="DC3":Case chr(20):blk_str="DC4":Case chr(21):blk_str="NAK":Case chr(22):blk_str="SYN":Case chr(23):blk_str="ETB":Case chr(24):blk_str="CAN":Case chr(25):blk_str="EM":Case chr(26):blk_str="SUB":Case chr(27):blk_str="ESC":Case chr(28):blk_str="FS":Case chr(29):blk_str="GS":Case chr(30):blk_str="RS":Case chr(31):blk_str="US":Case chr(127):blk_str="DEL":End Select:rmv_ctrl=blk_str:If IsNull(blk_str) OR IsEmpty(Blk_str) OR blk_str="" OR IsNumeric(Blk_str) Then:Else:rmv_ctrl=Replace(Replace(Replace(Replace(Replace(blk_str,"&","&amp;"),"  "," &nbsp;"),"""","&quot;"),"<","&lt;"),">","&gt;"): End If :End Function
Function cmd_b(blk_str):cmd_b="["&cmd_x(blk_str)&"], "&cmd_x("TypeName("&blk_str&")"):End Function
Function cmd_x(blk_str):On Error Resume Next:Dim xans, tmp:xans="":tmp="":execute "xans="&blk_str:If Err.Number <> 0  Then:xans=cmd_x("TypeName("&blk_str&")"):Select Case xans:Case 9::Case Else:xans="error":End Select:End If:If IsArray(xans)=False Then:cmd_x=rmv_ctrl(xans): Else:tmp=lst_arry(xans):cmd_x=trim(tmp):End If:End Function
Function lst_arry(blk_str):Dim tmp,i,q:q="""":tmp="":For i=0 to UBound(blk_str):if VarType(blk_str(i))>1 And VarType(blk_str(i))<6 Then:q="'":End If:tmp=tmp&" "&q&rmv_ctrl(blk_str(i))&q:Next:lst_arry=trim(tmp):End Function

vars="Class xclass:Private a:Private b:Private Sub Class_Initialize:a = """":b = 0:End Sub:Public Property Get xa:xa = a:End Property:Public Property Let xa(stra):a = stra:End Property:Public Property Get xb:xb = b:End Property:Public Sub Incb(numb):b=b+numb:End Sub:End Class:set d=New xclass":dsp_x
vars="d.xa=""stra""":dsp_x
vars="d.incb(3)":dsp_x
vars="d.incb(3)":dsp_x
</script>
HTML Web Page In-line Output:
Results on Microsoft Windows 8.1 Pro x64, Microsoft-IIS/8.5, VBScript Version 5.8 of page /sideway/default.asp
varsd.xa, TypeNamed.xb, TypeNameClass xclass:Private a:Private b:Private Sub Class_Initialize:a = "":b = 0:End Sub:Public Property Get xa:xa = a:End Property:Public Property Let xa(stra):a = stra:End Property:Public Property Get xb:xb = b:End Property:Public Sub Incb(numb):b=b+numb:End Sub:End Class:set d=New xclass[], String[0], Integerd.xa="stra"[stra], String[0], Integerd.incb(3)[stra], String[3], Integerd.incb(3)[stra], String[6], Integer

Function Statement

last updated 2017/11/22

to declare the name, arguments, and code that form the body of a Function procedure.

Syntax

[Public [Default] | Private] Function name [(arglist)]
   [statements]
   [name = expression]
   [Exit Function] 
   [statements]
   [name = expression]
End Function
arglist:  [ByVal | ByRef] varname[(…)],[ByVal | ByRef] varname[(…)],…

Argument

PublicOptional keyword that cannot be used together with Private keyword. Keyword used to indicate that the Function procedure is available to all other procedures in all scripts.DefaultOptional keyword that is used only with the Public keyword in a Class block to indicate that the Function procedure is the default method for the class. An error occurs if more than one Default procedure is specified in a class.PrivateOptional keyword that cannot be used together with Public keyword. Keyword used to Indicate that the Function procedure is accessible only to other procedures in the script where it is declared or if the Function is a member of a class, and that the Function procedure is accessible only to other procedures in that class.FunctionRequired keyword. To indicate the start of Function.nameRequired. Is used to specify the name of the Function following the standard variable naming conventions.arglistOptional. To specify the list of variables representing arguments that are passed to the Function procedure when it is called. Commas separate multiple variables.=Optional assignment keyword, but required when the assignment statement name= is specified. To assign the return value of the Function.statementsOptional. Any group of statements to be executed within the body of the Function procedure.expressionOptional, but required when the assignment statement name= is specified. To specify the return value of the Function.Exit FunctionOptional. to cause an immediate exit from a Function procedure. Program execution continues with the statement that follows the statement that called the Function procedure.End FunctionRequired. to indicate the end of Function.ByValOptional, but cannot be used together with ByRef. is used to Indicate that the argument is passed by value.ByRefOptional, but cannot be used together with ByVal. is used to Indicate that the argument is passed by reference. If ByVal and ByRef are omitted, the default is ByRef.varnameRequired. to specify the name of the variable representing the argument with name following standard variable naming conventions.(…)Optional, required if an array variable is specified. A pair of parenthetic brackets is needed to enclose subscripts.

Remarks

  • A Function procedure can be called by using the function name followed by the argument list.
  • However, if the Call keyword is used, the argument list after the function name must be enclosed in parentheses, and the return value of the function is discarded.
  • If a function is not explicityly specified using either Public or Private, Function procedures are public by default, that is, Function procedures are visible to all other procedures in script.
  • No other procedure, for example, Sub or Property Get, can be defined inside a Function procedure.
  • In a Function declaration, each parameter can be specified as ByRef or ByVal. If neither is specified, the default is ByRef. If ByVal is specified, the corresponding argument is always passed by value when the subroutine is called. If ByRef (or neither) is specified, the argument can be passed by reference or by value when the subroutine is called.
  • Function procedures can be recursive, that is, they can call themselves to perform a given task. However, recursion can lead to stack overflow.
  • Visual Basic Scripting Edition (VBScript) may rearrange arithmetic expressions to increase internal efficiency. Avoid using a Function procedure in an arithmetic expression when the function changes the value of variables in the same expression.
  • A Function procedure can be used on the right side of an expression in the same way as any intrinsic function, such as Sqr, Cos, or Chr, when using the value returned by the function.
  • To return a value from a function, assign the value to the function name with an expression in the procedure. Any number of such assignments can appear anywhere within the procedure. If no value is assigned to name, the procedure returns a default value: a numeric function returns 0 and a string function returns a zero-length string (""). A function that returns an object reference returns Nothing if no object reference is assigned to name (using Set) within the Function.
  • Like a Function procedure, a Sub procedure is a separate procedure that can take arguments, perform a series of statements, and change the value of its arguments. However, unlike a Function procedure, which returns a value, a Sub procedure cannot be used in an expression.
  • The values of local variables in a Function are not preserved between calls to the procedure.
  • Variables that are explicitly declared in a procedure (using Dim or the equivalent) are always local to the procedure. Variables that are used but not explicitly declared in a procedure are also local unless they are explicitly declared at some higher level outside the procedure.
  • For variables that are not explicitly declared in the procedure, a naming conflict can occur if anything that have been defined at the script level has the same name. If the procedure refers to an undeclared variable that has the same name as another procedure, constant, or variable, it is assumed that that procedure is referring to that script-level name. To avoid this kind of conflict, use an Option Explicit Statement to force explicit declaration of variables.
  • The Exit Function statement causes an immediate exit from a Function procedure. Program execution continues with the statement that follows the statement that called the Function procedure. Any number of Exit Function statements can appear anywhere in a Function procedure.

Requirement

1

Examples

Examples of Function Statement

ASP VbScript Command:
<script runat="server" language="VBScript">
Dim vars,strs,cmda:varx=1
cmda=array("a","b","sumab(a,b)")
Dim ucnt,tmp,i:ucnt=UBound(cmda):If var=1 Then:tmp="":Else:tmp="<b>vars</b>":End If:For i=0 to ucnt:tmp=tmp&"<b>"&rmv_ctrl(cmda(i))&", TypeName</b>":Next:Response.Write "Results on Microsoft Windows 8.1 Pro x64, Microsoft-IIS/8.5, VBScript Version 5.8 of page /sideway/default.asp<br />"&"<i>"&tmp&"</i>"
Function dsp_x:Dim tmp_a,tmp_b,i:If varx=0  Then:Execute vars:End If:If var=1 Then:tmp_a="":Else:tmp_a=rmv_ctrl(vars):End If:For i=0 to ucnt:tmp_b=cmd_b(cmda(i)):if i/2=fix(i/2) Then:tmp_b="<b>"&tmp_b&"</b>":End If:tmp_a=tmp_a&tmp_b:Next:Response.Write "<i>"&tmp_a&"</i>":End Function
Function rmv_ctrl(blk_str):Select Case blk_str:Case chr(0):blk_str="NUL":Case chr(1):blk_str="SOH":Case chr(2):blk_str="STX":Case chr(3):blk_str="ETX":Case chr(4):blk_str="EOT":Case chr(5):blk_str="ENQ":Case chr(6):blk_str="ACK":Case chr(7):blk_str="BEL":Case chr(8):blk_str="BS":Case chr(9):blk_str="HT":Case chr(10):blk_str="LF":Case chr(11):blk_str="VT":Case chr(12):blk_str="FF":Case chr(13):blk_str="CR":Case chr(14):blk_str="SO":Case chr(15):blk_str="SI":Case chr(16):blk_str="DLE":Case chr(17):blk_str="DC1":Case chr(18):blk_str="DC2":Case chr(19):blk_str="DC3":Case chr(20):blk_str="DC4":Case chr(21):blk_str="NAK":Case chr(22):blk_str="SYN":Case chr(23):blk_str="ETB":Case chr(24):blk_str="CAN":Case chr(25):blk_str="EM":Case chr(26):blk_str="SUB":Case chr(27):blk_str="ESC":Case chr(28):blk_str="FS":Case chr(29):blk_str="GS":Case chr(30):blk_str="RS":Case chr(31):blk_str="US":Case chr(127):blk_str="DEL":End Select:rmv_ctrl=blk_str:If IsNull(blk_str) OR IsEmpty(Blk_str) OR blk_str="" OR IsNumeric(Blk_str) Then:Else:rmv_ctrl=Replace(Replace(Replace(Replace(Replace(blk_str,"&","&amp;"),"  "," &nbsp;"),"""","&quot;"),"<","&lt;"),">","&gt;"): End If :End Function
Function cmd_b(blk_str):cmd_b="["&cmd_x(blk_str)&"], "&cmd_x("TypeName("&blk_str&")"):End Function
Function cmd_x(blk_str):On Error Resume Next:Dim xans, tmp:xans="":tmp="":execute "xans="&blk_str:If Err.Number <> 0  Then:xans=cmd_x("TypeName("&blk_str&")"):Select Case xans:Case 9::Case Else:xans="error":End Select:End If:If IsArray(xans)=False Then:cmd_x=rmv_ctrl(xans): Else:tmp=lst_arry(xans):cmd_x=trim(tmp):End If:End Function
Function lst_arry(blk_str):Dim tmp,i,q:q="""":tmp="":For i=0 to UBound(blk_str):if VarType(blk_str(i))>1 And VarType(blk_str(i))<6 Then:q="'":End If:tmp=tmp&" "&q&rmv_ctrl(blk_str(i))&q:Next:lst_arry=trim(tmp):End Function

vars="Function sumab(a,b):sumab=a+b:Exit Function:sumab=a:End Function:a=5:b=7":Execute vars:dsp_x
vars="a=4:b=3":varx=0:dsp_x
</script>
HTML Web Page In-line Output:
Results on Microsoft Windows 8.1 Pro x64, Microsoft-IIS/8.5, VBScript Version 5.8 of page /sideway/default.asp
varsa, TypeNameb, TypeNamesumab(a,b), TypeNameFunction sumab(a,b):sumab=a+b:Exit Function:sumab=a:End Function:a=5:b=7[5], Integer[7], Integer[12], Integera=4:b=3[4], Integer[3], Integer[7], Integer

Sub Statement

last updated 2017/11/24

to declares the name, arguments, and code that form the body of a Sub procedure.

Syntax

[Public [Default]  | Private] Sub name [(arglist)] 
   [statements]
   [Exit Sub]
   [statements]
End Sub
arglist:  [ByVal | ByRef] varname[(…)],[ByVal | ByRef] varname[(…)],…

Argument

PublicOptional keyword that cannot be used together with Private keyword. Keyword used to indicate that the Sub procedure is available to all other procedures in all scripts.DefaultOptional keyword that is used only with the Public keyword in a Class block to indicate that the Sub procedure is the default method for the class. An error occurs if more than one Default procedure is specified in a class.PrivateOptional keyword that cannot be used together with Public keyword. Keyword used to Indicate that the Sub procedure is accessible only to other procedures in the script where it is declared.SubRequired keyword. To indicate the start of Sub.nameRequired. Is used to specify the name of the Sub following the standard variable naming conventions.arglistOptional. To specify the list of variables representing arguments that are passed to the Sub procedure when it is called. Commas separate multiple variables.statementsOptional. Any group of statements to be executed within the body of the Sub procedure.Exit SubOptional. to cause an immediate exit from a Sub procedure. Program execution continues with the statement that follows the statement that called the Sub procedure.End SubRequired. to indicate the end of Sub.ByValOptional, but cannot be used together with ByRef. is used to Indicate that the argument is passed by value.ByRefOptional, but cannot be used together with ByVal. is used to Indicate that the argument is passed by reference. If ByVal and ByRef are omitted, the default is ByRef.varnameRequired. to specify the name of the

Remarks

  • A Sub procedure can be called by using the procedure name followed by the argument list.
  • Like a Function procedure, a Sub procedure is a separate procedure that can take arguments, perform a series of statements, and change the value of its arguments. Unlike a Function procedure, a Sub procedure does not return a value, so it cannot be used in an expression.
  • If not explicitly specified using either Public or Private, Sub procedures are public by default, that is, they are visible to all other procedures in the script. A Sub procedure cannot be defined inside any other procedure, for example, Function or Property Get.
  • In a Sub declaration, each parameter can be specified as ByRef or ByVal. If neither is specified, the default is ByRef. If ByVal is specified, the corresponding argument is always passed by value when the subroutine is called. If ByRef (or neither) is specified, the argument can be passed by reference or by value when the subroutine is called. For more information, see ByRef and ByVal Parameters.
  • Sub procedures can be recursive, that is, they can call themselves to perform a given task. However, recursion can lead to stack overflow.
  • The values of local variables in a Sub procedure are not preserved between calls to the procedure.
  • Variables that are explicitly declared in a procedure (using Dim or the equivalent) are always local to the procedure. Variables that are used but not explicitly declared in a procedure are also local, unless they are explicitly declared at some higher level outside the procedure.
  • If variables are not explicitly declared in a procedure, a naming conflict can occur if anything that have been defined at the script level has a duplicate name. If the procedure refers to an undeclared variable that has the same name as another procedure, constant or variable, it is assumed that the procedure is referring to that script-level name. To avoid this kind of conflict, use an Option Explicit Statement to force explicit declaration of variables.
  • The Exit Sub statement causes an immediate exit from a Sub procedure. Program execution continues with the statement that follows the statement that called the Sub procedure. Any number of Exit Sub statements can appear anywhere in a Sub procedure.

Requirement

1

Examples

Examples of Sub Statement

ASP VbScript Command:
<script runat="server" language="VBScript">
Dim vars,strs,cmda:varx=1
cmda=array("a","b","c")
Dim ucnt,tmp,i:ucnt=UBound(cmda):If var=1 Then:tmp="":Else:tmp="<b>vars</b>":End If:For i=0 to ucnt:tmp=tmp&"<b>"&rmv_ctrl(cmda(i))&", TypeName</b>":Next:Response.Write "Results on Microsoft Windows 8.1 Pro x64, Microsoft-IIS/8.5, VBScript Version 5.8 of page /sideway/default.asp<br />"&"<i>"&tmp&"</i>"
Function dsp_x:Dim tmp_a,tmp_b,i:If varx=0  Then:Execute vars:End If:If var=1 Then:tmp_a="":Else:tmp_a=rmv_ctrl(vars):End If:For i=0 to ucnt:tmp_b=cmd_b(cmda(i)):if i/2=fix(i/2) Then:tmp_b="<b>"&tmp_b&"</b>":End If:tmp_a=tmp_a&tmp_b:Next:Response.Write "<i>"&tmp_a&"</i>":End Function
Function rmv_ctrl(blk_str):Select Case blk_str:Case chr(0):blk_str="NUL":Case chr(1):blk_str="SOH":Case chr(2):blk_str="STX":Case chr(3):blk_str="ETX":Case chr(4):blk_str="EOT":Case chr(5):blk_str="ENQ":Case chr(6):blk_str="ACK":Case chr(7):blk_str="BEL":Case chr(8):blk_str="BS":Case chr(9):blk_str="HT":Case chr(10):blk_str="LF":Case chr(11):blk_str="VT":Case chr(12):blk_str="FF":Case chr(13):blk_str="CR":Case chr(14):blk_str="SO":Case chr(15):blk_str="SI":Case chr(16):blk_str="DLE":Case chr(17):blk_str="DC1":Case chr(18):blk_str="DC2":Case chr(19):blk_str="DC3":Case chr(20):blk_str="DC4":Case chr(21):blk_str="NAK":Case chr(22):blk_str="SYN":Case chr(23):blk_str="ETB":Case chr(24):blk_str="CAN":Case chr(25):blk_str="EM":Case chr(26):blk_str="SUB":Case chr(27):blk_str="ESC":Case chr(28):blk_str="FS":Case chr(29):blk_str="GS":Case chr(30):blk_str="RS":Case chr(31):blk_str="US":Case chr(127):blk_str="DEL":End Select:rmv_ctrl=blk_str:If IsNull(blk_str) OR IsEmpty(Blk_str) OR blk_str="" OR IsNumeric(Blk_str) Then:Else:rmv_ctrl=Replace(Replace(Replace(Replace(Replace(blk_str,"&","&amp;"),"  "," &nbsp;"),"""","&quot;"),"<","&lt;"),">","&gt;"): End If :End Function
Function cmd_b(blk_str):cmd_b="["&cmd_x(blk_str)&"], "&cmd_x("TypeName("&blk_str&")"):End Function
Function cmd_x(blk_str):On Error Resume Next:Dim xans, tmp:xans="":tmp="":execute "xans="&blk_str:If Err.Number <> 0  Then:xans=cmd_x("TypeName("&blk_str&")"):Select Case xans:Case 9::Case Else:xans="error":End Select:End If:If IsArray(xans)=False Then:cmd_x=rmv_ctrl(xans): Else:tmp=lst_arry(xans):cmd_x=trim(tmp):End If:End Function
Function lst_arry(blk_str):Dim tmp,i,q:q="""":tmp="":For i=0 to UBound(blk_str):if VarType(blk_str(i))>1 And VarType(blk_str(i))<6 Then:q="'":End If:tmp=tmp&" "&q&rmv_ctrl(blk_str(i))&q:Next:lst_arry=trim(tmp):End Function

vars="c=0:Sub sumab(a,b):c=a+b:Exit Sub:cc=a:End Sub:a=5:b=7:sumab a,b":Execute vars:sumab 5,7:dsp_x
vars="a=4:b=3:sumab a,b":varx=0:dsp_x
</script>
HTML Web Page In-line Output:
Results on Microsoft Windows 8.1 Pro x64, Microsoft-IIS/8.5, VBScript Version 5.8 of page /sideway/default.asp
varsa, TypeNameb, TypeNamec, TypeNamec=0:Sub sumab(a,b):c=a+b:Exit Sub:cc=a:End Sub:a=5:b=7:sumab a,b[5], Integer[7], Integer[12], Integera=4:b=3:sumab a,b[4], Integer[3], Integer[7], Integer

©sideway

ID: 180400030 Last Updated: 2018/4/30 Revision:

IMAGE

Home (5)

Business

Management

HBR (3)

Information

Recreation

Hobbies (7)

Culture

Chinese (1097)

English (336)

Reference (66)

Computer

Hardware (149)

Software

Application (187)

Digitization (24)

Numeric (19)

Programming

Web (618)new

CSS (SC)

ASP.NET (SC)

HTML

Knowledge Base

Common Color (SC)

Html Entity (Unicode) (SC)

Html 401 Special (SC)

OS (388)new

MS Windows

Windows10 (SC)

.NET Framework (SC)

DeskTop (7)

Knowledge

Mathematics

Formulas (8)

Number Theory (206)

Algebra (20)

Trigonometry (18)

Geometry (18)

Calculus (67)

Complex Analysis (21)

Engineering

Tables (8)

Mechanical

Mechanics (1)

Rigid Bodies

Statics (92)

Dynamics (37)

Fluid (5)

Fluid Kinematics (5)

Control

Process Control (1)

Acoustics (19)

FiniteElement (2)

Biology (1)

Geography (1)


Copyright © 2000-2019 Sideway . All rights reserved Disclaimers last modified on 10 Feb 2019