VBScript传真多个文档阵列问题

时间:2014-01-08 09:03:20

标签: arrays vbscript fax

我遇到了FaxDoc.Bodies功能问题。我得到错误“方法数据应该在一维零基础字符串数组中传递。”

我已经尝试了我能想到的一切,直接在FaxDoc.Bodies元素上使用array()。有什么想法吗?

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"

2 个答案:

答案 0 :(得分:1)

它要求一个数组并使用分号分隔符不起作用并返回相同的错误消息。

但是,我确实找到了使用VBA控制台应用程序而不是VBScript的解决方案。我的代码如下:

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

答案 1 :(得分:0)

According to MSDN您应该将文档作为字符串传递,文档用分号分隔:

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