简体   繁体   English

VBScript传真多个文档数组问题

[英]VBScript Faxing multiple documents array issue

I am having trouble with the FaxDoc.Bodies function. 我在使用FaxDoc.Bodies函数时遇到问题。 I get the error "Methods data should be passed in a one-dimensional zero-based array of strings." 我收到错误“方法数据应该以一维基于零的字符串数组形式传递”。

I have tried everything I can think of, from using array() directly on the FaxDoc.Bodies element. 我尝试了所有可以想到的方法,直接在FaxDoc.Bodies元素上使用array()。 Any ideas? 有任何想法吗?

Dim strJobIds
Dim STAttach(1)
'On Error Resume Next 
Set FaxServer = WScript.CreateObject("FAXCOMEX.FaxServer") 

WScript.Echo "FaxServer created"  
FaxServer.Connect "" 


Set FaxDoc = WScript.CreateObject("FAXCOMEX.FaxDocument") 



STAttach(0)="chili.txt"
STAttach(1)="sugarcookies.txt"


FaxDoc.Bodies=STAttach

FaxDoc.DocumentName = "My First Fax" 

FaxDoc.Recipients.Add ("15555551234") 

FaxDoc.Sender.Email = "bob@xyz.com" 
FaxDoc.Sender.Name = "Bob" 
FaxDoc.Sender.FaxNumber = "15555555678"

'    Optionally, Use FaxDoc.CoverPage and FaxDoc.CoverPageType to specify a cover page 
'    FaxDoc.CoverPage = generic 
'    FaxDoc.CoverPageType = 2 

'    Optionally, you can control banner in outbound faxes 
FaxServer.Folders.OutgoingQueue.Branding = True
FaxServer.Folders.OutgoingQueue.Save     '      Make the change persistent 
'    Optionally, use FaxServer.Folders.OutgoingQueue.Retries and 
'    FaxServer.Folders.OutgoingQueue.RetryDelay to control retries 

'    Submit the document to the connected fax server and get back the job ID. 
strJobIds=""
JobID = FaxDoc.ConnectedSubmit2(FaxServer, strJobIds) 

WScript.Echo "FaxDoc.ConnectedSubmit success"

It asks for an array and using the semicolon separator does not work and returns the same error messages. 它要求一个数组,并且使用分号分隔符不起作用,并返回相同的错误消息。

I did, however, find a solution using a VBA Console Application instead of VBScript. 但是,我确实找到了使用VBA控制台应用程序而不是VBScript的解决方案。 My code is as follows: 我的代码如下:

Module Module1
    Function DecodeToDocArray(ByVal inputDocListString As String, ByRef numDocuments As Integer, ByRef bRetVal As Boolean) As String()
        bRetVal = False
        If (String.IsNullOrEmpty(inputDocListString)) Then
            Return Nothing
        End If
        Dim docArray As String()
        Dim strDelimiter As String
        Dim delimiter As Char()

        docArray = Nothing
        strDelimiter = ";"
        delimiter = strDelimiter.ToCharArray()
        docArray = inputDocListString.Split(delimiter)
        numDocuments = docArray.GetLength(0)
        bRetVal = True
        Return docArray
    End Function
    Sub Main()



        Dim retVal As Boolean
        Dim numDocs As Integer
        Dim docArray As String()
        Dim strDocList As String = "chili.txt;sugarcookies.txt"
        MsgBox(strDocList)
        numDocs = 0
        docArray = DecodeToDocArray(strDocList, numDocs, retVal)
        If ((docArray.GetLength(0) = 0) Or (retVal = False)) Then
            System.Console.WriteLine("DecodeToDocArray failed")
            retVal = False
            MsgBox("End")
            End
        End If

        Dim FaxDoc = CreateObject("FAXCOMEX.FaxDocument")
        Dim FaxServer = CreateObject("FAXCOMEX.FaxServer")
        FaxServer.Connect("")

        MsgBox("test")
        FaxDoc.Bodies = docArray
        FaxDoc.Sender.LoadDefaultSender()
        FaxDoc.Recipients.Add("15555551234", "TestUser")
        Dim strJobIds As Object
        strJobIds = Nothing

        FaxDoc.ConnectedSubmit2(FaxServer, strJobIds)

        MsgBox("sent")

    End Sub

End Module

根据MSDN,您应该将文档作为字符串传递,并用半冒号分隔文档:

FaxDoc.Bodies = "chili.txt;sugarcookies.txt"

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM