wklw2003 Posted August 10, 2016 Posted August 10, 2016 I have a hundreds of color rules and the !tempArray needs to be in order. I can open this file in Notepad ++ and Excel. Once I marge them all together, I am looking for the best way to set the !tempArray to be in numbered order. Can someone Please help? tempArray = ARRAY() !gphAutoColourRul = |Electrical/PEEC/New| !gphAutoColTnslVal = 0 !gphAutoColEdgeOn = FALSE !gphAutoColourCol = object COLOUR(|164|) !gphAutoColour = object GPHAUTOCOLOUR(!gphAutoColourRul, !gphAutoColourCol, !gphAutoColTnslVal, !gphAutoColEdgeOn) !tempArray[1] = !gphAutoColour !gphAutoColourRul = |Electrical/PEEC/Demo| !gphAutoColTnslVal = 0 !gphAutoColEdgeOn = FALSE !gphAutoColourCol = object COLOUR(|green|) !gphAutoColour = object GPHAUTOCOLOUR(!gphAutoColourRul, !gphAutoColourCol, !gphAutoColTnslVal, !gphAutoColEdgeOn) !tempArray[2] = !gphAutoColour !gphAutoColourRul = |Electrical/PEEC/Existing| !gphAutoColTnslVal = 0 !gphAutoColEdgeOn = FALSE !gphAutoColourCol = object COLOUR(|grey|) !gphAutoColour = object GPHAUTOCOLOUR(!gphAutoColourRul, !gphAutoColourCol, !gphAutoColTnslVal, !gphAutoColEdgeOn) !tempArray[3] = !gphAutoColour
Xenobiologist Posted August 10, 2016 Posted August 10, 2016 You mean something like this? $re_A = StringSplit('02,1,10,11,3,15,16,17,2,3,4,5,6,7,8,9', ',' , 2) $re_A = _ArrayUnique($re_A) _ArraySortNum($re_A) _ArrayDisplay($re_A, "Sorted Array") Func _ArraySortNum(ByRef $n_array, $i_descending = 0, $i_start = 1) Local $i_ub = UBound($n_array) For $i_count = $i_start To $i_ub - 2 Local $i_se = $i_count If $i_descending Then For $x_count = $i_count To $i_ub - 1 If Number($n_array[$i_se]) < Number($n_array[$x_count]) Then $i_se = $x_count Next Else For $x_count = $i_count To $i_ub - 1 If Number($n_array[$i_se]) > Number($n_array[$x_count]) Then $i_se = $x_count Next EndIf Local $i_hld = $n_array[$i_count] $n_array[$i_count] = $n_array[$i_se] $n_array[$i_se] = $i_hld Next EndFunc ;==>_ArraySortNum Scripts & functions Organize Includes Let Scite organize the include files Yahtzee The game "Yahtzee" (Kniffel, DiceLion) LoginWrapper Secure scripts by adding a query (authentication) _RunOnlyOnThis UDF Make sure that a script can only be executed on ... (Windows / HD / ...) Internet-Café Server/Client Application Open CD, Start Browser, Lock remote client, etc. MultipleFuncsWithOneHotkey Start different funcs by hitting one hotkey different times
wklw2003 Posted August 10, 2016 Author Posted August 10, 2016 12 minutes ago, Xenobiologist said: You mean something like this? $re_A = StringSplit('02,1,10,11,3,15,16,17,2,3,4,5,6,7,8,9', ',' , 2) $re_A = _ArrayUnique($re_A) _ArraySortNum($re_A) _ArrayDisplay($re_A, "Sorted Array") Func _ArraySortNum(ByRef $n_array, $i_descending = 0, $i_start = 1) Local $i_ub = UBound($n_array) For $i_count = $i_start To $i_ub - 2 Local $i_se = $i_count If $i_descending Then For $x_count = $i_count To $i_ub - 1 If Number($n_array[$i_se]) < Number($n_array[$x_count]) Then $i_se = $x_count Next Else For $x_count = $i_count To $i_ub - 1 If Number($n_array[$i_se]) > Number($n_array[$x_count]) Then $i_se = $x_count Next EndIf Local $i_hld = $n_array[$i_count] $n_array[$i_count] = $n_array[$i_se] $n_array[$i_se] = $i_hld Next EndFunc ;==>_ArraySortNum How do I load the files so the temparray can be sorted? I can't bring the rules into AutoIT.
Xenobiologist Posted August 10, 2016 Posted August 10, 2016 I thought, you would read your stuff stuff into an array and then sort it. Scripts & functions Organize Includes Let Scite organize the include files Yahtzee The game "Yahtzee" (Kniffel, DiceLion) LoginWrapper Secure scripts by adding a query (authentication) _RunOnlyOnThis UDF Make sure that a script can only be executed on ... (Windows / HD / ...) Internet-Café Server/Client Application Open CD, Start Browser, Lock remote client, etc. MultipleFuncsWithOneHotkey Start different funcs by hitting one hotkey different times
wklw2003 Posted August 10, 2016 Author Posted August 10, 2016 2 minutes ago, Xenobiologist said: I thought, you would read your stuff stuff into an array and then sort it. I was wondering if the best way would be to create a file open dialog, click the file and have the array sort the temparray but I am not sure what to do.
Xenobiologist Posted August 10, 2016 Posted August 10, 2016 Then post a little file with content before and another file with the content after the sort. You may also describe what is neccessary to do the sort. Scripts & functions Organize Includes Let Scite organize the include files Yahtzee The game "Yahtzee" (Kniffel, DiceLion) LoginWrapper Secure scripts by adding a query (authentication) _RunOnlyOnThis UDF Make sure that a script can only be executed on ... (Windows / HD / ...) Internet-Café Server/Client Application Open CD, Start Browser, Lock remote client, etc. MultipleFuncsWithOneHotkey Start different funcs by hitting one hotkey different times
wklw2003 Posted August 10, 2016 Author Posted August 10, 2016 Here is the file, You can open it with Notepad. These are color rules... users will be sending me the rules. All the new rules will always start at 1... I need to marge all rules and have the !tempArray's in numeric order. These rule will change offen... I'll need to re-order them everytime they change.. If the !tempArray is not in numbered order the rules will not work. Thanks for your help... des-col.pmldat
jchd Posted August 10, 2016 Posted August 10, 2016 Looking quickly at the file posted, I don't understand the sort criterion. There are two entries with !tempArray[2] and when you are submitted new entries numbered at 1, will you just add them at the end (with incresing numbers) or is there another criterion to sort them? 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)
wklw2003 Posted August 10, 2016 Author Posted August 10, 2016 3 minutes ago, jchd said: Looking quickly at the file posted, I don't understand the sort criterion. There are two entries with !tempArray[2] and when you are submitted new entries numbered at 1, will you just add them at the end (with incresing numbers) or is there another criterion to sort them? sorry, that should be 1,2,3 but at his time all the numbers are mixed up and need to in order. once I get the rules from the users it will be in order. 1-200 from one group then 1-50 from another group... I need to marge them all together in a master file 1-250... I've been doing in manually, click on each temparray and typing 1,2,3 etc...
jchd Posted August 10, 2016 Posted August 10, 2016 I'd do it with an elaborate StringRegExpReplace, renumbering the file from 1 upwards. The only preliminary step is to remove the end lines from the old file and the head lines from the new file. Would that seem OK for you? 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)
wklw2003 Posted August 10, 2016 Author Posted August 10, 2016 7 minutes ago, jchd said: I'd do it with an elaborate StringRegExpReplace, renumbering the file from 1 upwards. The only preliminary step is to remove the end lines from the old file and the head lines from the new file. Would that seem OK for you? Sure, nothing I am doing is working...
jchd Posted August 10, 2016 Posted August 10, 2016 Here you are: Local $sText = FileRead("des-col.pmldat") Local $sTextNew = Execute("'" & StringRegExpReplace($sText, "(?m)(?<=^!tempArray\[)(\d+)(?=])", "' & _Increment() & '") & "'") FileDelete("des-col_new.pmldat") FileWrite("des-col_new.pmldat", $sTextNew) Func _Increment($reset = 0) Local Static $index = 1 If $reset Then $index = 1 $index += 1 Return $index - 1 EndFunc 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)
wklw2003 Posted August 10, 2016 Author Posted August 10, 2016 6 minutes ago, jchd said: Here you are: Local $sText = FileRead("des-col.pmldat") Local $sTextNew = Execute("'" & StringRegExpReplace($sText, "(?m)(?<=^!tempArray\[)(\d+)(?=])", "' & _Increment() & '") & "'") FileDelete("des-col_new.pmldat") FileWrite("des-col_new.pmldat", $sTextNew) Func _Increment($reset = 0) Local Static $index = 1 If $reset Then $index = 1 $index += 1 Return $index - 1 EndFunc Thanks, How does it know where the des-col.pmldat file is located?
kylomas Posted August 10, 2016 Posted August 10, 2016 ...Bowing to the master... Forum Rules Procedure for posting code "I like pigs. Dogs look up to us. Cats look down on us. Pigs treat us as equals." - Sir Winston Churchill
jchd Posted August 10, 2016 Posted August 10, 2016 Just adapt file names and pathes to your context. Please, don't bow to anyone. 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)
wklw2003 Posted August 11, 2016 Author Posted August 11, 2016 33 minutes ago, jchd said: Just adapt file names and pathes to your context. Please, don't bow to anyone. Local $sText = FileRead("C:\Users\Desktop\des-col.pmldat") Local $sTextNew = Execute("'" & StringRegExpReplace($sText, "(?m)(?<=^!tempArray\[)(\d+)(?=])", "' & _Increment() & '") & "'") FileDelete("C:\Users\Desktop\des-col_new.pmldat") FileWrite("C:\Users\Desktop\des-col_new.pmldat", $sTextNew) Func _Increment($reset = 0) Local Static $index = 1 If $reset Then $index = 1 $index += 1 Return $index - 1 EndFunc It's creating but the new file is empty. What am I missing?
jchd Posted August 11, 2016 Posted August 11, 2016 (edited) I have no idea. Try adding error checking and confirm there is no username in the middle of the path you intend to use (e.g. C:\Users\Frankenstein\Desktop\des-col.pmldat) 2:08 here --> bedtime! Bye. Edited August 11, 2016 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)
wklw2003 Posted August 11, 2016 Author Posted August 11, 2016 1 minute ago, jchd said: I have no idea. Try adding error checking and confirm there is no username in the middle of the path you intend to use (e.g. C:\Users\Frankenstein\Desktop\des-col.pmldat) Thanks for your help!!!!
wklw2003 Posted August 11, 2016 Author Posted August 11, 2016 2 minutes ago, wklw2003 said: Thanks for your help!!!! This is great.... I am going to have a drink in your honor!!!
wklw2003 Posted August 11, 2016 Author Posted August 11, 2016 3 hours ago, Xenobiologist said: Then post a little file with content before and another file with the content after the sort. You may also describe what is neccessary to do the sort. Thanks for your help on this issue.
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