如何使VB脚本计算mas启动的次数?

时间:2017-04-15 00:42:42

标签: vbscript

我想让我的VB脚本计算我启动它的次数并将数字写入硬盘驱动器上的文件 - 与该批处理文件类似。

private static int[] FindDuplicates(int[] arrA,int[] arrB)
    {
        var aList=new List<int>();
        Array.Sort(arrA);
        Array.Sort(arrB);


        for(int i=0;i<arrA.Length;i++)
        {
           if(arrB.Contains(arrA[i]))
           {           
           aList.Add(arrA[i]);
           }

        }
        return aList.ToArray();

    }

我在下面尝试了这段代码。在第一次运行时,它工作得很好,但在那之后it doesn't

@echo off
if not exist "C:\Users\User\Desktop\run.log" goto end
if exist "C:\Users\User\Desktop\run.log" goto 123
:123
for /f "delims=" %%x in (C:\Users\User\Desktop\run.log) do set var=%%x
Set /A result = %var% + 1
echo %result% > "C:\Users\User\Desktop\run.log"
exit
:end
echo 1 > "C:\Users\User\Desktop\run.log"
exit

1 个答案:

答案 0 :(得分:0)

你犯了多个错误。我已经用注释更新了代码,以便您了解流程。当然,一旦理解了流程,就可以改进代码。

尝试以下

Dim InputFile
Dim countText
Dim objFSO, oFile

Set objFSO = CreateObject("Scripting.FileSystemObject")
InputFile = "C:\Users\User\Desktop\run.log"
If objFSO.FileExists(InputFile) Then
    'Read the file
    Set oFile = objFSO.OpenTextFile(InputFile, 1, True)
    countText = oFile.ReadLine
    If IsNumeric(countText) Then
        MsgBox "Numeric"
        Count = CInt(countText) + 1
    Else
        Count = 1
    End If
    oFile.Close
    Set oFile = Nothing

    'Overwrite the file
    Set oFile = objFSO.OpenTextFile(InputFile, 2, True)
    oFile.Write (CStr(Count))
Else
    Set oFile = objFSO.CreateTextFile(InputFile, True)
    oFile.Write "1"
End If

'Close and Remove from memory 
oFile.Close
Set oFile = Nothing
Set objFSO = Nothing