Sideway
output.to from Sideway
Draft for Information Only

Content

VBScript Conditional Block Statement
 If…Then…Else Statement
  Syntax
  Argument
  Remark
  Version
 Examples
 Select Case Statement
  Syntax
  Argument
  Remark
  Version
 Examples

VBScript Conditional Block Statement

The conditional block statements are .

If…Then…Else Statement

last updated 22 Nov 2017

to conditionally execute a group of statements according to the condition expression.

Syntax

If condition Then
   [statements]
[ElseIf condition-n Then
   [elseifstatements]]…
[Else
   [elsestatements]]
End If
If condition Then statements [Else elsestatements ]

Argument

IfRequired keyword. to indicate the start of If…Then…Else Statement.conditionRequired. to specify the If conditional expression.ThenRequired keyword. to indicate the end of condition expression and the . statementsOptional. to specify the statement block containing one or more statements for execution if condition is True.ElseIfOptional statement keyword. to specify the start of another If conditional block. Multiple ElseIf statement blocks are allowed.condition-nOptional, required if ElseIf keyword is specified. to specify the ElseIf conditional expressionelseifstatementsOptional, required if ElseIf keyword is specified. to specify the statement block containing one or more statements for execution if condition-n is True.ElseOptional statement keyword. to specify the start of Else block.elsestatementsOptional, required if Else keyword is specified. to specify the statement block containing one or more statements for execution if all conditional expression is False.End IfRequired for block type If…Then…Else Statement. to indicate the end of If…Then…Else Statement block.

Remark

  • There are two types of conditional expressions. A numeric or string expression that evaluates to True or False. If condition is Null, condition is treated as False.
  • An expression of the form TypeOf objectname Is objecttype. The objectname is any object reference and objecttype is any valid object type. The expression is True if objectname is of the object type specified by objecttype; otherwise it is False.
  • There are two types of If…Then…Else Statements, block syntax and single-line syntax. The single-line syntax can be used for short, simple tests. However, the block syntax provides more structure and flexibility than the single-line form and is usually easier to read, maintain, and debug.
  • For block syntax, when a block If is executed, condition is tested. If condition is True, the statements following Then are executed. If condition is False, each ElseIf (if any) is evaluated in turn. When a True condition is found, the statements following the associated ElseIf are executed. If none of the ElseIf statements are True (or there are no ElseIf clauses), the statements following Else are executed. After executing the statements following Then or Else, execution continues with the statement following End If.
  • The Else and ElseIf clauses are both optional. ElseIf statements can be added as many as needed in a block If, but ElseIf statement must be first statement on the line, and none can appear after the Else clause. Block If statements can be nested; that is, contained within one another.
  • A block If statement must be the first statement on a line. The block If must end with an End If statement.
  • For single-line syntax, what follows the Then keyword is examined to determine whether a statement is a single-line If. If anything other than a comment appears after Then on the same line, the statement is treated as a single-line If statement. When using the single-line syntax, multiple statements are executed as the result of an If...Then decision, but they must all be on the same line and separated by colons.

Version

1

Examples

Examples of If…Then…Else Statement

ASP VbScript Command:
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
    <head>
<script runat="server" language="VBScript">
Function printdata
cmda=array("a"): ucnt =UBound(cmda) : call heading
vars="a=1:If a > 0 Then : a = 10 : End If":dsp_x
vars="a=1:If a > 0 Then a = 10":dsp_x
vars="a=1:If a > 3 Then : a = 2 : Else a = 5 : End If":dsp_x
vars="a=1:If a > 3 Then : a = 2 : Else If a = 1 Then : a = 7 : Else a = 9 : End If : End If":dsp_x
End Function
Dim abb,cnt,cmda,cmp,dai,dlt,dte,dad,e,fnd,flg,fir,f_dw,gbd,hor,i,ild,k,mth,min,num,pnn,pi,sec,str1,str2,str,strs,tme,tmp,ucnt,var,vars,varx,wkd,x,z:varx=0
Function heading: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 Server 2008 R2 Standard  x64, Microsoft-IIS/7.5, VB Version 14.0<br />"&"<i>"&tmp&"</i>":End Function
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
</script>
        <title>Sample Page</title>
        <meta http-equiv="Content-Type" content="text/html;charset=utf-8"> 
        <style type="text/css">
           i {display:table-row}
           u,b {display: table-cell}
        </style>
    </head>
    <body>
<%call printdata %>
    </body>
</html>
HTML Web Page Embedded Output:

Select Case Statement

last updated 24 Nov 2017

to execute one of several groups of statements, depending on the value of a testexpression.

Syntax

Select Case testexpression
   [Case expressionlist-n
      [statements-n]]…
   [Case Else
      [elsestatements-n]]
End Select

Argument

Select CaseRequired keyword. to indicate the start of Select Case.testexpressionRequired. Any numeric or string expression used as the case value selector.CaseOptional keyword. to indicate a selected Case block.expressionlist-nOptional, but required if Case appears. A comma delimited list of one or more expressions as the case matching values. statements-nOptional. One or more statements executed if testexpression matches any part of expressionlist-n.Case ElseOptional keyword. to indicate a selected Case Else block.elsestatements-nOptional. One or more statements executed if testexpression doesn't match any of the Case clauses.End SelectRequired keyword. to indicate the end of Select Case.

Remark

  • If testexpression matches any Case expressionlist expression, the statements following that Case clause are executed up to the next Case clause, or for the last clause, up to End Select. Control then passes to the statement following End Select. If testexpression matches an expressionlist expression in more than one Case clause, only the statements following the first match are executed.
  • The Case Else clause is used to indicate the elsestatements to be executed if no match is found between the testexpression and an expressionlist in any of the other Case selections. Although not required, it is a good idea to have a Case Else statement in your Select Case block to handle unforeseen testexpression values. If no Case expressionlist matches testexpression and there is no Case Else statement, execution continues at the statement following End Select.
  • Select Case statements can be nested. Each nested Select Case statement must have a matching End Select statement.

Version

1

Examples

Examples of Select Case Statement

ASP VbScript Command:
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
    <head>
 <script runat="server" language="VBScript">
Function printdata
cmda=array("a"): ucnt =UBound(cmda) : call heading
vars="b=5:Select Case b:Case 1 a=1:Case Else a=5:End select":dsp_x
vars="b=1:Select Case b:Case 1 a=1:Case Else a=5:End select":dsp_x
End Function
Dim abb,cnt,cmda,cmp,dai,dlt,dte,dad,e,fnd,flg,fir,f_dw,gbd,hor,i,ild,k,mth,min,num,pnn,pi,sec,str1,str2,str,strs,tme,tmp,ucnt,var,vars,varx,wkd,x,z:varx=0
Function heading: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 Server 2008 R2 Standard  x64, Microsoft-IIS/7.5, VB Version 14.0<br />"&"<i>"&tmp&"</i>":End Function
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
</script>
        <title>Sample Page</title>
        <meta http-equiv="Content-Type" content="text/html;charset=utf-8"> 
        <style type="text/css">
           i {display:table-row}
           u,b {display: table-cell}
        </style>
    </head>
    <body>
<%call printdata %>
    </body>
</html>
HTML Web Page Embedded Output:

©sideway

ID: 180400029 Last Updated: 4/29/2018 Revision: 0


Latest Updated LinksValid XHTML 1.0 Transitional Valid CSS!Nu Html Checker Firefox53 Chromena IExplorerna
IMAGE

Home 5

Business

Management

HBR 3

Information

Recreation

Hobbies 8

Culture

Chinese 1097

English 339

Reference 79

Computer

Hardware 249

Software

Application 213

Digitization 32

Latex 52

Manim 205

KB 1

Numeric 19

Programming

Web 289

Unicode 504

HTML 66

CSS 65

SVG 46

ASP.NET 270

OS 429

DeskTop 7

Python 72

Knowledge

Mathematics

Formulas 8

Algebra 84

Number Theory 206

Trigonometry 31

Geometry 34

Coordinate Geometry 2

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

Natural Sciences

Matter 1

Electric 27

Biology 1

Geography 1


Copyright © 2000-2024 Sideway . All rights reserved Disclaimers last modified on 06 September 2019