Wednesday, January 27, 2010

Writing a VBScript

'-------------------------
'Functions
'-------------------------
Function WriteRecordSet(aRecordSet,aFile)
Dim lRecordsetString
Dim lngFieldsIndex
Dim lngIndex
Dim lFieldValue
lRecordsetString = ""
lngFieldsIndex= aRecordSet.RecordCount - 1
For lngIndex = 0 to lngFieldsIndex
if lngIndex = 0 then
lRecordsetString = Cstr(aRecordSet.Fields(lngIndex).Name)
else
lRecordsetString = lRecordsetString & "" & Cstr(aRecordSet.Fields(lngIndex).Name)
end if
Next
aFile.WriteLine(lRecordsetString)
lRecordsetString = ""
aRecordSet.MoveFirst
Do While (Not aRecordSet.EOF)
For lngIndex = 0 to lngFieldsIndex
if (aRecordSet(lngIndex).Value = null) Then
lFieldValue = "DBNull"
else
lFieldValue = Cstr(aRecordSet(lngIndex).Value)
end if
if lngIndex = 0 then
lRecordsetString = lFieldValue
else
lRecordsetString = lRecordsetString & "" & lFieldValue
end if
Next
aFile.WriteLine(lRecordsetString)
aRecordSet.MoveNext
Loop
aRecordSet.MoveFirst
End Function

Function WriteArrayOfArray(aArrayOfArray,aFile)
Dim strArray
Dim lngUBound1
Dim lngUBound2
Dim lngIndex1
Dim lngIndex2
lngUBound1 = UBound(aArrayOfArray, 1)
lngUBound2 = UBound(aArrayOfArray, 2)
For lngIndex1 = 0 To lngUBound1
For lngIndex2 = 0 To lngUBound2
strArray = strArray + "[" & lngIndex1 & "," & lngIndex2 & "] = " & aArrayOfArray(lngIndex1, lngIndex2) & vbcrlf
Next
Next
aFile.WriteLine(strArray)
End Function

'-------------------------
'Start of your VB script
'-------------------------
Dim myFSO
Dim myFile
Set myFSO = CreateObject("Scripting.FileSystemObject")
Set myFile= myFSO.OpenTextFile("PadbVBScript.txt", 8, True)

Dim lPADBObject
set lPADBObject = CreateObject("IWebClientServ16.Profile","GMOBOSCRPAPP01R")
lPADBObject.setSqlServer = "GMOBOSCRPSQLR"
lPADBObject.formatOutput = True

Dim lRecordset
set lRecordset = CreateObject("ADODB.Recordset")
Dim lvRet
Dim lArray

set lRecordset = lPADBObject.getBenchmark(4004, "GMOBOSCRPSQLR")
myFile.WriteLine("<<>>")
WriteRecordSet lRecordset,myFile
myFile.WriteLine()

lvRet = lPADBObject.GetCountryWeights(1022,"8/31/2009","GMOBOSCRPSQLR",15,True)
myFile.WriteLine("<<>>")
WriteArrayOfArray lvRet,myFile
myFile.WriteLine()

lvRet = lPADBObject.GetChar(4002,"8/31/2009","GMOBOSCRPSQLR",,Array(4006),1)
lvRet = lPADBObject.toBaseCurrency(4002,"8/31/2009",lvRet,"GMOBOSCRPSQLR",True)
myFile.WriteLine("<<>>")
WriteArrayOfArray lvRet,myFile
myFile.WriteLine()

myFile.Close
set myFile = nothing
set myFSO = nothing
set lPADBObject = Nothing

VBS Functions

No comments: