Loop through the balances dimension and add them one by one
;*************************************************************************
;  Script Name:   SumBalances.kix
;  Author:        Wim Rotty
;  Date:          9/10/2007
;  Description:   Sum balances per Account
;*************************************************************************
;Script Options

If Not @LOGONMODE
    Break On
Else
    Break Off
EndIf
Dim $RC
$RC = SetOption("Explicit", "On")
$RC = SetOption("NoMacrosInStrings", "On")
$RC = SetOption("NoVarsInStrings", "On")
If @SCRIPTEXE = "KIX32.EXE"
    $RC = SetOption("WrapAtEOL", "On")
EndIf

;Declare variables
Dim
 
$Handle, $Text, $Line
Dim $AccountRow, $BalanceRow
Dim $Result[1,0]
Dim $Temp, $i
Dim $Total

;Initialize variables
$Handle = FreeFileHandle()
$Text = @SCRIPTDIR+"\test.txt"
$AccountRow = 1
$BalanceRow = 4

;Code
$RC = Open($Handle, $Text)
$Line = ReadLine($Handle)
While Not @ERROR
    If InStr($Line,"|")
       
$Line = Split($Line,"|")
       
$Temp = -1
       
For $i = 0 to UBound($Result,2)
           
If $Result[0,$i] = $Line[$AccountRow]
               
$Temp = $i
                $i = UBound($Result,2)
           
EndIf
        Next
        If $Temp > -1
           
$Result[1,$Temp] = CDbl($Result[1,$Temp]) + $Line[$BalanceRow]
       
Else
            If Not $Result[0,0] = ""
                ReDim Preserve $Result[1,UBound($Result,2)+1]
           
EndIf
            $Result[0,UBound($Result,2)] = $Line[$AccountRow]
           
$Result[1,UBound($Result,2)] = $Line[$BalanceRow]
       
EndIf
    EndIf
    $Line = ReadLine($Handle)
Loop
$RC = Close($Handle)
For Each $RC in $Result
    $RC ?
Next
For $i = 0 to UBound($Result,2)
   
$Total = CDbl($Result[1,$i]) + $Total
Next
$Total ?
Get $RC

;Personal UDF Section

;UDF Section