Martin Honnen wrote:
As for the error can you debug what value n has when you get
Invalid procedure call or argument
it might be that there is something wrong with that argument.
I couldn't read out "n" -- it was always showing as an empty string,
but there were some other oddities attached to it I can barely describe!
Thanks for the help to you and others. I finally managed to find
another script to workaround this critical portion of my old script
(which worked for years):
Public Sub SaveToDisk(sPat h)
Dim oFS, oFile
Dim nIndex
If sPath = "" Or FileName = "" Then Exit Sub
If Mid(sPath, Len(sPath)) <> "\" Then sPath = sPath & "\"
Set oFS = Server.CreateOb ject("Scripting .FileSystemObje ct")
If Not oFS.FolderExist s(sPath) Then Exit Sub
Set oFile = oFS.CreateTextF ile(sPath & FileName, true)
oFile.Write BinaryToString( FileData) <--- this was the error line
oFile.Close
End Sub
Public Sub SaveToDatabase( ByRef oField)
If LenB(FileData) = 0 Then Exit Sub
If IsObject(oField ) Then
oField.AppendCh unk FileData
End If
End Sub
' Following via PureASP Uploader ---------------
Function StringToBinary( String)
Dim I, B
For I=1 to len(String)
B = B & ChrB(Asc(Mid(St ring,I,1)))
Next
StringToBinary = B
End Function
Function BinaryToString( Binary)
'2001 Antonin Foller, PSTRUH Software
'Optimized version of PureASP conversion function
'Selects the best algorithm to convert binary data to String data
Dim TempString
On Error Resume Next
'Recordset conversion has a best functionality
TempString = RSBinaryToStrin g(Binary)
If Len(TempString) <> LenB(Binary) then'Conversion error
'We have to use multibyte version of BinaryToString
TempString = MBBinaryToStrin g(Binary)
end if
BinaryToString = TempString
End Function
Function MBBinaryToStrin g(Binary)
'1999 Antonin Foller, PSTRUH Software
'MultiByte version of BinaryToString function
'Optimized version of simple BinaryToString algorithm.
dim cl1, cl2, cl3, pl1, pl2, pl3
Dim L', nullchar
cl1 = 1
cl2 = 1
cl3 = 1
L = LenB(Binary)
Do While cl1<=L
pl3 = pl3 & Chr(AscB(MidB(B inary,cl1,1)))
cl1 = cl1 + 1
cl3 = cl3 + 1
if cl3>300 then
pl2 = pl2 & pl3
pl3 = ""
cl3 = 1
cl2 = cl2 + 1
if cl2>200 then
pl1 = pl1 & pl2
pl2 = ""
cl2 = 1
End If
End If
Loop
MBBinaryToStrin g = pl1 & pl2 & pl3
End Function
Function RSBinaryToStrin g(xBinary)
'1999 Antonin Foller, PSTRUH Software
'This function converts binary data (VT_UI1 | VT_ARRAY or MultiByte
string)
'to string (BSTR) using ADO recordset
'The fastest way - requires ADODB.Recordset
'Use this function instead of MBBinaryToStrin g if you have
ADODB.Recordset installed
'to eliminate problem with PureASP performance
Dim Binary
'MultiByte data must be converted to VT_UI1 | VT_ARRAY first.
if vartype(xBinary ) = 8 then Binary = MultiByteToBina ry(xBinary) else
Binary = xBinary
Dim RS, LBinary
Const adLongVarChar = 201
Set RS = CreateObject("A DODB.Recordset" )
LBinary = LenB(Binary)
if LBinary>0 then
RS.Fields.Appen d "mBinary", adLongVarChar, LBinary
RS.Open
RS.AddNew
RS("mBinary").A ppendChunk Binary
RS.Update
RSBinaryToStrin g = RS("mBinary")
Else
RSBinaryToStrin g = ""
End If
End Function
Function MultiByteToBina ry(MultiByte)
' This function converts multibyte string to real binary data (VT_UI1
| VT_ARRAY)
' Using recordset
Dim RS, LMultiByte, Binary
Const adLongVarBinary = 205
Set RS = CreateObject("A DODB.Recordset" )
LMultiByte = LenB(MultiByte)
if LMultiByte>0 then
RS.Fields.Appen d "mBinary", adLongVarBinary , LMultiByte
RS.Open
RS.AddNew
RS("mBinary").A ppendChunk MultiByte & ChrB(0)
RS.Update
Binary = RS("mBinary").G etChunk(LMultiB yte)
End If
MultiByteToBina ry = Binary
End Function
--
Google Blogoscoped
http://blog.outer-court.com