0

在 vbscript 中,我正在尝试(到目前为止没有成功)将数组作为参数传递给子:

subUnPackAArray(arrLineFieldValues)  

我从 Vbscript 收到以下错误消息:

Error:  Type mismatch: 'subUnPackAArray'
Code:   800A000D
Source: Microsoft VBScript runtime error
System: The data is invalid.

我将不胜感激有关在哪里寻找解决方案的任何解决方案或建议。我是 vbscript 爱好者,不是专业人士,所以请在批评时保持温和。

该数组包含以下文本:

Line  0
Line  1
Line  2
Line  3
Line  4
Line  5
Line  6
Line  7
Line  8
Line  9
Line  
Line  
Line  
.... etc....

从中获取文本的文件的名称是:

strFile2HarvestFromFullName = "C:\Apps\E_drive\Parameters for vbscript or python_script to harvest .txt"

我想确认子“subUnPackAArray”中没有错误(我试图将“arrLineFieldValues”作为参数传递给它)。
因此,为了确认这一点,我在行上方插入了 -- subUnPackAArray(arrLineFieldValues)
...几乎所有代码都在子“subUnPackAArray”中。
代码执行得很好,只有当 vbscript 到达该行时我才会收到错误消息:

subUnPackAArray(arrLineFieldValues)  

我不知道出了什么问题。

这是我的 vbsript 程序的全部文本:' 从文本文件中读取参数

strFile2HarvestFromFullName = "C:\Apps\E_drive\Parameters for vbscript or python_script to harvest .txt"

fn_Read_text_file_lines_into_1_dimL_array(strFile2HarvestFromFullName)


'*'''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
'* BEGIN_Function'*' BEGIN_Function '*' BEGIN_Function '*' BEGIN_Function '*' BEGIN_Function '*' BEGIN_Function '*' BEGIN_Function '*' BEGIN_Function 
'*'''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''

Function fn_Read_text_file_lines_into_1_dimL_array(fname)

    Dim strFile2HarvestFromFullName
    Dim objFSO
    Dim objTextFile
    Dim arrLineFieldValues()
    Dim strText
    Dim subUnPackAArray

    strFile2HarvestFromFullName = fname

    Const ForReading = 1

    Set objFSO = CreateObject("Scripting.FileSystemObject")
    Set objTextFile = objFSO.OpenTextFile(strFile2HarvestFromFullName, ForReading)
    i = 0

    Do Until objTextFile.AtEndOfStream 

        ReDim Preserve arrLineFieldValues(i)
        strText = objTextFile.ReadLine
        'MsgBox strText
        arrLineFieldValues(i) = strText
        i = i + 1

    Loop


    intUbound = UBound(arrLineFieldValues)
    strMsgBoxMsg = ""   

    For i = 0 To intUbound

        strMsgBoxMsg = strMsgBoxMsg & _
            "arrLineFieldValues(" & i & ") = " & arrLineFieldValues(i) & vbCrLf 

    Next ' For i = 0 To intUbound

    MsgBox "Line 45:  " & vbCrLf & strMsgBoxMsg


    subUnPackAArray(arrLineFieldValues)

End Function ' fn_Read_text_file_lines_into_1_dimL_array(fname)

'*''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
'* END_Function '*'END_Function '*'END_Function '*'END_Function '*'END_Function '*'END_Function '*'END_Function '*'END_Function '*'END_Function '*'END_Function 
'*''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''

'*''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
'* BEGIN_Sub'*' BEGIN_Sub '*' BEGIN_Sub '*' BEGIN_Sub '*' BEGIN_Sub '*' BEGIN_Sub '*' BEGIN_Sub '*' BEGIN_Sub '*' BEGIN_Sub '*' BEGIN_Sub '*' 
'*''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''

sub subUnPackAArray(strArray_OneDimensionOnly)
    '
    Dim strArray

    'strArray = strArray_OneDimensionOnlye
    intUbound = UBound(strArray_OneDimensionOnly)
    strMsgBoxMsg = ""   

    For i = 0 To intUbound

        strMsgBoxMsg = strMsgBoxMsg & _
            "strArray(" & i & ") = " & strArray_OneDimensionOnly(i) & vbCrLf 

    Next ' For i = 0 To intUbound

    MsgBox "Line 25:  " & vbCrLf & strMsgBoxMsg


End Sub ' subUnPackAArray()

'*''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
'* END_Sub '*'END_Sub '*'END_Sub '*'END_Sub '*'END_Sub '*'END_Sub '*'END_Sub '*'END_Sub '*'END_Sub '*'END_Sub '*'END_Sub '*'END_Sub '*'END_Sub 
'*''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
4

2 回答 2

2

Subs 不会被带括号调用。

改变这个:

MsgBox "Line 45:  " & vbCrLf & strMsgBoxMsg

subUnPackAArray(arrLineFieldValues)

对此:

MsgBox "Line 45:  " & vbCrLf & strMsgBoxMsg

subUnPackAArray arrLineFieldValues

该错误表明解析器期望遇到一个函数,而不是子例程。

于 2012-08-22T19:47:52.033 回答
2

Dim subUnPackAArray从中删除该行fn_Read_text_file_lines_into_1_dimL_array。局部变量覆盖全局变量。您正在尝试从本地范围调用全局对象,但您已经在本地定义了。它失败。

于 2012-08-22T19:55:58.070 回答