Jump to content

Noobie needs helps with Array


Recommended Posts

Hi everyone, I'm at best a noobie.  I have read through the Array helps, and specifically the 2D array help file, and I'm struggling to get my code working.

I have an array that is read from a file, thats working great.  I'm trying to do some math on the array, so I can find the largest, average, lowest, day over day change %, etc.

The array read working fine, I get 43 lines, line 0 is 44, and then I get data that looks like

0519 $10,000

0520 $10,001

0521 $10,002

The data in this array is a single 1D array, breaking it out into 2 columns so I can do the math is what I can get to happen.  

How do I reference the array to store this data?  Second, how do I assign this data to the appropriate row/column?

Thanks in advance.

Dim $all_cash_amounts[UBound($aInput)][2]
Dim $max_amount_in_account
Dim $min_amount_in_account

_FileReadToArray($LC_Check_file_path, $aInput)
_ArrayDisplay($aInput)

local $date = StringRegExp($aInput[1], "(\d\d\d\d)", 1)
local $cash = StringRegExp($aInput[1], "\d+\s(-?[0-9\.\,]+)", 1)
ConsoleWrite("Date is: " & $date & @CRLF)


For $i = 1 To UBound($aInput)-1
    $date = StringRegExp($aInput[$i], "(\d\d\d\d)", 1)
    $all_cash_amounts[$i][2] = $date[$i][0], $cash[$i][1]
    
Next


_ArrayDisplay($all_cash_amounts)

 

Link to comment
Share on other sites

First, Do Your Cash Amounts always have '$' ? This would simplify it a bit

You Could Use StringSplit

#include <Array.au3>
Local $aInput[2] = ["0225 $123.50", "0226 $163.50"]
Local $all_cash_amounts[UBound($aInput)][2]
For $i = 0 To UBound($aInput) - 1
    ;$date = StringRegExp($aInput[$i], "(\d\d\d\d)", 1)
    ;$cash = ...
    ;$all_cash_amounts[$i][0] = $date
    ;$all_cash_amounts[$i][1] = $cash
    ;Or
    $aTemp = StringSplit($aInput[$i], "$", $STR_NOCOUNT)
    If Not @error Then
        $all_cash_amounts[$i][0] = $aTemp[0]
        $all_cash_amounts[$i][1] = $aTemp[1]
    EndIf

Next
_ArrayDisplay($all_cash_amounts)

 

Edited by Bilgus
Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

×
×
  • Create New...