Invalid procedure call or argument in vbscript

拜拜、爱过 提交于 2019-12-20 01:02:25

问题


I am using vb script to upload a file to the server. The problem I'm having is that when I set the file to ASCII format like this...

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

I get an error when the sub is called that says

Invalid procedure call or argument

but if I set the file to unicode

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

it uploads successfully but will not open because of the incorrect encoding. The line that produces the error is this one if format is ASCII is this one

oFile.Write BinaryToString(FileData)

where oFile is the ASCII file I had created above

Here is the source code that produces the error. It's an upload function I got off the net..

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

Could it be configurations on the server? If this makes any sense please help..


回答1:


I suspect BinaryToString returns not only ASCII (actually the current OEM codepage) characters but also other characters in the unicode range that are outside the OEM codepage set.

What exactly does BinaryToString do?




回答2:


After an unreasonably long time dealing with this same issue, without really making sense to me, and not related to Unicode, I finally got it to work with:

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

This page was useful to me: http://ns7.webmasters.com/caspdoc/html/vbscript_filesystemobject_object_opentextfile_method.htm

Ilya Evdokimov



来源:https://stackoverflow.com/questions/1062670/invalid-procedure-call-or-argument-in-vbscript

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!