ParoXsitiC Posted July 31, 2010 Share Posted July 31, 2010 I did some looking around and I found a lot of codeAssociative arrays (hash/dicts etc). Not many of them that I found seem to support multidimensions except for this one: http://www.autoitscript.com/forum/index.php?showtopic=113182&st=0 This could do what I want, but I think its hard to read and understand the way he sets them up. What I am looking to do is this: Have a file we will called (wages.csv) that looks like this Default,0,40,10 Default,41,9999,15 Brian,0,40,15 Brian,41,50,20 Brian,51,9999,22 Chad,0,40,13 Chad,41,9999,17 That would then define a multi-dimentional array like this expandcollapse popupArray ( [Default] => Array ( [0] => Array ( [0] => 0 [1] => 40 [2] => 10 ) [1] => Array ( [0] => 41 [1] => 9999 [2] => 15 ) ) [Brian] => Array ( [0] => Array ( [0] => 0 [1] => 40 [2] => 15 ) [1] => Array ( [0] => 41 [1] => 50 [2] => 20 ) [2] => Array ( [0] => 51 [1] => 9999 [2] => 22 ) ) [Chad] => Array ( [0] => Array ( [0] => 0 [1] => 40 [2] => 13 ) [1] => Array ( [0] => 41 [1] => 9999 [2] => 17 ) ) ) Where default, brian, and chad could be use as keys. The whole point is that it will define a pay range for the employee (the key). If Brian worked 52 hours he would fall under 52-9999 thus getting 22 an hour. etc etc. Is this the best way approaching this idea or do you have a better idea? If it is...then how can I define the arrays I need to define? Link to comment Share on other sites More sharing options...
jchd Posted July 31, 2010 Share Posted July 31, 2010 Simply use a two-dimensional array. That's distinct from arrays in an array! This wonderful site allows debugging and testing regular expressions (many flavors available). An absolute must have in your bookmarks.Another excellent RegExp tutorial. Don't forget downloading your copy of up-to-date pcretest.exe and pcregrep.exe hereRegExp tutorial: enough to get startedPCRE v8.33 regexp documentation latest available release and currently implemented in AutoIt beta. SQLitespeed is another feature-rich premier SQLite manager (includes import/export). Well worth a try.SQLite Expert (freeware Personal Edition or payware Pro version) is a very useful SQLite database manager.An excellent eBook covering almost every aspect of SQLite3: a must-read for anyone doing serious work.SQL tutorial (covers "generic" SQL, but most of it applies to SQLite as well)A work-in-progress SQLite3 tutorial. Don't miss other LxyzTHW pages!SQLite official website with full documentation (may be newer than the SQLite library that comes standard with AutoIt) Link to comment Share on other sites More sharing options...
BugFix Posted July 31, 2010 Share Posted July 31, 2010 Because you want an Associative array, you can fake that. This works: expandcollapse popupLocal $tagDefault = 'int[3];' Enum $Default, $Brian, $Chad, $iCount Global $a[$iCount] $a[$Default] = DllStructCreate($tagDefault & $tagDefault) $a[$Brian] = DllStructCreate($tagDefault & $tagDefault & $tagDefault) $a[$Chad] = DllStructCreate($tagDefault & $tagDefault) DllStructSetData($a[$Default], 1, 0, 1) DllStructSetData($a[$Default], 1, 40, 2) DllStructSetData($a[$Default], 1, 10, 3) DllStructSetData($a[$Default], 2, 41, 1) DllStructSetData($a[$Default], 2, 9999, 2) DllStructSetData($a[$Default], 2, 15, 3) DllStructSetData($a[$Brian], 1, 0, 1) DllStructSetData($a[$Brian], 1, 40, 2) DllStructSetData($a[$Brian], 1, 15, 3) DllStructSetData($a[$Brian], 2, 41, 1) DllStructSetData($a[$Brian], 2, 50, 2) DllStructSetData($a[$Brian], 2, 20, 3) DllStructSetData($a[$Brian], 3, 51, 1) DllStructSetData($a[$Brian], 3, 9999, 2) DllStructSetData($a[$Brian], 3, 22, 3) DllStructSetData($a[$Chad], 1, 0, 1) DllStructSetData($a[$Chad], 1, 40, 2) DllStructSetData($a[$Chad], 1, 13, 3) DllStructSetData($a[$Chad], 2, 41, 1) DllStructSetData($a[$Chad], 2, 9999, 2) DllStructSetData($a[$Chad], 2, 17, 3) ConsoleWrite(_GetVal($Brian, 22) & @CRLF) ConsoleWrite(_GetVal($Brian, 43) & @CRLF) ConsoleWrite(_GetVal($Brian, 57) & @CRLF) ConsoleWrite(_GetVal($Chad, 35) & @CRLF) ConsoleWrite(_GetVal($Chad, 45) & @CRLF) Func _GetVal($Name, $Hour) Local $i = 1, $val While Not @error If Number($Hour) <= DllStructGetData($a[$Name], $i, 2) Then _ Return DllStructGetData($a[$Name], $i, 3) $i += 1 WEnd Return SetError(1,0,-1) ; hour greather than stored max value EndFunc Best Regards BugFix  Link to comment Share on other sites More sharing options...
ParoXsitiC Posted July 31, 2010 Author Share Posted July 31, 2010 Because you want an Associative array, you can fake that. This works: expandcollapse popupLocal $tagDefault = 'int[3];' Enum $Default, $Brian, $Chad, $iCount Global $a[$iCount] $a[$Default] = DllStructCreate($tagDefault & $tagDefault) $a[$Brian] = DllStructCreate($tagDefault & $tagDefault & $tagDefault) $a[$Chad] = DllStructCreate($tagDefault & $tagDefault) DllStructSetData($a[$Default], 1, 0, 1) DllStructSetData($a[$Default], 1, 40, 2) DllStructSetData($a[$Default], 1, 10, 3) DllStructSetData($a[$Default], 2, 41, 1) DllStructSetData($a[$Default], 2, 9999, 2) DllStructSetData($a[$Default], 2, 15, 3) DllStructSetData($a[$Brian], 1, 0, 1) DllStructSetData($a[$Brian], 1, 40, 2) DllStructSetData($a[$Brian], 1, 15, 3) DllStructSetData($a[$Brian], 2, 41, 1) DllStructSetData($a[$Brian], 2, 50, 2) DllStructSetData($a[$Brian], 2, 20, 3) DllStructSetData($a[$Brian], 3, 51, 1) DllStructSetData($a[$Brian], 3, 9999, 2) DllStructSetData($a[$Brian], 3, 22, 3) DllStructSetData($a[$Chad], 1, 0, 1) DllStructSetData($a[$Chad], 1, 40, 2) DllStructSetData($a[$Chad], 1, 13, 3) DllStructSetData($a[$Chad], 2, 41, 1) DllStructSetData($a[$Chad], 2, 9999, 2) DllStructSetData($a[$Chad], 2, 17, 3) ConsoleWrite(_GetVal($Brian, 22) & @CRLF) ConsoleWrite(_GetVal($Brian, 43) & @CRLF) ConsoleWrite(_GetVal($Brian, 57) & @CRLF) ConsoleWrite(_GetVal($Chad, 35) & @CRLF) ConsoleWrite(_GetVal($Chad, 45) & @CRLF) Func _GetVal($Name, $Hour) Local $i = 1, $val While Not @error If Number($Hour) <= DllStructGetData($a[$Name], $i, 2) Then _ Return DllStructGetData($a[$Name], $i, 3) $i += 1 WEnd Return SetError(1,0,-1) ; hour greather than stored max value EndFunc This seems to mimic what I need, I want to note the data is pulled from a csv, so it will be dynamic. But I guess I could automate that with a bunch of eval and such. Link to comment Share on other sites More sharing options...
Moderators SmOke_N Posted July 31, 2010 Moderators Share Posted July 31, 2010 Export the csv to sqlite, and use the _sqlite funcs to get your data. Common sense plays a role in the basics of understanding AutoIt... If you're lacking in that, do us all a favor, and step away from the computer. Link to comment Share on other sites More sharing options...
jchd Posted August 1, 2010 Share Posted August 1, 2010 Export the csv to sqlite, and use the _sqlite funcs to get your data.I was about to give this advice but got the fear to be called sqlite-maniac. This wonderful site allows debugging and testing regular expressions (many flavors available). An absolute must have in your bookmarks.Another excellent RegExp tutorial. Don't forget downloading your copy of up-to-date pcretest.exe and pcregrep.exe hereRegExp tutorial: enough to get startedPCRE v8.33 regexp documentation latest available release and currently implemented in AutoIt beta. SQLitespeed is another feature-rich premier SQLite manager (includes import/export). Well worth a try.SQLite Expert (freeware Personal Edition or payware Pro version) is a very useful SQLite database manager.An excellent eBook covering almost every aspect of SQLite3: a must-read for anyone doing serious work.SQL tutorial (covers "generic" SQL, but most of it applies to SQLite as well)A work-in-progress SQLite3 tutorial. Don't miss other LxyzTHW pages!SQLite official website with full documentation (may be newer than the SQLite library that comes standard with AutoIt) Link to comment Share on other sites More sharing options...
Moderators Melba23 Posted August 1, 2010 Moderators Share Posted August 1, 2010 jchd,got the fear to be called sqlite-maniacToo late! M23  Any of my own code posted anywhere on the forum is available for use by others without any restriction of any kind Open spoiler to see my UDFs: Spoiler ArrayMultiColSort ---- Sort arrays on multiple columnsChooseFileFolder ---- Single and multiple selections from specified path treeview listingDate_Time_Convert -- Easily convert date/time formats, including the language usedExtMsgBox --------- A highly customisable replacement for MsgBoxGUIExtender -------- Extend and retract multiple sections within a GUIGUIFrame ---------- Subdivide GUIs into many adjustable framesGUIListViewEx ------- Insert, delete, move, drag, sort, edit and colour ListView itemsGUITreeViewEx ------ Check/clear parent and child checkboxes in a TreeViewMarquee ----------- Scrolling tickertape GUIsNoFocusLines ------- Remove the dotted focus lines from buttons, sliders, radios and checkboxesNotify ------------- Small notifications on the edge of the displayScrollbars ----------Automatically sized scrollbars with a single commandStringSize ---------- Automatically size controls to fit textToast -------------- Small GUIs which pop out of the notification area  Link to comment Share on other sites More sharing options...
ParoXsitiC Posted August 4, 2010 Author Share Posted August 4, 2010 Sorry to reply late, and bring back an old subject but has anyone else have any advice or can point me to any alternative? Converted CSV to SQlite would probably work but seems like a bit of a hassle to just mimic assoc. arrays. Link to comment Share on other sites More sharing options...
jchd Posted August 4, 2010 Share Posted August 4, 2010 (edited) I would say that, to the contrary, using associative arrays for any serious business-like (payroll or whatever) application is deemed to turn out more complex and spaghetti-prone than using simple SQL. _SQLite_QuerySingleRow($hDB, "select wage from wages where name like " & _SQLite_Escape($employee) & " and " & $WorkTime & " between lowhours and highhours;", $row) if @error then _SQLite_QuerySingleRow($hDB, "select wage from wages where name like 'default' and " & $WorkTime & " between lowhours and highhours;", $row) endif $wage = $row[0] But, as Melba23 disclosed above, this is just my pet perversion Edited August 4, 2010 by jchd This wonderful site allows debugging and testing regular expressions (many flavors available). An absolute must have in your bookmarks.Another excellent RegExp tutorial. Don't forget downloading your copy of up-to-date pcretest.exe and pcregrep.exe hereRegExp tutorial: enough to get startedPCRE v8.33 regexp documentation latest available release and currently implemented in AutoIt beta. SQLitespeed is another feature-rich premier SQLite manager (includes import/export). Well worth a try.SQLite Expert (freeware Personal Edition or payware Pro version) is a very useful SQLite database manager.An excellent eBook covering almost every aspect of SQLite3: a must-read for anyone doing serious work.SQL tutorial (covers "generic" SQL, but most of it applies to SQLite as well)A work-in-progress SQLite3 tutorial. Don't miss other LxyzTHW pages!SQLite official website with full documentation (may be newer than the SQLite library that comes standard with AutoIt) Link to comment Share on other sites More sharing options...
ParoXsitiC Posted August 16, 2010 Author Share Posted August 16, 2010 (edited) Sorry for another late reply. So yeah, SQL seems more simple. However, as I stated. the CSV files are redownloaded from a server each time the program is read, so I will still need to use CSV files as a source of data. Which means I will need to convert CSV files to SQLlite databases using AutoIT. Any code on that? I guess in theory I could have PHP do that work for me, if its easier. And then just download the SQLlight database instead of the CSV file for autoit. By CSV, I mean exactly that. Comma Separated values(columns), with each row separated by a newline. Edit: nevermind. I googled "csv to sqlite autoit" ...normally it will search the forums for me... Didnt work for me. I found what I wanted here: http://www.autoitscript.com/forum/index.php?showtopic=117675&st=0&p=819670&hl=sqlite%20import&fromsearch=1&#entry819670 Edit2: There seems to be issues with running command lines using AutoIT...I decided to use this easy to read but ugly code: Local $hFile = @ScriptDir & "\wages.csv" Dim $FileArray _SQLite_Startup() _SQLite_Open() ; open :memory: Database If Not _SQLite_Exec(-1, "CREATE TEMP TABLE wagetable (name, lowhours, highhours, wage);") = $SQLITE_OK Then MsgBox(16, "SQLite Error", _SQLite_ErrMsg()) _FileReadToArray($hFile, $FileArray) _ArrayDelete($FileArray, 0) For $Line in $FileArray $Values = StringSplit($Line, ",", 2) If Not _SQLite_Exec(-1, "INSERT INTO wagetable VALUES ('"&$Values[0]&"','"&$Values[1]&"','"&$Values[2]&"', '"&$Values[3]&"');") = $SQLITE_OK Then MsgBox(16, "SQLite Error", _SQLite_ErrMsg()) Next Edited August 16, 2010 by ParoXsitiC Link to comment Share on other sites More sharing options...
Recommended Posts
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 accountSign in
Already have an account? Sign in here.
Sign In Now