Candid Smile

Candid Smile
Young and Innocent

Sunday, March 18, 2007

Programming Tips

Wanna post some important programming tips thru here as not to forget.

To Create an xml file from asp using VB scripting. Normal creation

Dim xmlDoc, rootEl, fieldAnswer, att01, p

'Create an xml Document
Set xmlDoc = server.CreateObject("Microsoft.XMLDOM")
xmlDoc.preserveWhiteSpace=true

'Create a root element and append it to the document
Set rootEl = xmlDoc.createElement("Element")
xmlDoc.appendChild rootEl
Set fieldAnswer = xmlDoc.createElement("Root1")
Set att01 = xmlDoc.createAttribute("Attr_ID")
'Set the value of the id attribute equal to the name of the current form field
att01.Text = "Sum Attr"
'Append the id attribute to the field element
fieldAnswer.setAttributeNode att01
'Append the field element as a child of the root element
rootEl.appendChild fieldAnswer
'Insert xml v ersion
Set p = xmlDoc.createProcessingInstruction("xml","version='1.0'")
xmlDoc.insertBefore p,xmlDoc.childNodes(0)

--------------------------------------------------------------------
Generate Unique Key for asp

Function gen_key(digits)

'Create and define array
dim char_array(50)
char_array(0) = "0"
char_array(1) = "1"
char_array(2) = "2"
char_array(3) = "3"
char_array(4) = "4"
char_array(5) = "5"
char_array(6) = "6"
char_array(7) = "7"
char_array(8) = "8"
char_array(9) = "9"
char_array(10) = "A"
char_array(11) = "B"
char_array(12) = "C"
char_array(13) = "D"
char_array(14) = "E"
char_array(15) = "F"
char_array(16) = "G"
char_array(17) = "H"
char_array(18) = "I"
char_array(19) = "J"
char_array(20) = "K"
char_array(21) = "L"
char_array(22) = "M"
char_array(23) = "N"
char_array(24) = "O"
char_array(25) = "P"
char_array(26) = "Q"
char_array(27) = "R"
char_array(28) = "S"
char_array(29) = "T"
char_array(30) = "U"
char_array(31) = "V"
char_array(32) = "W"
char_array(33) = "X"
char_array(34) = "Y"
char_array(35) = "Z"
'Initiate randomize method for default seeding
randomize
'Loop through and create the output based on the the variable passed to
'the function for the length of the key.
do while len(output) < num =" char_array(Int((35" output =" output" gen_key =" output">" & gen_key(10) &amp; "" & vbcrlf
aKey10 = gen_key(10)