Sideway BICK BlogSideway BICK BLOG from Sideway

A Sideway to Sideway Home

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

Script, Scripting Language, VBScript elements, Server-Side VBScript Function, Math Function Hex, Oct, RGB Function

VBScript Math Functions

Functions for manipulating mathematics expression.

Hex Function

last updated 9/19/2017

Create a hexadecimal number String from a given number by converting the decimal value of the given number from base 10 to a hexadecimal number of base 16.

Syntax

Hex(number)

Argument

numberRequired. Any valid numeric expression that is used as the decimal integer.

Returns

Returns a Variant of String data subtype containing a hexadecimal number String obtained from a given number by converting the decimal value of the given number from base 10 to a hexadecimal number of base 16.

Returns of function:

numberreturn valueValid numeric epressionhexadecimal number StringInvalid expressionRun-time error

Special returns of function:

numberreturn valueNullNullEmpty0""Run-time error

Remarks

  • Hex function is used to a decimal integer of base 10 to a hexadecimal number String of base 16.
  • The valid range of number is between -2147483648 and 2147483647 inclusive.
  • The number of hexadecimal digits returned by Hex function is therefore limited. For example, maximum 8 hexadecimal characters.
  • A given number is not a whole number, Hex function will first Round the number before convertion.
  • Hex function always return a hexadecimal number String
  • If a given number contains Null, Hex function returns Null. If a given number contains Empty, Hex function returns hexadecimal character, 0, not integer.
  • But, if a given number contains zero-length string, "", Hex function returns Run-time error.
  • Hexadecimal numbers can also be represented directly by preceding numbers in the proper range with &H or &h. For example, &H10 represents decimal 16 in hexadecimal notation.

Requirement

1

Oct Function

last updated 9/20/2017

Create a octal number String from a given number by converting the decimal value of the given number from base 10 to a octal number of base 8.

Syntax

Oct(number)

Argument

numberRequired. Any valid numeric expression that is used as the decimal integer.

Returns

Returns a Variant of String data subtype containing a octal number String obtained from a given number by converting the decimal value of the given number from base 10 to a octal number of base 8.

Returns of function:

numberreturn valueValid numeric epressionoctal number StringInvalid expressionRun-time error

Special returns of function:

numberreturn valueNullNullEmpty0""Run-time error

Remarks

  • Oct function is used to a decimal integer of base 10 to a octal number String of base 8.
  • The valid range of number is between -2147483648 and 2147483647 inclusive.
  • The number of octal digits returned by Oct function is therefore limited. For example, maximum 11 octal characters.
  • A given number is not a whole number, Oct function will first Round the number before convertion.
  • Oct function always return a octal number String
  • If a given number contains Null, Oct function returns Null. If a given number contains Empty, Oct function returns octal character, 0, not integer.
  • But, if a given number contains zero-length string, "", Oct function returns Run-time error.
  • octal numbers can also be represented directly by preceding numbers in the proper range with &O or &o. For example, &O10 represents decimal 8 in octal notation.

Requirement

1

Examples

Examples of Hex and Oct functions

ASP VbScript Command:
<script runat="server" language="VBScript">
Dim vars,strs,cmda
cmda=array("strs","Hex(strs)","Oct(strs)")
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="strs=Null":dsp_x
vars="strs=Empty":dsp_x
vars="strs=""""":dsp_x
vars="strs=0":dsp_x
vars="strs=32":dsp_x
vars="strs=55":dsp_x
vars="strs=125":dsp_x
vars="strs=126":dsp_x
vars="strs=127":dsp_x
vars="strs=-2147483649":dsp_x
vars="strs=-2147483648":dsp_x
vars="strs=2147483648":dsp_x
vars="strs=2147483647":dsp_x
vars="strs=-2147483647":dsp_x
vars="strs=268435455":dsp_x
vars="strs=-268435455":dsp_x
vars="strs=127":dsp_x
vars="strs=-127":dsp_x
vars="strs=1.4":dsp_x
vars="strs=1.5":dsp_x
vars="strs=1.6":dsp_x
vars="strs=2.4":dsp_x
vars="strs=2.5":dsp_x
vars="strs=2.6":dsp_x
vars="strs=-1.4":dsp_x
vars="strs=-1.5":dsp_x
vars="strs=-1.6":dsp_x
vars="strs=-2.4":dsp_x
vars="strs=-2.5":dsp_x
vars="strs=-2.6":dsp_x
vars="strs=-2047":dsp_x
vars="strs=-4095":dsp_x
vars="strs=&H10":dsp_x
vars="strs=&H127":dsp_x
vars="strs=&HFFFF":dsp_x
vars="strs=&h10":dsp_x
vars="strs=&h127":dsp_x
vars="strs=&hFFFF":dsp_x
vars="strs=&O10":dsp_x
vars="strs=&O127":dsp_x
vars="strs=&O3777":dsp_x
vars="strs=&O7777":dsp_x
vars="strs=&O170001":dsp_x
vars="strs=&O174001":dsp_x
vars="strs=&o10":dsp_x
vars="strs=&o127":dsp_x
vars="strs=&o3777":dsp_x
vars="strs=&o7777":dsp_x
vars="strs=&o170001":dsp_x
vars="strs=&o174001":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
varsstrs, TypeNameHex(strs), TypeNameOct(strs), TypeNamestrs=Null[], Null[], Null[], Nullstrs=Empty[], Empty[0], String[0], Stringstrs=""[], String[error], error[error], errorstrs=0[0], Integer[0], String[0], Stringstrs=32[32], Integer[20], String[40], Stringstrs=55[55], Integer[37], String[67], Stringstrs=125[125], Integer[7D], String[175], Stringstrs=126[126], Integer[7E], String[176], Stringstrs=127[127], Integer[7F], String[177], Stringstrs=-2147483649[-2147483649], Double[error], error[error], errorstrs=-2147483648[-2147483648], Double[80000000], String[20000000000], Stringstrs=2147483648[2147483648], Double[error], error[error], errorstrs=2147483647[2147483647], Long[7FFFFFFF], String[17777777777], Stringstrs=-2147483647[-2147483647], Long[80000001], String[20000000001], Stringstrs=268435455[268435455], Long[FFFFFFF], String[1777777777], Stringstrs=-268435455[-268435455], Long[F0000001], String[36000000001], Stringstrs=127[127], Integer[7F], String[177], Stringstrs=-127[-127], Integer[FF81], String[177601], Stringstrs=1.4[1.4], Double[1], String[1], Stringstrs=1.5[1.5], Double[2], String[2], Stringstrs=1.6[1.6], Double[2], String[2], Stringstrs=2.4[2.4], Double[2], String[2], Stringstrs=2.5[2.5], Double[2], String[2], Stringstrs=2.6[2.6], Double[3], String[3], Stringstrs=-1.4[-1.4], Double[FFFFFFFF], String[37777777777], Stringstrs=-1.5[-1.5], Double[FFFFFFFE], String[37777777776], Stringstrs=-1.6[-1.6], Double[FFFFFFFE], String[37777777776], Stringstrs=-2.4[-2.4], Double[FFFFFFFE], String[37777777776], Stringstrs=-2.5[-2.5], Double[FFFFFFFE], String[37777777776], Stringstrs=-2.6[-2.6], Double[FFFFFFFD], String[37777777775], Stringstrs=-2047[-2047], Integer[F801], String[174001], Stringstrs=-4095[-4095], Integer[F001], String[170001], Stringstrs=&H10[16], Integer[10], String[20], Stringstrs=&H127[295], Integer[127], String[447], Stringstrs=&HFFFF[-1], Integer[FFFF], String[177777], Stringstrs=&h10[16], Integer[10], String[20], Stringstrs=&h127[295], Integer[127], String[447], Stringstrs=&hFFFF[-1], Integer[FFFF], String[177777], Stringstrs=&O10[8], Integer[8], String[10], Stringstrs=&O127[87], Integer[57], String[127], Stringstrs=&O3777[2047], Integer[7FF], String[3777], Stringstrs=&O7777[4095], Integer[FFF], String[7777], Stringstrs=&O170001[-4095], Integer[F001], String[170001], Stringstrs=&O174001[-2047], Integer[F801], String[174001], Stringstrs=&o10[8], Integer[8], String[10], Stringstrs=&o127[87], Integer[57], String[127], Stringstrs=&o3777[2047], Integer[7FF], String[3777], Stringstrs=&o7777[4095], Integer[FFF], String[7777], Stringstrs=&o170001[-4095], Integer[F001], String[170001], Stringstrs=&o174001[-2047], Integer[F801], String[174001], String

RGB Function

last updated 9/21/2017

Create a whole number from the given red, green, and blue argument according to the RGB color converting rule.

Syntax

RGB(red, green, blue)

Argument

redRequired. Any valid numberic expression that is used as the red component of the color by bounding the numeric value in the range between 0 and 255 inclusive.GreenRequired. Any valid numberic expression that is used as the green component of the color by bounding the numeric value in the range between 0 and 255 inclusive.blueRequired. Any valid numberic expression that is used as the blue component of the color by bounding the numeric value in the range between 0 and 255 inclusive.

Returns

Returns a Variant of Long data subtype containing the whole number obtained from the given red, green, and blue argument according to the RGB color converting rule.

Remarks

  • RGB function is used to create a number from the given red, green, and blue argument according to the RGB color converting rule.
  • The valid range of red, green, and blue arguments of RGB function is between 0 and 255 inclusive.
  • The values of red, green, and blue arguments of RGB function that greater and equal to 255 are assumed to be 255 before evaluation.
  • In other words, the return value of RGB function is between 0 and 16777215.
  • The arguments of RGB function is the decimal byte value of a base 16 number. Red argument contains the decimal value of the low-order byte, Blue argument contains the decimal value of the middle byte, and Green argument contains the decimal value of the high-order byte.
  • Return value can be used for application methods and properties that accept a color specification expect that specification to be a number representing an RGB color value. An RGB color value specifies the relative intensity of red, green, and blue to cause a specific color to be displayed.
  • For applications that require the byte order to be reversed, reversed RGB= CLng(blue + (green * 256) + (red * 65536))

Requirement

2

Examples

Examples of RGB function

ASP VbScript Command:
<script runat="server" language="VBScript">
Dim vars,strs,cmda
cmda=array("strs1","strs2","strs3","RGB(strs1,strs2,strs3)")
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="strs1=Null":dsp_x
vars="strs1=Empty":dsp_x
vars="strs1=""""":dsp_x
vars="strs1=0:strs2=0:strs3=0":dsp_x
vars="strs1=1:strs2=0:strs3=0":dsp_x
vars="strs1=1.4:strs2=0:strs3=0":dsp_x
vars="strs1=1.5:strs2=0:strs3=0":dsp_x
vars="strs1=1.6:strs2=0:strs3=0":dsp_x
vars="strs1=2.4:strs2=0:strs3=0":dsp_x
vars="strs1=2.5:strs2=0:strs3=0":dsp_x
vars="strs1=2.6:strs2=0:strs3=0":dsp_x
vars="strs1=0:strs2=1:strs3=0":dsp_x
vars="strs1=0:strs2=0:strs3=1":dsp_x
vars="strs1=255:strs2=0:strs3=0":dsp_x
vars="strs1=0:strs2=255:strs3=0":dsp_x
vars="strs1=0:strs2=0:strs3=255":dsp_x
vars="strs1=255:strs2=255:strs3=255":dsp_x
vars="strs1=1:strs2=1:strs3=1":dsp_x
vars="strs1=254.5:strs2=254.5:strs3=254.5":dsp_x
vars="strs1=255.5:strs2=255.5:strs3=255.5":dsp_x
vars="strs1=256:strs2=256:strs3=256":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
varsstrs1, TypeNamestrs2, TypeNamestrs3, TypeNameRGB(strs1,strs2,strs3), TypeNamestrs1=Null[], Null[], Empty[], Empty[error], errorstrs1=Empty[], Empty[], Empty[], Empty[0], Longstrs1=""[], String[], Empty[], Empty[error], errorstrs1=0:strs2=0:strs3=0[0], Integer[0], Integer[0], Integer[0], Longstrs1=1:strs2=0:strs3=0[1], Integer[0], Integer[0], Integer[1], Longstrs1=1.4:strs2=0:strs3=0[1.4], Double[0], Integer[0], Integer[1], Longstrs1=1.5:strs2=0:strs3=0[1.5], Double[0], Integer[0], Integer[2], Longstrs1=1.6:strs2=0:strs3=0[1.6], Double[0], Integer[0], Integer[2], Longstrs1=2.4:strs2=0:strs3=0[2.4], Double[0], Integer[0], Integer[2], Longstrs1=2.5:strs2=0:strs3=0[2.5], Double[0], Integer[0], Integer[2], Longstrs1=2.6:strs2=0:strs3=0[2.6], Double[0], Integer[0], Integer[3], Longstrs1=0:strs2=1:strs3=0[0], Integer[1], Integer[0], Integer[256], Longstrs1=0:strs2=0:strs3=1[0], Integer[0], Integer[1], Integer[65536], Longstrs1=255:strs2=0:strs3=0[255], Integer[0], Integer[0], Integer[255], Longstrs1=0:strs2=255:strs3=0[0], Integer[255], Integer[0], Integer[65280], Longstrs1=0:strs2=0:strs3=255[0], Integer[0], Integer[255], Integer[16711680], Longstrs1=255:strs2=255:strs3=255[255], Integer[255], Integer[255], Integer[16777215], Longstrs1=1:strs2=1:strs3=1[1], Integer[1], Integer[1], Integer[65793], Longstrs1=254.5:strs2=254.5:strs3=254.5[254.5], Double[254.5], Double[254.5], Double[16711422], Longstrs1=255.5:strs2=255.5:strs3=255.5[255.5], Double[255.5], Double[255.5], Double[16777215], Longstrs1=256:strs2=256:strs3=256[256], Integer[256], Integer[256], Integer[16777215], Long

Sideway BICK Blog

02/04


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