Link:http://output.to/sideway/default.asp?qno=180400003 Script, Scripting Language, VBScript elements, Server-Side VBScript Function VarType, TypeName Function
VBScript Data Type Functions
Functions for manipulating data type of expression.
VarType Functionlast updated 9/21/2017Create an Integer from a given varname to indicate the subtype of a variable.
SyntaxVarType(varname) ArgumentvarnameRequired. Any valid variable or expression.ReturnsReturns a Variant of Integer data subtype containing a number obtained from a given varname to indicate the subtype of a variable. Return values of VarType functions ConstantReturn ValueDescriptionvbEmpty0Empty (uninitialized)vbNull1Null (no valid data)vbInteger2IntegervbLong3Long integervbSingle4Single-precision floating-point numbervbDouble5Double-precision floating-point numbervbCurrency6CurrencyvbDate7DatevbString8StringvbObject9Automation objectvbError10ErrorvbBoolean11BooleanvbVariant12Variant (used only with arrays of Variants)vbDataObject13A data-access objectvbByte17BytevbArray8192Array Special returns of function: varnamereturn valueNull1Empty0""8 Remarks- The VarType function never returns the value, 8192, for Array by itself. Some other value are added to indicate a particular type of array. In other words, VarType function returns the value for an Array of type Variant after additional value for indicating a particular type of argument has been added to the value returned from VarTyper function for Variant. For example, the value returned for an Array of type Variant is calculated as 8192+12, or 8204.
- If an object has a default property, VarType function of an object returns the type of its default property.
Requirement1 TypeName Functionlast updated 9/21/2017Create a String from a given varname to indicate the Variant subtype name of a variable.
SyntaxTypeName(varname) ArgumentvarnameRequired. Any valid variable or expression.ReturnsReturns a Variant of String data subtype containing a String obtained from a given varname to indicate the Variant subtype name of a variable. Return values of TypeName functions Return valueDescriptionByteByte value.IntegerInteger value.LongLong integer value.SingleSingle-precision floating-point value.DoubleDouble-precision floating-point value.CurrencyCurrency value.DecimalDecimal value.DateDate or time value.StringCharacter string value.BooleanBoolean value; True or False.EmptyUninitialized.NullNo valid data.<object type>Actual type name of an object.ObjectGeneric object.UnknownUnknown object type.NothingObject variable that doesn't yet refer to an object instance.ErrorError. Special returns of function: varnamereturn valueNullNullEmptyEmpty""String Remarks- The TypeName function never returns the typename for Array, a generic Variant() is always returned without indicating the type of Array.
- The TypeName function for object returns the actual type name of an object.
Requirement2 ExamplesExamples of VarType and TypeName functions ASP VbScript Command:<script runat="server" language="VBScript">
Dim vars,strs,cmda
cmda=array("strs","VarType(strs)","TypeName(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,"&","&")," "," "),"""","""),"<","<"),">",">"): 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=Empty":dsp_x
vars="strs=Null":dsp_x
vars="strs=1":dsp_x
vars="strs=14444444":dsp_x
vars="strs=CSng(1.401298E-45)":dsp_x
vars="strs=1E100":dsp_x
vars="strs=CCur(1)":dsp_x
vars="strs=Now":dsp_x
vars="strs =""a""":dsp_x
vars="Set strs = ObjectContext":dsp_x
vars="set strs=Server.GetLastError()":dsp_x
vars="strs=True":dsp_x
vars="strs=split(""a b"")":dsp_x
vars="strs=CByte(1)":dsp_x
vars="strs=array(1,2)":dsp_x
'vars="Set strs = CreateObject(""DAO.DBEngine"")":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, TypeNameVarType(strs), TypeNameTypeName(strs), TypeNamestrs=Empty[], Empty[0], Integer[Empty], Stringstrs=Null[], Null[1], Integer[Null], Stringstrs=1[1], Integer[2], Integer[Integer], Stringstrs=14444444[14444444], Long[3], Integer[Long], Stringstrs=CSng(1.401298E-45)[1.401298E-45], Single[4], Integer[Single], Stringstrs=1E100[1E+100], Double[5], Integer[Double], Stringstrs=CCur(1)[1], Currency[6], Integer[Currency], Stringstrs=Now[3/27/2019 9:27:43 AM], Date[7], Integer[Date], Stringstrs ="a"[a], String[8], Integer[String], StringSet strs = ObjectContext[IASPObjectContext], IASPObjectContext[9], Integer[IASPObjectContext], Stringset strs=Server.GetLastError()[IASPError], IASPError[9], Integer[IASPError], Stringstrs=True[True], Boolean[11], Integer[Boolean], Stringstrs=split("a b")["a" "b"], Variant()[8204], Integer[Variant()], Stringstrs=CByte(1)[1], Byte[17], Integer[Byte], Stringstrs=array(1,2)['1' '2'], Variant()[8204], Integer[Variant()], String
|
|