Sideway
output.to from Sideway





Draft for Information Only

VBScript Dictionary Object

Dictionary Object is a simple build-in VBScript Object for storing data as a set of key and item pairs in form of an Object.

Dictionary Object

last updated 2017/12/9

is to provide simple key and item paired data storage.

Syntax

Set dictobjvar = CreateObject("Scripting.Dictionary")

Remarks

  • is a build-in Object for storing data as a set of key and item pairs and a new instance of Object reference is assigned by Set statement.
  • A Dictionary object is the equivalent of a PERL associative array
  • Items can be any form of data, and are stored in the array.
  • Each item is associated with a unique key.|The key is used to retrieve an individual item and is usually an integer or a string, but can be anything except an array.

Dictionary Methods

last updated 2017/12/9

Six Methods are predefined for the Dictionary Object, namely, Add Method, Exists Method, Items Method, Keys Method, Remove Method, and RemoveAll Method. The Add Method is a specific Method for Dictionary Object only. Dot notation is used to access the available Method for a Dictionary Object, for example, dictionaryobjectvariable.methodname.

Syntax

dictobjvar.Add (key, item)
objvar.Exists(key)
objvar.Items()
objvar.Keys()
objvar.Remove(key)
objvar.RemoveAll()

Dictionary Properties

last updated 2017/12/9

Four Properties are predefined for the Dictionary Object, namely, Count Property, Item Property, Key Property, CompareMode Propety. Dot notation is used to access the available Property for a Dictionary Object, for example, dictionaryobjectvariable.propertyname.

Syntax

objvar.Count
objvar.Item(key)[ = itemnew]
objvar.Key(key) = keynew
objvar.CompareMode[ = comparenew]

Examples

Examples of Dictionary Object

ASP VbScript Command:
<script runat="server" language="VBScript">
Dim vars,strs,cmda:varx=0
cmda=array("Eval(f)","d.Keys","d.Items","d.Count")
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="Set d = CreateObject(""Scripting.Dictionary""): f=""d.CompareMode""":dsp_x
vars="d.Add ""11"",""62""":dsp_x
vars="On Error Resume Next:d.Add 11,""22"":d.Add 11,1:f=Err.Number:Err.Clear":dsp_x
vars="f=""d.Add 11,1""":dsp_x
vars="d.Remove(11):f=""d.Exists(11)""":dsp_x
vars="On Error Resume Next:d.Add 11,""32"":d.CompareMode=1:f=Err.Number":dsp_x
vars="d.Item(11)=""42"":f=""d.CompareMode""":dsp_x
vars="d.Item(12)=""42"":f=""d.Item(11)""":dsp_x
vars="d.Item(13)=32:f=""d.Item(12)""":dsp_x
vars="d.Key(13)=15:f=""d.Item(14)""":dsp_x
vars="On Error Resume Next:d.Key(13)=15:f=Err.Number:Err.Clear":dsp_x
vars="On Error Resume Next:d.Key(13)=16:f=Err.Number:Err.Clear":dsp_x
vars="d.RemoveAll:d.CompareMode=1: f=""d.CompareMode""":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
varsEval(f), TypeNamed.Keys, TypeNamed.Items, TypeNamed.Count, TypeNameSet d = CreateObject("Scripting.Dictionary"): f="d.CompareMode"[0], Long[], Variant()[], Variant()[0], Longd.Add "11","62"[0], Long["11"], Variant()["62"], Variant()[1], LongOn Error Resume Next:d.Add 11,"22":d.Add 11,1:f=Err.Number:Err.Clear[457], Long["11" '11'], Variant()["62" "22"], Variant()[2], Longf="d.Add 11,1"[error], error["11" '11'], Variant()["62" "22"], Variant()[2], Longd.Remove(11):f="d.Exists(11)"[False], Boolean["11"], Variant()["62"], Variant()[1], LongOn Error Resume Next:d.Add 11,"32":d.CompareMode=1:f=Err.Number[5], Long["11" '11'], Variant()["62" "32"], Variant()[2], Longd.Item(11)="42":f="d.CompareMode"[0], Long["11" '11'], Variant()["62" "42"], Variant()[2], Longd.Item(12)="42":f="d.Item(11)"[42], String["11" '11' '12'], Variant()["62" "42" "42"], Variant()[3], Longd.Item(13)=32:f="d.Item(12)"[42], String["11" '11' '12' '13'], Variant()["62" "42" "42" '32'], Variant()[4], Longd.Key(13)=15:f="d.Item(14)"[], Empty["11" '11' '12' '15' '14'], Variant()["62" "42" "42" '32' ''], Variant()[5], LongOn Error Resume Next:d.Key(13)=15:f=Err.Number:Err.Clear[32811], Long["11" '11' '12' '15' '14'], Variant()["62" "42" "42" '32' ''], Variant()[5], LongOn Error Resume Next:d.Key(13)=16:f=Err.Number:Err.Clear[32811], Long["11" '11' '12' '15' '14'], Variant()["62" "42" "42" '32' ''], Variant()[5], Longd.RemoveAll:d.CompareMode=1: f="d.CompareMode"[1], Long[], Variant()[], Variant()[0], Long

┬ęsideway

ID: 180500008 Last Updated: 2018/5/8 Revision:

IMAGE

Home (1)

Business

Management

HBR (3)

Information

Recreation

Hobbies (7)

Culture

Chinese (1097)

English (334)new

Reference (60)

Computer

Hardware (148)

Software

Application (187)

Digitization (24)

Numeric (19)

Programming

Web (533)

HTML

Knowledge Base

Common Color (1)

Html Entity (Unicode) (1)

Html 401 Special (1)

OS (366)

MS Windows

Windows10 (1)

DeskTop (5)

Knowledge

Mathematics

Formulas (8)

Number Theory (128)new

Algebra (14)

Trigonometry (18)

Geometry (18)

Calculus (66)

Engineering

Tables (8)

Mechanical

Control

Process Control (1)

Mechanics (1)

Rigid Bodies

Statics & Dynamics (128)

Fluid (5)

Fluid Kinematics (5)

Acoustics (19)

FiniteElement (2)

Biology (1)

Geography (1)


facebook
Latest Updated Links

Copyright © 2000-2018 Sideway . All rights reserved Disclaimersfacebook last modified on 08 Mar 2018