Wombat Posted July 31, 2013 Share Posted July 31, 2013 (edited) I need a little guidence please. I'll explain more once I have made it home from work... until then here is my code: expandcollapse popup#include <ButtonConstants.au3> #include <EditConstants.au3> #include <GUIConstantsEx.au3> #include <StaticConstants.au3> #include <WindowsConstants.au3> #include <String.au3> #include <Array.au3> #include <File.au3> Opt("GUIOnEventMode", 1) ; GUI section starts here: $Form1 = GUICreate("M47 Tool", 460, 166, 287, 223) GUISetFont(10, 800, 0, "Franklin Gothic Medium Cond") GUISetOnEvent($GUI_EVENT_CLOSE, "Close_M47_Tool") $Input1 = GUICtrlCreateInput(". . .", 176, 72, 265, 25) $AddButton = GUICtrlCreateButton("Add", 176, 112, 121, 41) GUICtrlSetOnEvent ( -1, "Add_M47") $RemoveButton = GUICtrlCreateButton("Remove", 320, 112, 121, 41) GUICtrlSetOnEvent (-1, "Remove_M47") $Label1 = GUICtrlCreateLabel("Drag and Drop File here:", 16, 72, 143, 21) $Label2 = GUICtrlCreateLabel("This tool will add the M47 code to your programs", 98, 8, 281, 21) Local $LSTtoEDIT GUISetState(@SW_SHOW) ; GUI section ends here. ;;;;;;;;;;;;;;;;;;;;; While 1 WEnd Func Close_M47_Tool() Exit EndFunc Func Add_M47() Local $Find = "M0" Local $Replace = "WORKING SO FAR" $ReadInput1 = GUICtrlRead($Input1) _FileReadToArray ($ReadInput1, $LSTtoEDIT) _ArrayToString ($LSTtoEDIT) _ReplaceStringInFile ($ReadInput1, $Find, $Replace, 0, 0) EndFunc Func Remove_M47() Local $Find = "WORKING SO FAR" Local $Replace = "M0" $ReadInput1 = GUICtrlRead($Input1) _FileReadToArray ($ReadInput1, $LSTtoEDIT) _ArrayToString ($LSTtoEDIT) _ReplaceStringInFile ($ReadInput1, $Find, $Replace, 0, 0) Exit EndFunc Alrighty, so here's what I'm needing help with. I need to be able to take a .lst file (basically a .txt file) and search for the M0 that occurs in the file. The thing is the line will look like so: N24M08N25M67 N26M0 N27M45 ...without the colors or boldness of course (1)The numbers in red will not always be the same, so i need a way to find this line even if its: N34M0 or N500M0 (2)The _ReplaceStringInFile picks up strings such as the one in purple due to it containing M0 within it when I need it to seek out only lines that contain exactly N**M0 (*=whatever number this may be) Can anyone shed some light on this for me? please and thank you Edited July 31, 2013 by Wombat Just look at us.Everything is backwards; everything is upside down. Doctors destroy health. Lawyers destroy justice. Universities destroy knowledge. Governments destroy freedom. The major media destroy information and religions destroy spirituality. ~ Michael Ellner The internet is our one and only hope at a truly free world, do not let them take it from us... Link to comment Share on other sites More sharing options...
Anas Posted July 31, 2013 Share Posted July 31, 2013 (edited) StringRegExp(..., '(?i)' & 'Nd{1,}M0') EDIT: you can replace all matches using FileRead and StringRegExpReplace. Edited July 31, 2013 by Anas Link to comment Share on other sites More sharing options...
Edano Posted July 31, 2013 Share Posted July 31, 2013 (edited) i would do this: . Func Add_M47() Local $Find = "M0" Local $Replace = "WORKING SO FAR" $ReadInput1 = GUICtrlRead($Input1) $file=FileRead($ReadInput1) $file=StringReplace($file,$Find&@CRLF,$Replace&@CRLF) $open=FileOpen($ReadInput1,2) FileWrite($open,$file) FileClose($open) EndFunc E . Edit: this works for all "M0" at end of line. Edit: line breaks are also possible by only @cr or @lf, but mostly @crlf Edited July 31, 2013 by Edano Wombat 1 [color=rgb(255,0,0);][font="'comic sans ms', cursive;"]FukuLeaks[/color][/font] Link to comment Share on other sites More sharing options...
Wombat Posted July 31, 2013 Author Share Posted July 31, 2013 (edited) Maybe I should explain exactly what I'm trying to accomplish. Example: Say we have a .lst file that looks like this= N01M67 N02M34 N03M02 N04M11 N05M0 N06M12 I need the code to edit it as such= N01M67 N02M34 N03M02 N04M11 N04.1M47 N05M0 N06M12 in g-code (which is machine code for punches, presses, etc) an N stands for a block of code (a flag if you will), and this particular machine uses a list of codes to process certain functions such as M67 might open its clamps, or M11 might increase pressure during punching. I need the script to find the M0 code on whatever N block it may be on whether its N24 or N01 and add a new block above it containing the M47 code while taking the N blocks number (in the example given it is N05) and reducing it by .9 so thatN24M0 Would become:N23.1M47 N24M0 I have to retain the M0 code and ADD the M47 code directly above it whilst also making the N block's number .9 less than the N block for the M0 code. I know this is possible, but I cannot find the proper way to accomplish it, and yes have and am still tearing through the help file and checking old posts here at the forum (some are very old lol) Edited July 31, 2013 by Wombat Just look at us.Everything is backwards; everything is upside down. Doctors destroy health. Lawyers destroy justice. Universities destroy knowledge. Governments destroy freedom. The major media destroy information and religions destroy spirituality. ~ Michael Ellner The internet is our one and only hope at a truly free world, do not let them take it from us... Link to comment Share on other sites More sharing options...
Moderators Melba23 Posted July 31, 2013 Moderators Share Posted July 31, 2013 Wombat,I did something very similar to this a while ago when I was asked to amend the code for a large routing machine making kitchen cabinets. I needed to intercept and modify the code between the pattern software script producer and the router itself. It worked but alas the modifications requested did not have the required effect on the overall speed of the process. This looks a very similar task. Let me dig out the code, see how I did it then and look at how it can be modified - can you wait until tomorrow? 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...
Wombat Posted July 31, 2013 Author Share Posted July 31, 2013 I can wait til whenever, I'm using it as a simple tool for our machinists to quickly and effortlessly add this code to their programs. Thank you for the reply btw Just look at us.Everything is backwards; everything is upside down. Doctors destroy health. Lawyers destroy justice. Universities destroy knowledge. Governments destroy freedom. The major media destroy information and religions destroy spirituality. ~ Michael Ellner The internet is our one and only hope at a truly free world, do not let them take it from us... Link to comment Share on other sites More sharing options...
Moderators Melba23 Posted July 31, 2013 Moderators Share Posted July 31, 2013 Wombat,That was easier than I remembered. I hope this does the trick: #include <Array.au3> ; Simulate reading the file into an array $sText = "N01M67" & @CRLF & _ "N24M08" & @CRLF & _ "N24M0" & @CRLF & _ "N04M11" & @CRLF & _ "N05M0" & @CRLF & _ "N06M12" $aLines = StringSplit($sText, @CRLF, 1) _ArrayDisplay($aLines, "Original") For $i = UBound($aLines) - 1 To 1 Step -1 ; Loop upwards through the array to maintain the index values ; Read current line $sLine = $aLines[$i] ; Check for M0 at end of line If StringRegExp($sLine, "^.*M0$") Then ; Extract digits and subtract 0.9 $nDigits = Number(StringRegExpReplace($sLine, "^\D+(\d+)M0$", "$1")) - 0.9 ; Insert new line at current point and increase line count _ArrayInsert($aLines, $i, "N" & $nDigits & "M47") $aLines[0] += 1 ; Display amended array _ArrayDisplay($aLines, "Inserted") EndIf Next ; Final result _ArrayDisplay($aLines, "Final")For me that fires on the lines N24M0 and N05M0, but does not fire for N24M08.Good enough? M23 Wombat 1 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...
kylomas Posted July 31, 2013 Share Posted July 31, 2013 @M23 - very slick If I may, you might want to normalize EOL's before the stringsplit like this $str = StringRegExpReplace($str, '\R', @CRLF) P.S. I coded another solution but it is embarrassed to be seen by yours. kylomas 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 Link to comment Share on other sites More sharing options...
guinness Posted July 31, 2013 Share Posted July 31, 2013 (edited) $str = StringRegExpReplace($str, 'R', @CRLF)Did you know that already? Or have you been paying attention? Edited July 31, 2013 by guinness UDF List: _AdapterConnections() • _AlwaysRun() • _AppMon() • _AppMonEx() • _ArrayFilter/_ArrayReduce • _BinaryBin() • _CheckMsgBox() • _CmdLineRaw() • _ContextMenu() • _ConvertLHWebColor()/_ConvertSHWebColor() • _DesktopDimensions() • _DisplayPassword() • _DotNet_Load()/_DotNet_Unload() • _Fibonacci() • _FileCompare() • _FileCompareContents() • _FileNameByHandle() • _FilePrefix/SRE() • _FindInFile() • _GetBackgroundColor()/_SetBackgroundColor() • _GetConrolID() • _GetCtrlClass() • _GetDirectoryFormat() • _GetDriveMediaType() • _GetFilename()/_GetFilenameExt() • _GetHardwareID() • _GetIP() • _GetIP_Country() • _GetOSLanguage() • _GetSavedSource() • _GetStringSize() • _GetSystemPaths() • _GetURLImage() • _GIFImage() • _GoogleWeather() • _GUICtrlCreateGroup() • _GUICtrlListBox_CreateArray() • _GUICtrlListView_CreateArray() • _GUICtrlListView_SaveCSV() • _GUICtrlListView_SaveHTML() • _GUICtrlListView_SaveTxt() • _GUICtrlListView_SaveXML() • _GUICtrlMenu_Recent() • _GUICtrlMenu_SetItemImage() • _GUICtrlTreeView_CreateArray() • _GUIDisable() • _GUIImageList_SetIconFromHandle() • _GUIRegisterMsg() • _GUISetIcon() • _Icon_Clear()/_Icon_Set() • _IdleTime() • _InetGet() • _InetGetGUI() • _InetGetProgress() • _IPDetails() • _IsFileOlder() • _IsGUID() • _IsHex() • _IsPalindrome() • _IsRegKey() • _IsStringRegExp() • _IsSystemDrive() • _IsUPX() • _IsValidType() • _IsWebColor() • _Language() • _Log() • _MicrosoftInternetConnectivity() • _MSDNDataType() • _PathFull/GetRelative/Split() • _PathSplitEx() • _PrintFromArray() • _ProgressSetMarquee() • _ReDim() • _RockPaperScissors()/_RockPaperScissorsLizardSpock() • _ScrollingCredits • _SelfDelete() • _SelfRename() • _SelfUpdate() • _SendTo() • _ShellAll() • _ShellFile() • _ShellFolder() • _SingletonHWID() • _SingletonPID() • _Startup() • _StringCompact() • _StringIsValid() • _StringRegExpMetaCharacters() • _StringReplaceWholeWord() • _StringStripChars() • _Temperature() • _TrialPeriod() • _UKToUSDate()/_USToUKDate() • _WinAPI_Create_CTL_CODE() • _WinAPI_CreateGUID() • _WMIDateStringToDate()/_DateToWMIDateString() • Au3 script parsing • AutoIt Search • AutoIt3 Portable • AutoIt3WrapperToPragma • AutoItWinGetTitle()/AutoItWinSetTitle() • Coding • DirToHTML5 • FileInstallr • FileReadLastChars() • GeoIP database • GUI - Only Close Button • GUI Examples • GUICtrlDeleteImage() • GUICtrlGetBkColor() • GUICtrlGetStyle() • GUIEvents • GUIGetBkColor() • Int_Parse() & Int_TryParse() • IsISBN() • LockFile() • Mapping CtrlIDs • OOP in AutoIt • ParseHeadersToSciTE() • PasswordValid • PasteBin • Posts Per Day • PreExpand • Protect Globals • Queue() • Resource Update • ResourcesEx • SciTE Jump • Settings INI • SHELLHOOK • Shunting-Yard • Signature Creator • Stack() • Stopwatch() • StringAddLF()/StringStripLF() • StringEOLToCRLF() • VSCROLL • WM_COPYDATA • More Examples... Updated: 22/04/2018 Link to comment Share on other sites More sharing options...
kylomas Posted July 31, 2013 Share Posted July 31, 2013 (edited) guinness, I dug it out of the topic you have in the Examples section. edit: Hopefully I'm always paying attention. Something you want to tell me? Edited July 31, 2013 by kylomas 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 Link to comment Share on other sites More sharing options...
jchd Posted July 31, 2013 Share Posted July 31, 2013 (edited) As a one-liner: EDIT: removed Number() as it isn't useful. Local $s = "N01M67" & @CRLF & "N02M34" & @CRLF & "N03M02" & @CRLF & "N04M11" & @CRLF & "N05M0" & @CRLF & "N06M12" & @CRLF $t = Execute("'" & StringRegExpReplace($s, "(?m)(N\d+M\d+\R)N(\d+)(M0\R)", "$1N' & StringFormat('%04.1f', $2 - 0.9) & 'M47" & @CRLF & "N$2$3") & "'") ConsoleWrite($t) Edited July 31, 2013 by jchd 0xdefea7 and Wombat 2 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...
kylomas Posted July 31, 2013 Share Posted July 31, 2013 As a one-liner: Local $s = "N01M67" & @CRLF & "N02M34" & @CRLF & "N03M02" & @CRLF & "N04M11" & @CRLF & "N05M0" & @CRLF & "N06M12" & @CRLF $t = Execute("'" & StringRegExpReplace($s, "(?m)(N\d+M\d+\R)N(\d+)(M0\R)", "$1N' & StringFormat('%04.1f', Number($2) - 0.9) & 'M47" & @CRLF & "N$2$3") & "'") ConsoleWrite($t) *sigh* The code I wrote just booked passage out of the country... 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 Link to comment Share on other sites More sharing options...
guinness Posted July 31, 2013 Share Posted July 31, 2013 Something you want to tell me? Just happy! UDF List: _AdapterConnections() • _AlwaysRun() • _AppMon() • _AppMonEx() • _ArrayFilter/_ArrayReduce • _BinaryBin() • _CheckMsgBox() • _CmdLineRaw() • _ContextMenu() • _ConvertLHWebColor()/_ConvertSHWebColor() • _DesktopDimensions() • _DisplayPassword() • _DotNet_Load()/_DotNet_Unload() • _Fibonacci() • _FileCompare() • _FileCompareContents() • _FileNameByHandle() • _FilePrefix/SRE() • _FindInFile() • _GetBackgroundColor()/_SetBackgroundColor() • _GetConrolID() • _GetCtrlClass() • _GetDirectoryFormat() • _GetDriveMediaType() • _GetFilename()/_GetFilenameExt() • _GetHardwareID() • _GetIP() • _GetIP_Country() • _GetOSLanguage() • _GetSavedSource() • _GetStringSize() • _GetSystemPaths() • _GetURLImage() • _GIFImage() • _GoogleWeather() • _GUICtrlCreateGroup() • _GUICtrlListBox_CreateArray() • _GUICtrlListView_CreateArray() • _GUICtrlListView_SaveCSV() • _GUICtrlListView_SaveHTML() • _GUICtrlListView_SaveTxt() • _GUICtrlListView_SaveXML() • _GUICtrlMenu_Recent() • _GUICtrlMenu_SetItemImage() • _GUICtrlTreeView_CreateArray() • _GUIDisable() • _GUIImageList_SetIconFromHandle() • _GUIRegisterMsg() • _GUISetIcon() • _Icon_Clear()/_Icon_Set() • _IdleTime() • _InetGet() • _InetGetGUI() • _InetGetProgress() • _IPDetails() • _IsFileOlder() • _IsGUID() • _IsHex() • _IsPalindrome() • _IsRegKey() • _IsStringRegExp() • _IsSystemDrive() • _IsUPX() • _IsValidType() • _IsWebColor() • _Language() • _Log() • _MicrosoftInternetConnectivity() • _MSDNDataType() • _PathFull/GetRelative/Split() • _PathSplitEx() • _PrintFromArray() • _ProgressSetMarquee() • _ReDim() • _RockPaperScissors()/_RockPaperScissorsLizardSpock() • _ScrollingCredits • _SelfDelete() • _SelfRename() • _SelfUpdate() • _SendTo() • _ShellAll() • _ShellFile() • _ShellFolder() • _SingletonHWID() • _SingletonPID() • _Startup() • _StringCompact() • _StringIsValid() • _StringRegExpMetaCharacters() • _StringReplaceWholeWord() • _StringStripChars() • _Temperature() • _TrialPeriod() • _UKToUSDate()/_USToUKDate() • _WinAPI_Create_CTL_CODE() • _WinAPI_CreateGUID() • _WMIDateStringToDate()/_DateToWMIDateString() • Au3 script parsing • AutoIt Search • AutoIt3 Portable • AutoIt3WrapperToPragma • AutoItWinGetTitle()/AutoItWinSetTitle() • Coding • DirToHTML5 • FileInstallr • FileReadLastChars() • GeoIP database • GUI - Only Close Button • GUI Examples • GUICtrlDeleteImage() • GUICtrlGetBkColor() • GUICtrlGetStyle() • GUIEvents • GUIGetBkColor() • Int_Parse() & Int_TryParse() • IsISBN() • LockFile() • Mapping CtrlIDs • OOP in AutoIt • ParseHeadersToSciTE() • PasswordValid • PasteBin • Posts Per Day • PreExpand • Protect Globals • Queue() • Resource Update • ResourcesEx • SciTE Jump • Settings INI • SHELLHOOK • Shunting-Yard • Signature Creator • Stack() • Stopwatch() • StringAddLF()/StringStripLF() • StringEOLToCRLF() • VSCROLL • WM_COPYDATA • More Examples... Updated: 22/04/2018 Link to comment Share on other sites More sharing options...
Wombat Posted July 31, 2013 Author Share Posted July 31, 2013 How would I make it so that it only looks for the first M0 in the file and adds the M4 above it and not any others? Also, this did not write anything to the console: Func Add_M47() $ReadInput1 = GUICtrlRead($Input1) _FileReadToArray ($ReadInput1, $sText) $t = Execute("'" & StringRegExpReplace($sText, "(?m)(N\d+M\d+\R)N(\d+)(M0\R)", "$1N' & StringFormat('%04.1f', $2 - 0.9) & 'M47" & @CRLF & "N$2$3") & "'") ConsoleWrite($t) EndFunc Sorry for the short posts, I'm working on this while working on the machine as well. Thank you all for being so very helpful, I really do appreciate it! Just look at us.Everything is backwards; everything is upside down. Doctors destroy health. Lawyers destroy justice. Universities destroy knowledge. Governments destroy freedom. The major media destroy information and religions destroy spirituality. ~ Michael Ellner The internet is our one and only hope at a truly free world, do not let them take it from us... Link to comment Share on other sites More sharing options...
jchd Posted July 31, 2013 Share Posted July 31, 2013 (edited) It's a matter of specifying that you want only 1 replacement done: Func Add_M47() Local $ReadInput1 = GUICtrlRead($Input1) Local $sText = FileRead($ReadInput1) Local $sTextM47 = Execute("'" & StringRegExpReplace($sText, "(?m)(N\d+M\d+\R)N(\d+)(M0\R)", "$1N' & StringFormat('%04.1f', $2 - 0.9) & 'M47" & @CRLF & "N$2$3", 1) & "'") MsgBox(0, "Only first M47 added", $sTextM47) ; do whatever you want with the modified text EndFunc This code processes the text as a single block. It doesn't load lines into an array. ConsoleWrite only writes data to the Scite console for uncompiled scripts. This MsgBox should work better for you, provided your text is not too long to fit in the box. Edited July 31, 2013 by jchd Wombat 1 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...
jchd Posted July 31, 2013 Share Posted July 31, 2013 I just forgot to mention that this code won't work if the M0 line is the very first line in the file. If that is an issue, just add a question mark in the pattern after the first capture, like that: Func Add_M47() Local $ReadInput1 = GUICtrlRead($Input1) Local $sText = FileRead($ReadInput1) Local $sTextM47 = Execute("'" & StringRegExpReplace($sText, "(?m)(N\d+M\d+\R)?N(\d+)(M0\R)", "$1N' & StringFormat('%04.1f', $2 - 0.9) & 'M47" & @CRLF & "N$2$3", 1) & "'") MsgBox(0, "Only first M47 added", $sTextM47) ; do whatever you want with the modified text EndFunc Wombat 1 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...
Wombat Posted August 1, 2013 Author Share Posted August 1, 2013 I just forgot to mention that this code won't work if the M0 line is the very first line in the file. If that is an issue, just add a question mark in the pattern after the first capture, like that: Func Add_M47() Local $ReadInput1 = GUICtrlRead($Input1) Local $sText = FileRead($ReadInput1) Local $sTextM47 = Execute("'" & StringRegExpReplace($sText, "(?m)(N\d+M\d+\R)?N(\d+)(M0\R)", "$1N' & StringFormat('%04.1f', $2 - 0.9) & 'M47" & @CRLF & "N$2$3", 1) & "'") MsgBox(0, "Only first M47 added", $sTextM47) ; do whatever you want with the modified text EndFunc It wont be, and thank you for the condensed version. Now to implement test, debug, and returns with the results Just look at us.Everything is backwards; everything is upside down. Doctors destroy health. Lawyers destroy justice. Universities destroy knowledge. Governments destroy freedom. The major media destroy information and religions destroy spirituality. ~ Michael Ellner The internet is our one and only hope at a truly free world, do not let them take it from us... Link to comment Share on other sites More sharing options...
Wombat Posted August 1, 2013 Author Share Posted August 1, 2013 (edited) Here's what I've got so far: expandcollapse popup#include <ButtonConstants.au3> #include <EditConstants.au3> #include <GUIConstantsEx.au3> #include <StaticConstants.au3> #include <WindowsConstants.au3> #include <String.au3> #include <Array.au3> #include <File.au3> Opt("GUIOnEventMode", 1) ; GUI section starts here: $GUI = GUICreate("M47 Tool", 509, 136, 340, 175) GUISetIcon("C:\prog_res\Lab\test_res\config.ico", -1) GUISetOnEvent($GUI_EVENT_CLOSE, "Close_M47_Tool") $Input1 = GUICtrlCreateInput("", 92, 56, 329, 21) $Label1 = GUICtrlCreateLabel("Use this tool to add or remove the M47 code from a program", 11, 16, 486, 24) GUICtrlSetFont(-1, 12, 800, 0, "MS Sans Serif") $Button1 = GUICtrlCreateButton("Add M47", 88, 88, 161, 41) GUICtrlSetCursor (-1, 0) GUICtrlSetOnEvent(-1, "Add_M47") $Button2 = GUICtrlCreateButton("Remove M47", 260, 88, 161, 41) GUICtrlSetCursor (-1, 0) GUICtrlSetOnEvent(-1, "Remove_M47") $Icon1 = GUICtrlCreateIcon("C:\prog_res\Lab\test_res\SysReqMet.ico", -1, 64, 56, 24, 24) GUICtrlSetTip(-1, "Program does contain M47") $Icon2 = GUICtrlCreateIcon("C:\prog_res\Lab\test_res\Error.ico", -1, 40, 56, 24, 24) GUICtrlSetTip(-1, "Program does not contain M47") $Button3 = GUICtrlCreateButton("", 440, 48, 49, 41, $BS_ICON) GUICtrlSetImage(-1, "C:\prog_res\Lab\test_res\reload%2032.ico", -1) GUICtrlSetTip(-1, "Reload Tool") GUICtrlSetCursor (-1, 0) GUICtrlSetOnEvent(-1, "Tool_Reload") $Button4 = GUICtrlCreateButton("?", 456, 104, 33, 25, $BS_PUSHBOX) GUICtrlSetFont(-1, 12, 800, 0, "MS Sans Serif") GUICtrlSetColor(-1, 0xFFFF00) GUICtrlSetTip(-1, "Open the Help file") GUICtrlSetCursor (-1, 4) GUICtrlSetOnEvent(-1, "Open_Help") Local $sText GUISetState(@SW_SHOW) ; GUI section ends here. ;;;;;;;;;;;;;;;;;;;;; While 1 WEnd Func Input_Prog_Check(); Checks the program for the M47 code and displays either an error icon or success icon EndFunc Func Close_M47_Tool(); CLoses the Tool Exit EndFunc Func Add_M47(); This function adds the M47 code to the program Local $ReadInput1 = GUICtrlRead($Input1) Local $sText = FileRead($ReadInput1) Local $sTextM47 = Execute("'" & StringRegExpReplace($sText, "(?m)(N\d+M\d+\R)?N(\d+)(M0\R)", "$1N' & StringFormat('%04.1f', $2 - 0.9) & 'M47" & @CRLF & "N$2$3", 1) & "'") FileDelete ($ReadInput1) FileWrite ($ReadInput1, $sTextM47) EndFunc Func Remove_M47(); This function removes the M47 code from the program EndFunc Func Tool_Reload(); This function clears the $ReadInput1 var GUICtrlSetData ($Input1, "") EndFunc Func Open_Help(); The function opens the help file to aid the user in adding or removing the M47 code EndFunc Next, I need to know if there is, and if so how, anyway to make Input1 get the file path via dragging and dropping a file onto it? As well as, how can I make it check the .lst for the M47 code immediately after the data for it is changed so that the tool can inform the user whether it already has it or not? Edit: also, that code does exactly what I need it to! Edited August 1, 2013 by Wombat Just look at us.Everything is backwards; everything is upside down. Doctors destroy health. Lawyers destroy justice. Universities destroy knowledge. Governments destroy freedom. The major media destroy information and religions destroy spirituality. ~ Michael Ellner The internet is our one and only hope at a truly free world, do not let them take it from us... Link to comment Share on other sites More sharing options...
Wombat Posted August 1, 2013 Author Share Posted August 1, 2013 (edited) So I figured out the Drag and Drop (with the >help of Melba23, thank you for everything you do here!) expandcollapse popup#include <ButtonConstants.au3> #include <EditConstants.au3> #include <GUIConstantsEx.au3> #include <StaticConstants.au3> #include <WindowsConstants.au3> #include <String.au3> #include <Array.au3> #include <File.au3> Opt("GUIOnEventMode", 1) ; GUI section starts here: $GUI = GUICreate("M47 Tool", 509, 136, 340, 175, Default, $WS_EX_ACCEPTFILES) GUISetIcon("C:\prog_res\Lab\test_res\config.ico", -1) GUISetOnEvent($GUI_EVENT_CLOSE, "Close_M47_Tool") $Input1 = GUICtrlCreateInput("", 92, 56, 329, 21) $Label1 = GUICtrlCreateLabel("Use this tool to add or remove the M47 code from a program", 11, 16, 486, 24) GUICtrlSetFont(-1, 12, 800, 0, "MS Sans Serif") $Button1 = GUICtrlCreateButton("Add M47", 88, 88, 161, 41) GUICtrlSetCursor (-1, 0) GUICtrlSetOnEvent(-1, "Add_M47") $Button2 = GUICtrlCreateButton("Remove M47", 260, 88, 161, 41) GUICtrlSetCursor (-1, 0) GUICtrlSetOnEvent(-1, "Remove_M47") $Button3 = GUICtrlCreateButton("", 440, 48, 49, 41, $BS_ICON) GUICtrlSetImage(-1, "C:\prog_res\Lab\test_res\reload%2032.ico", -1) GUICtrlSetTip(-1, "Reload Tool") GUICtrlSetCursor (-1, 0) GUICtrlSetOnEvent(-1, "Tool_Reload") $Button4 = GUICtrlCreateButton("?", 456, 104, 33, 25, $BS_PUSHBOX) GUICtrlSetFont(-1, 12, 800, 0, "MS Sans Serif") GUICtrlSetColor(-1, 0xFFFF00) GUICtrlSetBkColor(-1, 0xD4D0C8) GUICtrlSetTip(-1, "Open the Help file") GUICtrlSetCursor (-1, 4) GUICtrlSetOnEvent(-1, "Open_Help") $Graphic1 = GUICtrlCreateGraphic(48, 48, 40, 41) GUICtrlSetGraphic(-1, $GUI_GR_ELLIPSE, 5, 4, 30, 31) $cDrop_Dummy = GUICtrlCreateDummy() GUICtrlSetOnEvent(-1, "_On_Drop") Local $sText Global $aDrop_List GUISetState(@SW_SHOW) ; GUI section ends here. ;;;;;;;;;;;;;;;;;;;;; ; Register $WM_DROPFILES function to detect drops anywhere on the GUI <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<< GUIRegisterMsg(0x233, "On_WM_DROPFILES") ; $WM_DROPFILES ;;;;;;;;;;;;;;;;;;;; While 1 WEnd Func _On_Drop() ; <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<< For $i = 1 To $aDrop_List[0] GUICtrlSetData($Input1, $aDrop_List[$i]) Next EndFunc ;==>_On_Drop Func Input_Prog_Check(); Checks the program for the M47 code and displays either an error icon or success icon EndFunc Func Close_M47_Tool(); CLoses the Tool Exit EndFunc Func Add_M47(); This function adds the M47 code to the program Local $ReadInput1 = GUICtrlRead($Input1) Local $sText = FileRead($ReadInput1) Local $sTextM47 = Execute("'" & StringRegExpReplace($sText, "(?m)(N\d+M\d+\R)?N(\d+)(M0\R)", "$1N' & StringFormat('%04.1f', $2 - 0.9) & 'M47" & @CRLF & "N$2$3", 1) & "'") FileDelete ($ReadInput1) FileWrite ($ReadInput1, $sTextM47) EndFunc Func Remove_M47(); This function removes the M47 code from the program EndFunc Func Tool_Reload(); This function clears the $ReadInput1 var GUICtrlSetData ($Input1, "") EndFunc Func Open_Help(); The function opens the help file to aid the user in adding or removing the M47 code $Form2 = GUICreate("Form2", 665, 834, 484, 50) GUISetOnEvent($GUI_EVENT_CLOSE, "Help_window_close") GUISetIcon("C:\prog_res\Lab\test_res\config.ico", -1) $Label1 = GUICtrlCreateLabel("M47 Help Window", 225, 8, 215, 33) GUICtrlSetFont(-1, 18, 800, 0, "MS Sans Serif") GUICtrlSetColor(-1, 0xFFFF00) GUICtrlSetBkColor(-1, 0xA0A0A4) $Pic1 = GUICtrlCreatePic("C:\prog_res\Lab\test_res\ScreenCap.bmp", 8, 56, 649, 363) $Label2 = GUICtrlCreateLabel("1: Indicates that the loaded program contains the M47 code", 59, 472, 476, 25) GUICtrlSetFont(-1, 12, 800, 0, "Franklin Gothic Medium") GUICtrlSetColor(-1, 0xFF0000) $Label3 = GUICtrlCreateLabel("2: Indicates that the Loaded Program does not contain the M47 code", 59, 519, 544, 25) GUICtrlSetFont(-1, 12, 800, 0, "Franklin Gothic Medium") GUICtrlSetColor(-1, 0xFF0000) $Label4 = GUICtrlCreateLabel("3: Use this button to add the M47 code", 59, 566, 312, 25) GUICtrlSetFont(-1, 12, 800, 0, "Franklin Gothic Medium") GUICtrlSetColor(-1, 0xFF0000) $Label5 = GUICtrlCreateLabel("4: Use this button to remove the M47 code", 59, 613, 338, 25) GUICtrlSetFont(-1, 12, 800, 0, "Franklin Gothic Medium") GUICtrlSetColor(-1, 0xFF0000) $Label6 = GUICtrlCreateLabel("5: Use this button to access the Help Window", 59, 660, 359, 25) GUICtrlSetFont(-1, 12, 800, 0, "Franklin Gothic Medium") GUICtrlSetColor(-1, 0xFF0000) $Label7 = GUICtrlCreateLabel("6: Use this button to reset the M47 Tool Window", 59, 707, 382, 25) GUICtrlSetFont(-1, 12, 800, 0, "Franklin Gothic Medium") GUICtrlSetColor(-1, 0xFF0000) $Label8 = GUICtrlCreateLabel("7: Either type in the full path, or drag and drop the file here", 59, 754, 644, 25) GUICtrlSetFont(-1, 12, 800, 0, "Franklin Gothic Medium") GUICtrlSetColor(-1, 0xFF0000) GUISetState(@SW_SHOW) EndFunc Func Help_window_close() GUIDelete ("M47 Help Window") EndFunc ; React to items dropped on the GUI <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<< Func On_WM_DROPFILES($hWnd, $iMsg, $wParam, $lParam) ; Credit to ProgAndy for DLL calls #forceref $hWnd, $iMsg, $lParam Local $iSize, $pFileName ; Get number of files dropped Local $aRet = DllCall("shell32.dll", "int", "DragQueryFileW", "hwnd", $wParam, "int", 0xFFFFFFFF, "ptr", 0, "int", 0) ; Reset array to correct size Global $aDrop_List[$aRet[0] + 1] = [$aRet[0]] ; And add item names For $i = 0 To $aRet[0] - 1 $aRet = DllCall("shell32.dll", "int", "DragQueryFileW", "hwnd", $wParam, "int", $i, "ptr", 0, "int", 0) $iSize = $aRet[0] + 1 $pFileName = DllStructCreate("wchar[" & $iSize & "]") DllCall("shell32.dll", "int", "DragQueryFileW", "hwnd", $wParam, "int", $i, "ptr", DllStructGetPtr($pFileName), "int", $iSize) $aDrop_List[$i + 1] = DllStructGetData($pFileName, 1) $pFileName = 0 Next ; Send the count to trigger the drop function in the main loop GUICtrlSendToDummy($cDrop_Dummy, $aDrop_List[0]) EndFunc ;==>On_WM_DROPFILES;;;; credit: Melba23 This really is a hidden jewel of a community Now all i need help with is how to search the file to see if the M47 code is already in the file... Edited August 1, 2013 by Wombat Just look at us.Everything is backwards; everything is upside down. Doctors destroy health. Lawyers destroy justice. Universities destroy knowledge. Governments destroy freedom. The major media destroy information and religions destroy spirituality. ~ Michael Ellner The internet is our one and only hope at a truly free world, do not let them take it from us... Link to comment Share on other sites More sharing options...
guinness Posted August 1, 2013 Share Posted August 1, 2013 Do you intend for this to work for future versions of AutoIt? UDF List: _AdapterConnections() • _AlwaysRun() • _AppMon() • _AppMonEx() • _ArrayFilter/_ArrayReduce • _BinaryBin() • _CheckMsgBox() • _CmdLineRaw() • _ContextMenu() • _ConvertLHWebColor()/_ConvertSHWebColor() • _DesktopDimensions() • _DisplayPassword() • _DotNet_Load()/_DotNet_Unload() • _Fibonacci() • _FileCompare() • _FileCompareContents() • _FileNameByHandle() • _FilePrefix/SRE() • _FindInFile() • _GetBackgroundColor()/_SetBackgroundColor() • _GetConrolID() • _GetCtrlClass() • _GetDirectoryFormat() • _GetDriveMediaType() • _GetFilename()/_GetFilenameExt() • _GetHardwareID() • _GetIP() • _GetIP_Country() • _GetOSLanguage() • _GetSavedSource() • _GetStringSize() • _GetSystemPaths() • _GetURLImage() • _GIFImage() • _GoogleWeather() • _GUICtrlCreateGroup() • _GUICtrlListBox_CreateArray() • _GUICtrlListView_CreateArray() • _GUICtrlListView_SaveCSV() • _GUICtrlListView_SaveHTML() • _GUICtrlListView_SaveTxt() • _GUICtrlListView_SaveXML() • _GUICtrlMenu_Recent() • _GUICtrlMenu_SetItemImage() • _GUICtrlTreeView_CreateArray() • _GUIDisable() • _GUIImageList_SetIconFromHandle() • _GUIRegisterMsg() • _GUISetIcon() • _Icon_Clear()/_Icon_Set() • _IdleTime() • _InetGet() • _InetGetGUI() • _InetGetProgress() • _IPDetails() • _IsFileOlder() • _IsGUID() • _IsHex() • _IsPalindrome() • _IsRegKey() • _IsStringRegExp() • _IsSystemDrive() • _IsUPX() • _IsValidType() • _IsWebColor() • _Language() • _Log() • _MicrosoftInternetConnectivity() • _MSDNDataType() • _PathFull/GetRelative/Split() • _PathSplitEx() • _PrintFromArray() • _ProgressSetMarquee() • _ReDim() • _RockPaperScissors()/_RockPaperScissorsLizardSpock() • _ScrollingCredits • _SelfDelete() • _SelfRename() • _SelfUpdate() • _SendTo() • _ShellAll() • _ShellFile() • _ShellFolder() • _SingletonHWID() • _SingletonPID() • _Startup() • _StringCompact() • _StringIsValid() • _StringRegExpMetaCharacters() • _StringReplaceWholeWord() • _StringStripChars() • _Temperature() • _TrialPeriod() • _UKToUSDate()/_USToUKDate() • _WinAPI_Create_CTL_CODE() • _WinAPI_CreateGUID() • _WMIDateStringToDate()/_DateToWMIDateString() • Au3 script parsing • AutoIt Search • AutoIt3 Portable • AutoIt3WrapperToPragma • AutoItWinGetTitle()/AutoItWinSetTitle() • Coding • DirToHTML5 • FileInstallr • FileReadLastChars() • GeoIP database • GUI - Only Close Button • GUI Examples • GUICtrlDeleteImage() • GUICtrlGetBkColor() • GUICtrlGetStyle() • GUIEvents • GUIGetBkColor() • Int_Parse() & Int_TryParse() • IsISBN() • LockFile() • Mapping CtrlIDs • OOP in AutoIt • ParseHeadersToSciTE() • PasswordValid • PasteBin • Posts Per Day • PreExpand • Protect Globals • Queue() • Resource Update • ResourcesEx • SciTE Jump • Settings INI • SHELLHOOK • Shunting-Yard • Signature Creator • Stack() • Stopwatch() • StringAddLF()/StringStripLF() • StringEOLToCRLF() • VSCROLL • WM_COPYDATA • More Examples... Updated: 22/04/2018 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