SaveBinaryData

Function SaveBinaryData(FileName, ByteArray)

  Const adTypeBinary = 1

  Const adSaveCreateOverWrite = 2

 

  'Create Stream object

  Dim BinaryStream

  Set BinaryStream = CreateObject("ADODB.Stream")

 

  'Specify stream type - we want To save binary data.

  BinaryStream.Type = adTypeBinary

 

  'Open the stream And write binary data To the object

  BinaryStream.Open

  BinaryStream.Write ByteArray

 

  'Save binary data To disk

  BinaryStream.SaveToFile FileName, adSaveCreateOverWrite

End Function


Example of Reading a Blob from DB

sFileName = "" & rsRSFile("FILENAME")

wscript.echo "Saving doc #: " & iDocID & " as filename: " &  sFileName

  size = rsRSFile.Fields("DOC_BLOB").ActualSize

  wscript.echo vbtab & "Size: " & size

  if size > 0 then

    blob = rsRSFile.Fields("DOC_BLOB").GetChunk(size)

    'wscript.echo blob

    wscript.echo vbtab & vbtab & rsRS("DOCUMENT_NAME")

    wscript.echo SaveBinaryData(sFileAndPath & sFileName, blob)

  end if 

    Sub CreateFolder(ByVal strPath)

        On Error Resume Next

        Dim objFSO ' Could be made global..

        set objFSO = CreateObject("Scripting.FileSystemObject") 'Could be set global...

        If Not objFSO.FolderExists(objFSO.GetParentFolderName(strPath)) Then Call CreateFolder(objFSO.GetParentFolderName(strPath))

        objFSO.CreateFolder(strPath)

        On Error GoTo 0

    End Sub

IIF

Public Function IIf(blnExpression, vTrueResult, vFalseResult)

  If blnExpression Then

   IIf = vTrueResult

    Else

   IIf = vFalseResult

   End If

End Function

funFormatColumns

function funFormatColumns(sString,iCount)

 if iCount >  len(sString) then

  iDiff =iCount- len(sString)

   funFormatColumns   = sString & space(iDiff)

 

 else

    funFormatColumns = left(sString,iCount)

 end if  

end function


Ping

Function Ping(Target)

Dim results

    On Error Resume Next

    Set shell = CreateObject("wScript.Shell")

    ' Send 1 echo request, waiting 2 seconds for result

    Set exec = shell.Exec("ping -n 1 -w 100 " & Target)

    results = LCase(exec.StdOut.ReadAll)

    Ping = (InStr(results, "reply from") > 0)

End Function


funScrubStr

function funScrubStr(strTxt)

  funScrubStr=replace(replace(replace(strTxt,"'","''")," & chr(34) & "," & chr(34) & chr(34) & "), ",", ",,")

end function