如何求和和数组的子值

时间:2019-07-18 10:01:04

标签: vbscript qtp hp-uft

首先,我检查了这个问题,但是我不清楚如何在代码中实现: How to create a dynamic array and sum its values

考虑此代码:

'Abrimos el archivo     
Dim objFS 
Dim objFile
ReDim aSumaAmounts(0)
ReDim aRestaAmount(0)
sF1 = "C:\Users\" & Environment("UserName") & "\Desktop\20190414210000_OPEL_TRANSFER_DETAIL.TXT"

'Abrimos el txt del Trasfer Details
Set objFS = CreateObject("Scripting.FileSystemObject")
Set objFile = objFS.OpenTextFile(sF1)

Do Until objFile.AtEndOfStream

   intLine = objFile.Line
   sContent = objFile.ReadLine
   contentSplited = split(sContent, ";")

   If contentSplited(3) = "FA" Then

        If aSumaAmounts(0) = ""  Then
            aSumaAmounts(0) = contentSplited(5)
        else

            ReDim Preserve aSumaAmounts(UBound(aSumaAmounts) + 1)
            aSumaAmounts(UBound(aSumaAmounts)) = contentSplited(5)

        End If

    ElseIf contentSplited(3) = "NC" Then

        If aRestaAmount(0) = ""  Then
            aRestaAmount(0) = contentSplited(5)
        else

            ReDim Preserve aRestaAmount(UBound(aRestaAmount) + 1)   
            aRestaAmount(UBound(aRestaAmount)) = contentSplited(5)

        End If

   End If

目标是逐行读取txt,在动态数组中输入该行的一些数据,然后将aSumaAmounts()数组和SUB的值与aRestaAmounts()数组求和。

我该如何计算总和?考虑到数组大小是动态的。

0 个答案:

没有答案