This is a collection of usefull little object to use whit Asp and VB/VBScript.
By now, the only available object is a Dictionary.
2.1 The Dictionay object
Class identifier: midori.dict
set ObjDict = createObject("midori.dict")
Why another Dictionary? There isn't already the "Scripting.Dictionary"
from Microsoft?
Yes! But I tryed (in Asp)
Set Application("bubu") = server.CreateObject("Scripting.Dictionary")
and the reply of the IIS 4.0 was:
Improper use of the object.
Cannot assign to intrinsic Application an object with apartement threading
model behavior.
I've to use a dictionary at Application level, and I cant use the "Commerce.Dictionary"
because I don't need MS Commerce Server!
So there is a Dictionary Object that use Single Thread Model, usable within
the application object.
This object has this methods and properties:
add, change/add an entry to the dictionary usinge
the key (method)
remove, remove an entry from the dictionary (method)
exist, control the presence of an entry in the dictionary
(method)
item, get an entry from the dictionary using the
key (method)
data, change/get/add an entry to the dictionary using
the key (default property)
datai, change/get/add an entry to the dictionary
using an index (property)
index, return the index of a entry from his key(property)
count, return the count of object in the dictionary
(property)
key, change/get the key of a entry (property)
purge, clear all the dictionary contents (method)
saveTo, Save the Dictionary to a file(method)
loadFrom, load dictionary contents from a file,
previously stored by saveTo method (method)
2.1.1 add (method)
Sub add(ByVal key As Variant, ByVal data As Variant)
Add or modify an entry of the dictionary. If an entry with the value
Key exist, that entry is modified; else a new entry for the specified
Key/Data is created in the dictionary. If you want to get an item
from the dictionary use the item metod or the data
default property.
The Key should be a String or a Number. But ANY variant type should work;
The data can be any variant Type.
Parameters:
key
|
a VARIANT containing a the ID key, and should be String or number.
This value is used to lookup in the dictionary to get/set the data.
An entry with the same value is found in the dictionary, the corresponding
data is overwritten. Else a new entry for the specified Key/Data is
created in the dictionary. |
data |
a VARIANT containing the data to be stored in the dictionary. Can
contain any Type. |
Example:
set objDict = application("myDictionary")
key = request("access_key")
Value = Request("access_value")
if NOT objDict.exist(key) then
objDict.add(key, Value)
End if
2.1.2 remove (method)
Sub remove(ByVal key As Variant)
Remove an entry from the dictionary. If an entry with the value Key doesn't
exist, the method does nothing. If you want to get an item from
the dictionary use the item metod or the data
default property. If you want to put an item in the dictionary
use the add metod or the data
default property.
Parameters:
key
|
a VARIANT containing a the ID key, and should be String or number.
This value is used to lookup in the dictionary to get/set the data.
An entry with the same value is found in the dictionary, the corresponding
data is overwritten. Else a new entry for the specified Key/Data is
created in the dictionary. |
Example:
set objDict = application("myDictionary")
key = request("access_key")
if objDict.exist(key) then
objDict.remove(key)
End if
2.1.3 exist (method)
Function exist(ByVal key As Variant) As Variant
Return True if an entry with the value Key exist in the Dictionary, else
return False. If you want to get an item from the dictionary use
the item metod or the data default
property.
Parameters:
key
|
a VARIANT containing a the ID key, and should be String or number.
This value is used to lookup in the dictionary to get/set the data.
An entry with the same value is found in the dictionary, the corresponding
data is overwritten. Else a new entry for the specified Key/Data is
created in the dictionary. |
Returned value:
True if the specified key exist in the dictionary. Else False
Example:
set objDict = application("myDictionary")
key = request("access_key")
if objDict.exist(key) then
response.write("<p>"
& objDict.item(key) & "</p>")
End if
2.1.4 item (method)
Function item(ByVal key As Variant) As Variant
Return an entry from the dictionary. If an entry with the value Key exist,
return the associated data; else the method return an Empty value.
If you want to put an item in the dictionary use the add
metod or the data default property.
Parameters:
key
|
a VARIANT containing a the ID key, and should be String or number.
This value is used to lookup in the dictionary to get/set the data.
An entry with the same value is found in the dictionary, the corresponding
data is overwritten. Else a new entry for the specified Key/Data is
created in the dictionary. |
Returned value:
The data if the specified key exist in the dictionary. Else an
Empty value
Example:
set objDict = application("myDictionary")
key = request("access_key")
response.write("<p>" & objDict.item("key")
& "</p>")
2.1.5 data (default property)
myDictionaryObject.data(key) = MyData
MyData = myDictionaryObject.data(key)
This propery represent a rapid way to use the add and item
methods.
myDictionaryObject.data(key) = MyData is equivalent to myDictionaryObject.add(key,
MyData)
and
MyData = myDictionaryObject.data(key) is equivalent to MyData =
myDictionaryObject.item(key)
BUT this is also the Dafault Property,
so to use it just do:
myDictionaryObject(key) = MyData
MyData = myDictionaryObject(key)
If you want to remove an item from the dictionary use the remove
method
Parameters:
key
|
a VARIANT containing a the ID key, and should be String or number.
This value is used to lookup in the dictionary to get/set the data.
An entry with the same value is found in the dictionary, the corresponding
data is overwritten. Else a new entry for the specified Key/Data is
created in the dictionary. |
2.1.6 datai (property)
myDictionaryObject.datai(index) = MyData
MyData = myDictionaryObject.datai(index)
This propery represent the way to add items to the dictionary using an
index and not a key.
In this way, the dictionary works like an array.
Iou can use this property to iterate inside the dictionary.
If you want to put an item in the dictionary usinge keys, use
the add metod or the data default
property.
Parameters:
index
|
a VARIANT containing a 1 based index of the entry to get/modify,
and must be an integer. If you specify a value greather than the entry
count, the property is not modified or an empty value is returned. |
Example:
For i = 1 To myDictionaryObject.Count
Text1 = Text1 & myDictionaryObject.datai(i)
Next
For i = 1 To myDictionaryObject.Count
myDictionaryObject.datai(i) = i *
1024
Next
2.1.7 index (property)
myKey = myDictionaryObject.index(key)
You can use this property to get the internal index of an entry specifing
a key. Can be:
0 , if no entry with key was found
any integer > 0, if a entry with key was found
The property is read only.
Parameters:
key
|
a VARIANT containing a the ID key, and should be String or number.
This value is used to lookup in the dictionary to get/set the data.
An entry with the same value is found in the dictionary, the corresponding
data is overwritten. Else a new entry for the specified Key/Data is
created in the dictionary. |
Example:
myKey = "MrSat"
myIndex = myDictionaryObject.index(myKey)
if myIndex > 0 then
response.Write("the "
& myKey & " index is " & myIndex)
End if
2.1.8 count (property)
You can use this property to get the courrent number of entry in the
dictionary.
The property is read only.
Example:
For i=0 to myDictionaryObject.count
response.Write("item" &
i & " value=" & myDictionaryObject.datai ( i ) )
Next
2.1.9 key (property)
MyKey = myDictionaryObject.key(index)
You can use this property to get or change the key of an entry specifing
the internal index.
Parameters:
index
|
a VARIANT containing a 1 based index of the entry to get/modify,
and must be an integer. If you specify a value greather than the entry
count, the property is not modified or an empty value is returned. |
Example:
if myDictionaryObject.count >0 then
MyOldKey = myDictionaryObject.key
( 12 )
myDictionaryObject.key ( 12 ) = MyNewKey
end if
2.1.10 purge (method)
myDictionaryObject.purge( )
Clear all the dictionary contents. If you want to remove an item
from the dictionary use the remove method.
2.1.11 saveTo (method)
myDictionaryObject.saveTo( FilePath As VARIANT )
Save the dictionary contents to a file, specified in FilePath. Then,
to load the dictionary from a file use the loadFrom
method.
Parameters:
FilePath
|
A VARIANT containing a string; that string represents the path
of the file to store the data. If a file exists, it will be overwritten
and old data will be lost. |
Example:
if myDictionaryObject.count >0 then
myDictionaryObject.saveTo(C:\temp\dict_data.dic")
set myDictionaryObject = Nothing
end if
2.1.12 loadFrom (method)
myDictionaryObject.loadFrom( FilePath As VARIANT )
Load the Dictionary contents from a file, specified in FilePath. If you
want to save the dictionary to a file use the saveTo
method.
The previous dictionary content will be lost when calling this method.
If the data file is not found, the dictionary data will remain untouched.
Parameters:
FilePath
|
A VARIANT containing a string; that string represents the path
of the file containing data to be loaded. Must be a file previously
written by the saveTo metod. Editing that file may damage all data
in ti contained! |
Dim myDictionaryObject
Set myDictionaryObject = Server.CreateObject("midori.dict")
myDictionaryObject.LoadFrom(C:\temp\dict_data.dic")
response.write("Count: " & myDictionaryObject.count &
"<br>")
2.2 The Base64 Object
Class identifier: midori.base64
set objB64 = createObject("midori.base64")
A Base64 String Encoder and Decoder. It is totally compatible with the
RFC822 Base64 description.
This object has that methods:
Base64Encode, encode a string or an array into a
base64 string(method)
Base64Decode, decode a base64 string or array into
into a string containing the original data(method)
Base64EncToArray, encode a string or an array into
a base64 array of bytes(method)
Base64DecToArray, decode a base64 string or array
into an array of bytes containing the original data (method)
2.2.1 Base64Encode (method)
Function base64Encode(inData As Variant) As Variant
Encode the input using the Base64 encoding. The output is a base64 String,
that contains only this chars:
ABCDEFGHIJKLMNOPQRSTUVWXYZ
abcdefghijklmnopqrstuvwxyz0123456789+/
And the special termination char "="
If you want to decode base64 data into a string use Base64Decode.
If you want to decode base64 data into an array of bytes use Base64DecToArray.
Parameters:
inData
|
a VARIANT containing the data to be encoded. Can be a string, an
array of chars, an array of integer values (from 0 to 255, or byte). |
Returned value:
A VARIANT containing a base64 encoded string.
Example:
StrOriginal = "The text!!!"
set objB64 = createObject("midori.base64")
B4String = objB64.Base64Encode(StrOriginal)
StrOriginal2 = objB64.Base64Decode(B4String)
response.write("Original : " & StrOriginal & "<br>"
& "Encoded :" & _
B4String
& "<br>" & "Decoded : " & StrOriginal2
& "<br>" )
2.2.2 Base64Decode(method)
Function base64Decode(base64Data As Variant) As Variant
Decode the input Base 64 data into a string representing the original
data.
If you want to encode data to a base64 string use Base64Encode.
If you want to encode data to a base64 array use Base64EncToArray.
Parameters:
base64Data
|
a VARIANT containing the base64 data to be decoded. Must be a valid
base64 data, or an error will be generated.
Can be a string, an array of chars, an array of integer values (from
0 to 255, or byte). |
Returned value:
A VARIANT containing the decoded, original string.
Example: HTTP BASIC AUTHORIZATION
set objB64 = createObject("midori.base64")
Dim UP, Pos, Auth
Auth = Request.ServerVariables("HTTP_AUTHORIZATION")
LOGON_USER = ""
LOGON_PASSWORD = ""
If LCase(Left(Auth, 5)) = "basic" Then
UP = objB64.Base64Decode(Mid(Auth,
7))
Pos = InStr(UP, ":")
If Pos > 1 Then
LOGON_USER
= Left(UP, Pos - 1)
LOGON_PASSWORD
= Mid(UP, Pos + 1)
End If
End If
2.2.3 Base64EncToArray (method)
Function base64EncToArray (inData As Variant) As Variant
Encode the input data into a base64 array. The input can bee an array
or a string.
If you want to encode data to a base64 string use Base64Encode.
Parameters:
base64Data
|
a VARIANT containing the data to be encoded.
Can be a string, an array of chars, an array of integer values (from
0 to 255, or byte). |
Returned value:
A VARIANT containing an array. This array contain the base64 encoded data.
Example:
StrOriginal = "The text!!!"
set objB64 = createObject("midori.base64")
B4Array = objB64.Base64EncToArray(StrOriginal)
response.bynaryWrite(B4Array)
2.2.4 Base64DecToArray (method)
Function base64DecToArray(base64Data As Variant) As Variant
Decode the input Base 64 data into an array of bytes, containing the
original data.
If you want to decode data to a string use Base64Decode.
Parameters:
base64Data
|
a VARIANT containing the base64 data to be decoded. Must be a valid
base64 data, or an error will be generated.
Can be a string, an array of chars, an array of integer values (from
0 to 255, or byte). |
Returned value:
A VARIANT containing an array. This array represent the original data
decoded.
Example:
B4Array = request.binaryRead( 8 )
set objB64 = createObject("midori.base64")
ArrayOriginalData = objB64.Base64DecToArray(B4Array)
2.3 The Convert Object
Class identifier: midori.convert
set objB64 = createObject("midori.convert")
This object implements method to make "odd" conversions, like
array to string and back.
This object has that methods:
toString, convert an array of char or integer values
to a string (method)
toArray, convert a string to an array of bytes. Or
an array of chars or integer values to an array of bytes (method)
toStringArray, convert a string to an array of chars.
Or an array of integer values to an array of chars (method)
2.3.1 toString (method)
Function toString(inData As Variant) As Variant
Convert:
- an array of integer values
- an array of chars
to a string.
Parameters:
inData
|
a VARIANT containing the data to be converted into a string. Can
an array of chars, an array of integer values (from 0 to 255, or byte),
an array of strings. |
Returned value:
A VARIANT containing a string.
Remarks:
If the input is an array of strings, the method only use the first char
of each string.
Example:
set conv = createObject("midori.convert")
ArrayC = Session("ArrC")
response.write(conv.toString(ArrayC))
2.3.2 toArray (method)
Function toArray(inData As Variant) As Variant
Convert:
- a string
- an array of integer values
- an array of chars
to an array of bytes
Parameters:
inData
|
a VARIANT containing the data to be converted into the array of
bytes. Can be a string, an array of chars, an array of integer values
(from 0 to 255, or byte), an array of strings. |
Returned value:
A VARIANT containing an array of bytes.
Remarks:
If the input is an array of strings, the method only use the first char
of each string.
Example:
set conv = createObject("midori.convert")
strInKLM = request("KLM")
response.binaryWrite(conv.toArray(strInKLM))
2.3.3 toStringArray (method)
Function toStringArray(inData As Variant) As Variant
Convert:
- a string
- an array of integer values
- an array of chars
to an array of chars.
Parameters:
inData
|
a VARIANT containing the data to be converted into the array of
bytes. Can be a string, an array of chars, an array of integer values
(from 0 to 255, or byte), an array of strings. |
Returned value:
A VARIANT containing an array of chars.
Remarks:
If the input is an array of strings, the method only use the first char
of each string.
Midori, Paipai Networks, Jan 2001.
|