code未能接通QUOT; Application.Match"打电话,"对象所需的"信息 [英] Code fails on "Application.Match" call, "object required" message

查看:207
本文介绍了code未能接通QUOT; Application.Match"打电话,"对象所需的"信息的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

需要帮助,在此行....如果ISERROR(Application.Match(ILINE,编曲,0))然后...
它的运行时错误是一个对象是必需的。我已经尝试了一些不同的东西来解决,但我坚持。一直在研究,但没有找到任何内容的决议。

当我试图声明......昏暗ARR作为变量,它反驳道,预期声明的末尾。我只是点击ProcessCollection.vbs运行脚本。我使用EditPlus3,它并选择应用程序,在这条线的红色文本。

我试过VbsEdit当中,当它调试到这条线,ILINE,编曲,被定义,但应用程序的值是空。

 的GetFiles()
WriteCSV()*****
功能的GetFiles
昏暗的ARR
昏暗改编为Variant
昏暗iFileLines
昏暗ILINE
设置objFSO =的CreateObject(Scripting.FileSystemObject的)
objStartFolder =C:\\ HGIS \\一
设置objFolder = objFSO.GetFolder(objStartFolder)
设置colFiles = objFolder.Files对于每个OBJFILE在colFiles
    Wscript.Echo objFile.Name
    最惠国= objStartFolder +\\+ objFile.Name
    Wscript.Echo最惠国
    打开文件和放大器;处理每个文件
    设置FSO =的CreateObject(Scripting.FileSystemObject的)
    设置theFile = fso.OpenTextFile(MFN,8,真)
    iFileLines = theFile.Line
    ILINE = 0
    ARR =阵列(2,3,iFileLines - 1)第二,第三,和去年第二
    MSGBOX iFileLines    设置objFileToRead =的CreateObject(Scripting.FileSystemObject的)。的OpenTextFile(MFN,1)
    暗淡strLine中,TotStr
    TotStr =塞拉
    这样做虽然不objFileToRead.AtEndOfStream
         strLine中= objFileToRead.ReadLine()
         MSGBOX strLine中
         解析为特定的数据线 - 即-2014-获取日期/时间戳记
         ILINE = ILINE + 1
         '然后检查行号是阵列中:
         采集数据并存储到CSV文件为Excel分析
         如果ISERROR(Application.Match(ILINE,编曲,0))然后
            这不是在数组中,做到这一点....
            MSGBOX不
         其他
            这是在数组中,抓住它
            TotStr = TotStr +,+ strLine中
            MSGBOX TotStr
         万一
    循环
    objFileToRead.Close
    设置objFileToRead =什么
下一个csvFile.Close
结束功能
*****


解决方案

我发现从贾斯汀功能在DigitalDeviation.com多尔斯,我用来替换Application.Match功能。

 功能IsInArray(〜应变,arrCheck)
    IsInArray:检查数组内的值
    作者:贾斯汀施舍 - www.DigitalDeviation.com
    昏暗bFlag
    bFlag =假
    如果IsArray的(arrCheck),而不是ISNULL(〜应变)然后
        我朦胧
        对于i = 0到UBound函数(arrCheck)
            如果LCASE(arrcheck(I))= LCASE(〜应变)然后
                bFlag = TRUE
                对于出口
            万一
        下一个
    万一
    IsInArray = bFlag
结束功能
*****

Need help, in this line....If IsError(Application.Match(iLine, arr, 0)) Then ... Its runtime error is that an object is required. I've tried a number of different things to solve, but am stuck. Been researching but not finding anything as a resolution.

When I try to declare..."Dim arr as variant" it retorts that "Expected end of statement". I am simply clicking on "ProcessCollection.vbs" to run the script. I'm using EditPlus3, and it does highlight "Application" in red text in this line.

I've tried VbsEdit and when it debugs to this line, iLine, arr, are defined, but the value of "Application" is "Empty".

GetFiles()
'WriteCSV()

'*****
Function GetFiles
Dim arr
'Dim arr as Variant
Dim iFileLines
Dim iLine
Set objFSO = CreateObject("Scripting.FileSystemObject")
objStartFolder = "C:\hgis\a"
Set objFolder = objFSO.GetFolder(objStartFolder)
Set colFiles = objFolder.Files

For Each objFile in colFiles
    'Wscript.Echo objFile.Name
    mfn = objStartFolder +"\"+ objFile.Name
    Wscript.Echo mfn
    'open file & process each file
    set fso = CreateObject("Scripting.FileSystemObject") 
    Set theFile = fso.OpenTextFile(mfn, 8, True) 
    iFileLines = theFile.Line
    iLine = 0
    arr = Array(2, 3, iFileLines - 1) ' second, third, and 2nd from last
    msgbox iFileLines

    Set objFileToRead = CreateObject("Scripting.FileSystemObject").OpenTextFile(mfn,1)
    Dim strLine, TotStr
    TotStr = "CellA"
    do while not objFileToRead.AtEndOfStream
         strLine = objFileToRead.ReadLine()
         msgbox strline
         'Parse lines for specific data - i.e. "-2014-" to get date/time stamp
         iLine = iLine + 1
         'And then check if the line number is in the array:
         'Capture data and store to csv file for Excel analysis
         If IsError(Application.Match(iLine, arr, 0)) Then
            ' It isn't in the array, do this....
            msgbox "no"
         Else
            ' It is in the array, grab it
            TotStr = TotStr +","+ strline 
            msgbox TotStr
         End If
    loop
    objFileToRead.Close
    Set objFileToRead = Nothing
Next

'csvFile.Close 
End Function
'*****

解决方案

I found a function from Justin Doles at DigitalDeviation.com that I used to replace the Application.Match function.

Function IsInArray(strIn, arrCheck)
    'IsInArray: Checks for a value inside an array
    'Author: Justin Doles - www.DigitalDeviation.com
    Dim bFlag 
    bFlag = False
    If IsArray(arrCheck) AND Not IsNull(strIn) Then
        Dim i
        For i = 0 to UBound(arrCheck)
            If LCase(arrcheck(i)) = LCase(strIn) Then
                bFlag = True
                Exit For
            End If
        Next
    End If
    IsInArray = bFlag
End Function
'*****

这篇关于code未能接通QUOT; Application.Match"打电话,"对象所需的"信息的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆