From 7adfefb67000d70a51e9238bd4ca13b2465713ac Mon Sep 17 00:00:00 2001 From: David Daily Date: Fri, 24 Jan 2020 03:24:06 -0600 Subject: [PATCH] Update 'func.ahk' --- func.ahk | 72 +++++++++++++------------------------------------------- 1 file changed, 16 insertions(+), 56 deletions(-) diff --git a/func.ahk b/func.ahk index 0154f16..a270071 100644 --- a/func.ahk +++ b/func.ahk @@ -29,75 +29,34 @@ GetInfo(xID) ; Accept what is passed here as the variable "xID" in the script { if (xID) { - csv := FileOpen(A_MyDocuments "\Work_Docs\emails.csv", "r") - if RegExMatch(csv.Read, xID) - { - Loop { - ReadLine := csv.ReadLine() - Array := StrSplit(ReadLine,",") - } Until InStr(Array[1], xID) - csv.Close() - Test := {xid: Array[1], email: Array[2], name: Array[3], user: Array[4], org: Array[5]} ; Return the array so we can do {variable}.email and so on - Return Test - } Else - { - Return Test.xid := "0" - } + Loop, Read, %A_MyDocuments%\Work_Docs\emails.csv ; read every line of "emails.csv" + { + Array := StrSplit(A_LoopReadLine,",") ; split the line at its separating commas to get separate "columns" AKA elements + if InStr(Array[1],xID) ; if at the specified element (1) the specified content (dealers xID) has been found, + Break ; stop searching + } + Test:= {xid: Array[1], email: Array[2], name: Array[3], user: Array[4], org: Array[5]} ; Return the array so we can do {variable}.email and so on + Return Test } if !(xID) { - Return Test.xid := "0" + Return } } -SetInfo(xID, column, value) -{ - StringUpper, xID, xID ;just to make sure - if (xID) - { - csv := FileOpen(A_MyDocuments "\Work_Docs\emails.csv", "r") - Array := [] - Dealinfo := [] - Loop { - ReadLine := csv.ReadLine() - Array := StrSplit(ReadLine,",") - usrid := Array[1] - Dealinfo[usrid] := {xid: Array[1], email: Array[2], name: Array[3], user: Array[4], org: Array[5]} - } Until (csv.AtEOF) - csv.Close() - - Switch column - { - Case "email": Dealinfo[xID].email := value - Case "name": Dealinfo[xID].name := value - Case "user": Dealinfo[xID].user := value - Case "org": Dealinfo[xID].org := value - } - - for k in Dealinfo - { - tempcsv .= Dealinfo[k].xid . "," . Dealinfo[k].email . "," . Dealinfo[k].name . "," . Dealinfo[k].user . "," . Dealinfo[k].org - } - csv := A_MyDocuments . "\Work_Docs\emails.csv" - FileAppend, %tempcsv%, tempcsv - FileCopy, tempcsv, %csv%, 1 - FileDelete, tempcsv - - Return true - } Else Return false -} - ;------------------------------------------------------------------------------ ; INI Manipulation that supports UTF-8 ;------------------------------------------------------------------------------ ini_load(location) { + File := FileOpen(location, "r") out := {} - Loop, Read, %location% + Loop { - RegExMatch(A_LoopReadLine, "(?<=\[).*(?=\])", _RESection) ; Matches section name - RegExMatch(A_LoopReadLine, "(?.*)=(?.*)", _) ; Key = _Key, Value = _Value + Line := File.ReadLine() + RegExMatch(Line, "(?<=\[).*(?=\])", _RESection) ; Matches section name + RegExMatch(Line, "(?.*)=(?.*)", _) ; Key = _Key, Value = _Value If (_RESection) { @@ -111,7 +70,8 @@ ini_load(location) out[currentSection][_Key] := _Value } } - } + } Until (File.AtEOF) + File.Close() Return out }