itctravel Posted January 9, 2013 Share Posted January 9, 2013 (edited) I know this looks similar to some other posts. I looked at a few and 1 of them I thought for sure was the answer but it didn't work so in desperation I am starting this thread. So, I have a large text file that I am looking to replace the words "RUN DATE" when certain criteria isn't met. I through some MsgBox feedback etc in here so I could better understand what is happening. It seems the logic is working. It finds the instances where the criteria is met and makes (appears to) changes to the array which is evident when it performs the "MsgBox(0, "String Replace State", $StringReplace)" function i.e. I see the change to that array in the result. The problem is that when I do a _FileWriteFromArray and then look at the new file that is created it doesn't reflect the changes made. I know I am very close but just can't seem to figure this one out. I did try changing the $i_Base to 0 specifically as was mentioned on another thread (Thought for sure that would work) but still the same problem. Here is my ugly code...please don't laugh #include <Array.au3> #include <File.au3> $FileOpen = FileOpen ( "c:\trantest.txt") Local $TranText = FileRead("c:\trantest.txt") Local $TranArray = StringSplit($TranText, ' ', 1);This splits the .txt file into an array. Each array is the beginning of a new page which is what the 'FF' represents. MsgBox(0, "Number of Strings in Array", $TranArray[0]) For $i = $TranArray[0] To 1 Step -1;This checks how many arrays the page has been split into so that we can loop through each array to test for the condition we are looking for. $UnsignedTrans = 99999 ;We need to set an initial value here. If there is a page with RUN DATE that doesn't have the text 'Unsigned transcriptions" this value will be set to zero $Search = StringInStr ( $TranArray[$i], "RUN DATE") MsgBox(0, "Array Test", $Search) If $Search <> 0 Then MsgBox(0, "String Found", "String Found in Array" & $i) Global $UnsignedTransTest = StringInStr($TranArray[$i], "Unsigned transcriptions") MsgBox(0, "Unsigned text exists?", $UnsignedTransTest) $UnsignedTrans = $UnsignedTransTest MsgBox(0, "2", $UnsignedTrans) EndIf If $UnsignedTrans = 0 Then MsgBox(0, "Error at line", $i) Local $StringReplace = StringReplace($TranArray[$i], "RUN DATE", "xxxxxxx", 1) _ArrayDisplay($TranArray) $UnsignedTrans = 99999; this resets the variable so the next loop itteration can run correctly ;FileClose($FileOpen) $FileWrite = _FileWriteFromArray("C:\test.txt", $TranArray) MsgBox(0, "File Write State", $FileWrite) MsgBox(0, "File Write Error", @error) MsgBox(0, "String Replace State", $StringReplace) EndIf Next MsgBox(0, "", "Blast Off!") Edited January 9, 2013 by itctravel Link to comment Share on other sites More sharing options...
AdmiralAlkex Posted January 9, 2013 Share Posted January 9, 2013 (edited) Seems you confused yourself a lot there. Maybe because you name everything "tran"? Some things to start with: _ArrayDisplay($TranArray[$i]) There is no array in $TranArray[$i]. Maybe you meant _ArrayDisplay($TranArray) $FileWrite = _FileWriteFromArray("C:\test.txt", $TranText) Again, $TranText is not an array, it's just the return from FileRead(). Not sure what you're trying to do there. You also have FileClose() crazy far from where it would do any good, and you aren't actually using the filehandle from FileOpen() in FileRead(). If that's your whole script then FIleOpen() doesn't do any good anyway so I would just remove it. And please encase your code with AutoIt tags in the future. Makes it much easier to read. Just put [autoit ] [ /autoit] around your code (without the spaces). Edited January 9, 2013 by AdmiralAlkex .Some of my scripts: ShiftER, Codec-Control, Resolution switcher for HTC ShiftSome of my UDFs: SDL UDF, SetDefaultDllDirectories, Converting GDI+ Bitmap/Image to SDL Surface Link to comment Share on other sites More sharing options...
itctravel Posted January 9, 2013 Author Share Posted January 9, 2013 (edited) Admiral; Thanks for your reply. I changed so much playing around that I accidently initially posted the wrong iteration of the program. Thanks for the tip about the autoit tags...I modified appropriately. So to clarify what I am trying to do is I have 'divided' this long .txt into an array which is created with each 'new page' of the report Local $TranArray = StringSplit($TranText, ' ', 1) for some reason the special character I am splitting with doesn't translate over to this post but it is here and I verified that part is working. Then I run through each array to see if the words "RUN DATE" exists without the words "Unsigned transcriptions" on the page. If it does, I want to replace the words "RUN DATE" with "xxxxxxx" Sorry for prematurely posting the wrong code but what you see now is the best I have come to so far and seems to work except for the saving to file part. It does save the file but the file doesn't show the "xxxxxxx" changes I made in the loop. I am wondering if there are special ASCII characters in my .txt file that could be preventing this from working? I know it is a long shot but I have racked my brain as to why the canges never 'take' BTW, I like your boat Edited January 10, 2013 by itctravel Link to comment Share on other sites More sharing options...
itctravel Posted January 10, 2013 Author Share Posted January 10, 2013 So I am trying to break this down to basics and I've done a simple experiment that shows the problem. I Created a .txt (test.txt) document that contains only the following line "this, is, a, line, of, text" I then perform this script #include <Array.au3> Local $TranText = FileRead("c:\test.txt") Local $TranArray = StringSplit($TranText, ',') Local $text = StringReplace($TranArray[1], "i", "-") Local $numreplacements = @extended MsgBox(0, "The number of replacements done was", $numreplacements) _ArrayDisplay($TranArray) The $numreplacements indicates a change was made but when you do the _ArrayDisplay, it doesn't reflect the change For what it is worth, I am at version Version 3.2.0 for SciTE Link to comment Share on other sites More sharing options...
Developers Jos Posted January 10, 2013 Developers Share Posted January 10, 2013 (edited) Makes sense when you are not updating the array with the result but putting it in $text. Edited January 10, 2013 by Jos SciTE4AutoIt3 Full installer Download page - Beta files Read before posting How to post scriptsource Forum etiquette Forum Rules Live for the present, Dream of the future, Learn from the past. Link to comment Share on other sites More sharing options...
guinness Posted January 10, 2013 Share Posted January 10, 2013 (edited) Notice the difference between the two: #include <Array.au3> Local $sText = '"this, is, a, line, of, text"'; FileRead('Example.txt') Local $aArray = StringSplit($sText, ',') $aArray[1] = StringReplace($aArray[1], 'i', '-') ; Re-assign the replacement back to $aArray[1]. Local $iReplacements = @extended MsgBox(4096, '', 'The number of replacements done was: ' & $iReplacements) _ArrayDisplay($aArray) So it's not AutoIt that is broken in this instance. Edited January 10, 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...
Moderators Melba23 Posted January 10, 2013 Moderators Share Posted January 10, 2013 (edited) itctravel, Of course it will not change the array element - you never tell it to! But this script does: #include <Array.au3> Local $TranText = FileRead("test.txt") Local $TranArray = StringSplit($TranText, ',') _ArrayDisplay($TranArray) $TranArray[1] = StringReplace($TranArray[1], "i", "-") Local $numreplacements = @extended MsgBox(0, "The number of replacements done was", $numreplacements) _ArrayDisplay($TranArray) Can you see the difference. M23 Edit: Great minds eh! Edited January 10, 2013 by Melba23 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...
guinness Posted January 10, 2013 Share Posted January 10, 2013 (edited) Edit: Great minds eh! Aimed at me I presume. -_0 Edited January 10, 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...
Moderators Melba23 Posted January 10, 2013 Moderators Share Posted January 10, 2013 guinness, All 3 of us actually! Although Jos cheated and did not provide an example script. 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...
guinness Posted January 10, 2013 Share Posted January 10, 2013 Also he meant $text not $test, but I think itctravel would have understood. 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...
Developers Jos Posted January 10, 2013 Developers Share Posted January 10, 2013 Although Jos cheated and did not provide an example script. teach ...fish ... etc etc BrewManNH 1 SciTE4AutoIt3 Full installer Download page - Beta files Read before posting How to post scriptsource Forum etiquette Forum Rules Live for the present, Dream of the future, Learn from the past. Link to comment Share on other sites More sharing options...
itctravel Posted January 10, 2013 Author Share Posted January 10, 2013 Thank you Sooooo much, especially Guinness and Melba. It's all about the details! I'm glad I gave ya'll a chuckle...just learning this stuff so I REALLY appreciate this support mechanism for a great program. Keep up the great work guys(gals)!! Link to comment Share on other sites More sharing options...
Developers Jos Posted January 10, 2013 Developers Share Posted January 10, 2013 Thank you Sooooo much, especially Guinness and Melba. It's all about the details! I'm glad I gave ya'll a chuckle...just learning this stuff so I REALLY appreciate this support mechanism for a great program. Keep up the great work guys(gals)!!mmm not sure i like this answer where you indicate to prefer to be spoon fed.... SciTE4AutoIt3 Full installer Download page - Beta files Read before posting How to post scriptsource Forum etiquette Forum Rules Live for the present, Dream of the future, Learn from the past. Link to comment Share on other sites More sharing options...
itctravel Posted January 10, 2013 Author Share Posted January 10, 2013 Jos. You are reading too much into my interpretation. I enjoy learning. I think anyone messing with this stuff does. If yours were the only response it may have eventually lead me to the fix but it really wasn't stearing me on a course to efficient resolution as much as the others. Link to comment Share on other sites More sharing options...
Developers Jos Posted January 10, 2013 Developers Share Posted January 10, 2013 Jos. You are reading too much into my interpretation. I enjoy learning. I think anyone messing with this stuff does. If yours were the only response it may have eventually lead me to the fix but it really wasn't stearing me on a course to efficient resolution as much as the others.... and you are reading too much into my reply ... was just "playing" with you'all .... SciTE4AutoIt3 Full installer Download page - Beta files Read before posting How to post scriptsource Forum etiquette Forum Rules Live for the present, Dream of the future, Learn from the past. 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