Sideway BICK BlogSideway BICK BLOG from Sideway

A Sideway to Sideway Home

Link:http://output.to/sideway/default.asp?qno=180400020

Script, Scripting Language, VBScript elements, Server-Side VBScript Operator Arithmetic

VBScript Arithmetic Operators

The arithmetic operators are ^ Operator, * Operator, / Operator, \ Operator, Mod Operator, + Operator, - Operator.

^ Operator

last updated 11/17/2017

Exponentiation operator is used to create a value by raising a number to the power of an exponent.

Syntax

number^exponent

Argument

numberAny numeric expression.exponentAny numeric expression.

Remarks

  • Number can be negative only if exponent is an integer value. When more than one exponentiation is performed in a single expression, the ^ operator is evaluated as it is encountered from left to right.
  • If either number or exponent is a Null expression, result is also Null.

Requirement

1

* Operator

last updated 11/17/2017

Multiplication operator is used to create a value by multiplying two numbers.

Syntax

number1*number2

Argument

number1Any numeric expression.number2Any numeric expression.

Remarks

  • If one or both expressions are Null expressions, result is Null. If an expression is Empty, it is treated as if it were 0.

Requirement

1

/ Operator

last updated 11/17/2017

Division operator is used to create a value by dividing two numbers and obtaining a floating-point result.

Syntax

number1/number2

Argument

number1Any numeric expression.number2Any numeric expression.

Remarks

  • If one or both expressions are Null expressions, result is Null. Any expression that is Empty is treated as 0.

Requirement

1

\ Operator

last updated 11/17/2017

Integer division operator (\) is used to create a value by dividing two numbers and obtaining an integer result.

Syntax

number1\number2

Argument

number1Any numeric expression.number2Any numeric expression.

Remarks

  • The result is the integer quotient of number1 divided by number2. The integer quotient discards any remainder and retains only the integer portion.
  • Before division is performed, numeric expressions are rounded to Byte, Integer, or Long subtype expressions.
  • If any expression is Null, result is also Null. Any expression that is Empty is treated as 0.
  • The Division operator (/) returns the full quotient, retaining the remainder in the fractional portion.The remainder is obtained by Mod Operator.

Requirement

1

Mod Operator

last updated 11/17/2017

Modulus operator is used to create a value by dividing two integers and obtaining the integer remainder.

Syntax

number1 Mod number2

Argument

number1Any numeric expression.number2Any numeric expression.

Remarks

  • If number1 or number2 are floating point numbers, they are first rounded to integers.
  • The Mod (modulus) operator divides number1 by number2 and returns the integer remainder.
  • If any expression is Null, result is also Null. Any expression that is Empty is treated as 0.

Requirement

1

+ Operator

last updated 11/17/2017

Addition operator or plus concatenating operator is used to create a value by summing two numeric expressions or by concatenating two string expressions

Syntax

expression1+expression2

Argument

expression1Any expression.expression2Any expression.

Remarks

  • Although you can also use the + operator to concatenate two character strings, you should use the & operator for concatenation to eliminate ambiguity. When you use the + operator, you may not be able to determine whether addition or string concatenation will occur.
  • The type of the expressions determines the behavior of the + operator. If both expressions are numeric then add. If both expressions are strings then concatenate. If one expression is numeric and the other is a string then type mismatch error.
  • If one or both expressions are Null expressions, result is Null. If both expressions are Empty, result is an Integer subtype. However, if only one expression is Empty, the other expression is returned unchanged as result.

Requirement

1

- Operator

last updated 11/17/2017

Subtraction operator is used to create a value by finding the difference between two numbers or by negating the value of a numeric expression.

Syntax

number1-number2
-number

Argument

numberAny numeric expression.number1Any numeric expression.number2 Any numeric expression.

Remarks

  • In Syntax 1, the - operator is the arithmetic subtraction operator used to find the difference between two numbers. In Syntax 2, the - operator is used as the unary negation operator to indicate the negative value of an expression.
  • If one or both expressions are Null expressions, result is Null. If an expression is Empty, it is treated as if it were 0.

Requirement

1

Examples

Examples of VarType and TypeName functions

ASP VbScript Command:
<script runat="server" language="VBScript">
Dim vars,strs,cmda
cmda=array("a","b","a^b","a*b","a/b","a\b","a Mod b","a+b","a-b","-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 /internet/users/sideblog/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="a=Null:b=3":dsp_x
vars="a=Empty:b=3":dsp_x
vars="a="""":b=3":dsp_x
vars="a=2:b=Null":dsp_x
vars="a=2:b=Empty":dsp_x
vars="a=2:b=""""":dsp_x
vars="a=Null:b=""b""":dsp_x
vars="a=Empty:b=""b""":dsp_x
vars="a="""":b=""b""":dsp_x
vars="a=""a"":b=Null":dsp_x
vars="a=""a"":b=Empty":dsp_x
vars="a=""a"":b=""""":dsp_x
vars="a=Null:b=Null":dsp_x
vars="a=Empty:b=Empty":dsp_x
vars="a="""":b=""""":dsp_x
vars="a=2:b=3":dsp_x
vars="a=2.2:b=3.3":dsp_x
vars="a=4:b=0.5":dsp_x
vars="a=4:b=-0.5":dsp_x
vars="a=4:b=-5":dsp_x
vars="a=-4:b=2":dsp_x
vars="a=-4:b=0.5":dsp_x
vars="a=-4:b=2.5":dsp_x
vars="a=-4:b=-2.5":dsp_x
vars="a=-4:b=-0.5":dsp_x
vars="a=-4:b=-2":dsp_x
vars="a=""-4"":b=""2""":dsp_x
vars="a=""a"":b=""b""":dsp_x
vars="a=""-4"":b=-2":dsp_x
vars="a=""a"":b=-2":dsp_x
vars="a=-4:b=""-2""":dsp_x
vars="a=-4:b=""b""":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 /internet/users/sideblog/default.asp
varsa, TypeNameb, TypeNamea^b, TypeNamea*b, TypeNamea/b, TypeNamea\b, TypeNamea Mod b, TypeNamea+b, TypeNamea-b, TypeName-b, TypeNamea=Null:b=3[], Null[3], Integer[], Null[], Null[], Null[], Null[], Null[], Null[], Null[-3], Integera=Empty:b=3[], Empty[3], Integer[0], Double[0], Integer[0], Single[0], Integer[0], Integer[3], Integer[-3], Integer[-3], Integera="":b=3[], String[3], Integer[error], error[error], error[error], error[error], error[error], error[error], error[error], error[-3], Integera=2:b=Null[2], Integer[], Null[], Null[], Null[], Null[], Null[], Null[], Null[], Null[], Nulla=2:b=Empty[2], Integer[], Empty[1], Double[0], Integer[error], error[error], error[error], error[2], Integer[2], Integer[0], Integera=2:b=""[2], Integer[], String[error], error[error], error[error], error[error], error[error], error[error], error[error], error[error], errora=Null:b="b"[], Null[b], String[], Null[], Null[], Null[], Null[], Null[], Null[], Null[error], errora=Empty:b="b"[], Empty[b], String[error], error[error], error[error], error[error], error[error], error[b], String[error], error[error], errora="":b="b"[], String[b], String[error], error[error], error[error], error[error], error[error], error[b], String[error], error[error], errora="a":b=Null[a], String[], Null[], Null[], Null[], Null[], Null[], Null[], Null[], Null[], Nulla="a":b=Empty[a], String[], Empty[error], error[error], error[error], error[error], error[error], error[a], String[error], error[0], Integera="a":b=""[a], String[], String[error], error[error], error[error], error[error], error[error], error[a], String[error], error[error], errora=Null:b=Null[], Null[], Null[], Null[], Null[], Null[], Null[], Null[], Null[], Null[], Nulla=Empty:b=Empty[], Empty[], Empty[1], Double[0], Integer[error], error[error], error[error], error[0], Integer[0], Integer[0], Integera="":b=""[], String[], String[error], error[error], error[error], error[error], error[error], error[], String[error], error[error], errora=2:b=3[2], Integer[3], Integer[8], Double[6], Integer[0.666666666666667], Double[0], Integer[2], Integer[5], Integer[-1], Integer[-3], Integera=2.2:b=3.3[2.2], Double[3.3], Double[13.4894687605334], Double[7.26], Double[0.666666666666667], Double[0], Long[2], Long[5.5], Double[-1.1], Double[-3.3], Doublea=4:b=0.5[4], Integer[0.5], Double[2], Double[2], Double[8], Double[error], error[error], error[4.5], Double[3.5], Double[-0.5], Doublea=4:b=-0.5[4], Integer[-0.5], Double[0.5], Double[-2], Double[-8], Double[error], error[error], error[3.5], Double[4.5], Double[0.5], Doublea=4:b=-5[4], Integer[-5], Integer[0.0009765625], Double[-20], Integer[-0.8], Double[0], Integer[4], Integer[-1], Integer[9], Integer[5], Integera=-4:b=2[-4], Integer[2], Integer[16], Double[-8], Integer[-2], Double[-2], Integer[0], Integer[-2], Integer[-6], Integer[-2], Integera=-4:b=0.5[-4], Integer[0.5], Double[error], error[-2], Double[-8], Double[error], error[error], error[-3.5], Double[-4.5], Double[-0.5], Doublea=-4:b=2.5[-4], Integer[2.5], Double[error], error[-10], Double[-1.6], Double[-2], Long[0], Long[-1.5], Double[-6.5], Double[-2.5], Doublea=-4:b=-2.5[-4], Integer[-2.5], Double[error], error[10], Double[1.6], Double[2], Long[0], Long[-6.5], Double[-1.5], Double[2.5], Doublea=-4:b=-0.5[-4], Integer[-0.5], Double[error], error[2], Double[8], Double[error], error[error], error[-4.5], Double[-3.5], Double[0.5], Doublea=-4:b=-2[-4], Integer[-2], Integer[0.0625], Double[8], Integer[2], Double[2], Integer[0], Integer[-6], Integer[-2], Integer[2], Integera="-4":b="2"[-4], String[2], String[16], Double[-8], Double[-2], Double[-2], Long[0], Long[-42], String[-6], Double[-2], Doublea="a":b="b"[a], String[b], String[error], error[error], error[error], error[error], error[error], error[ab], String[error], error[error], errora="-4":b=-2[-4], String[-2], Integer[0.0625], Double[8], Double[2], Double[2], Long[0], Long[-6], Double[-2], Double[2], Integera="a":b=-2[a], String[-2], Integer[error], error[error], error[error], error[error], error[error], error[error], error[error], error[2], Integera=-4:b="-2"[-4], Integer[-2], String[0.0625], Double[8], Double[2], Double[2], Long[0], Long[-6], Double[-2], Double[2], Doublea=-4:b="b"[-4], Integer[b], String[error], error[error], error[error], error[error], error[error], error[error], error[error], error[error], error

Sideway BICK Blog

20/04


Copyright © 2000-2020 Sideway . All rights reserved Disclaimerslast modified on 26 January 2013