将OpenTextFile与.tmp文件一起使用

时间:2012-12-27 16:03:49

标签: vbscript

我使用的是名为Move It Central的软件。它允许上载VBScripts以用于各种文件。行MICacheFilename()返回C:\TEMP\path\file.tmp,但此文件是一个简单的txt文件。

我正在尝试使用OpenTextFile方法计算此文本文件中的行数,但是我收到错误Object doesn't support this property or method。我似乎无法弄清楚为什么我会这样做。脚本如下。我相信很多问题都是用户错误,因为我对VBS非常不熟悉

Sub main()
    Dim objFSO, textInput, strTextFile, actualRows, testRows, mFunction, strTemp
    CONST ForReading = 1

    MISetTaskParam "cachedFile", mFile
    textInput = "the next line is the cachedFile"
    MILogMsg textInput
    MILogMsg mFile


    Set objFSO = CreateObject("Scripting.FileSystemObject")
    strTextFile = MICacheFilename()
    textInput = objFSO.OpenTextFile(strTextFile,ForReading)
    testRows = MIGetTaskParam("testRows")

    Do While textInput.AtEndOfStream <> True
        strTemp = textInput.SkipLine
    Loop
    IF textInput.Line-1 >= testRows THEN
        MILogMsg "true"
    ELSE
        MILogMsg "false"
    END IF
end sub
main

1 个答案:

答案 0 :(得分:2)

您错过了SET关键字

set textInput = objFSO.OpenTextFile(strTextFile,ForReading)

参考:http://msdn.microsoft.com/en-us/library/office/gg278834.aspx