New way to process emails.csv
updated the function to use an object instead of just reading lines, added a function to write to the csv as well so I can update it without actually modifying it
This commit is contained in:
		
							
								
								
									
										58
									
								
								func.ahk
									
									
									
									
									
								
							
							
						
						
									
										58
									
								
								func.ahk
									
									
									
									
									
								
							| @@ -3,7 +3,7 @@ SendMode, Input | ||||
| FileEncoding, UTF-8	; Makes sure the special characters dont break stuff | ||||
| SetWorkingDir, %A_MyDocuments%\D3K	; Make sure we can find the .ahks linked below | ||||
|  | ||||
| d3k_version = 2.7		; The current version | ||||
| d3k_version = 2.8		; The current version | ||||
|  | ||||
| ini = %A_MyDocuments%\D3Ksettings.ini	; Where the settings ini is | ||||
|  | ||||
| @@ -29,21 +29,53 @@ GetInfo(xID)	; Accept what is passed here as the variable "xID" in the script | ||||
| { | ||||
| 	if (xID) | ||||
| 	{ | ||||
| 		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 | ||||
| 		csv := FileOpen(A_MyDocuments "\Work_Docs\emails-test.csv", "r") | ||||
| 		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 | ||||
| 	} | ||||
| 	if !(xID) | ||||
| 	{ | ||||
| 		Return | ||||
| 	} | ||||
| 	} Else Return false | ||||
| } | ||||
|  | ||||
| SetInfo(xID, column, value) | ||||
| { | ||||
| 	StringUpper, xID, xID	;just to make sure | ||||
| 	if (xID) | ||||
| 	{ | ||||
| 		csv := FileOpen(A_MyDocuments "\Work_Docs\emails-test.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-test.csv" | ||||
| 		FileAppend, %tempcsv%, tempcsv | ||||
| 		FileCopy, tempcsv, %csv%, 1 | ||||
| 		FileDelete, tempcsv | ||||
|  | ||||
| 		Return true | ||||
| 	} Else Return false | ||||
| } | ||||
|  | ||||
| ;------------------------------------------------------------------------------ | ||||
| ; INI Manipulation that supports UTF-8 | ||||
|   | ||||
		Reference in New Issue
	
	Block a user