2009-06-30 98 views
2

我使用VB腳本上傳文件到服務器。我遇到的問題是,當我設置文件,這樣的ASCII格式...無效的過程調用或參數在VBScript

Set oFile = oFS.CreateTextFile(sPath & FileName, True, False) 

我得到一個錯誤,當子叫,說

無效的過程調用或參數

,但如果我設置文件爲Unicode

Set oFile = oFS.CreateTextFile(sPath & FileName, True, True) 

它上傳成功但由於編碼不正確而無法打開。 產生錯誤的線是這一個,如果格式是ASCII是這個

oFile.Write BinaryToString(FileData) 

其中oFile是我上述

創建的ASCII文件在這裏是產生錯誤的源代碼。這是一個上傳功能,我下車淨..

Public Sub SaveToDisk(sPath) 
     Dim oFS, oFile 
     Dim nIndex 

     If sPath = "" Or FileName = "" Then Exit Sub 
     If Mid(sPath, Len(sPath)) <> "\" Then sPath = sPath & "\" 

     Set oFS = Server.CreateObject("Scripting.FileSystemObject") 
     If Not oFS.FolderExists(sPath) Then Exit Sub 

     Set oFile = oFS.CreateTextFile(sPath & FileName, True, False) 
     oFile.Write BinaryToString(FileData) 

     oFile.Close 
    End Sub 

    Function BinaryToString(Binary) 
     'Antonin Foller, http://www.motobit.com 
     'Optimized version of a simple BinaryToString algorithm. 

     Dim cl1, cl2, cl3, pl1, pl2, pl3 
     Dim L 
     cl1 = 1 
     cl2 = 1 
     cl3 = 1 
     L = LenB(Binary) 

     Do While cl1<=L 
      pl3 = pl3 & Chr(AscB(MidB(Binary,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 
     BinaryToString = pl1 & pl2 & pl3 
    End Function 

難道是在服務器上配置?如果這使得任何意義,請幫助..

+0

中的FileData舉行哪些數據類型以及它是如何在第一時間獲得? – AnthonyWJones 2009-07-01 14:46:12

回答

0

我懷疑BinaryToString不是隻返回ASCII(實際上目前的OEM代碼頁)的字符,而且在Unicode範圍內的其他字符是OEM代碼頁設置之外。

這到底是什麼BinaryToString嗎?

+0

Function BinaryToString(Binary) \t \t'Antonin Foller,http://www.motobit.com \t \t'簡單BinaryToString算法的優化版本。 \t \t \t \t昏暗CL1,CL2,CL3,PL1,PL2,PL3 \t \t昏暗大號 \t \t CL1 = 1 \t \t CL2 = 1 \t \t CL3 = 1 \t \t L = LENB(二進制) \t \t \t \t的do while CL1 <= L \t \t \t PL3 = PL3&CHR(ASCB(MIDB(二進制,cl1,1))) \t \t \t CL1 = CL1 + 1 \t \t \t CL3 = CL3 + 1 \t \t \t如果CL3> 300然後 \t \t \t \t PL2 = PL2 PL3& \t \t \t \t PL3 = 「」 \t \t \t \t CL3 = 1 \t \t \t \t CL2 = CL2 + 1 \t \t \t \t如果CL2> 200然後 \t \t \t \t \t PL1 = PL1及PL2 \t \t \t \t \t PL2 = 「」 \t \t \t \t \t CL2 = 1 \t \t \t \t End If \t \t \t結束如果 \t \t環 \t \t BinaryToString = PL1和PL2和PL3 \t端功能 – Kwah009 2009-07-01 14:25:28