youtuber Posted September 21, 2018 Share Posted September 21, 2018 (edited) Trying to delete empty lines is giving error expandcollapse popup#include <ButtonConstants.au3> #include <EditConstants.au3> #include <GUIConstantsEx.au3> #include <WindowsConstants.au3> #include <File.au3> $Form1 = GUICreate("Form1", 616, 457, 192, 124) $Edit1 = GUICtrlCreateEdit("" & @CRLF, 24, 24, 569, 393, BitOR($ES_MULTILINE, $ES_AUTOVSCROLL, $WS_VSCROLL)) GUICtrlSetData(-1, "") GUICtrlSendMsg($Edit1, $EM_LIMITTEXT, -1, 0) $Button1 = GUICtrlCreateButton("Button1", 512, 424, 75, 25) GUISetState(@SW_SHOW) While 1 $nMsg = GUIGetMsg() Switch $nMsg Case $GUI_EVENT_CLOSE Exit Case $Button1 _allfilesetdata() EndSwitch WEnd Func _allfilesetdata() Local $aFiles = _FileListToArray(@ScriptDir, "*.txt", $FLTA_FILES, True) Local $aLines For $i = 1 To $aFiles[0] _FileReadToArray($aFiles[$i], $aLines) ;$aLines = StringRegExpReplace($aFiles[$i], '(?m:^\s*[\r\n])', '') ;If Not StringRegExp($alines[$i], '[^\s]', 0) Then _ArrayDelete($alines, $i) ;$aLines = StringRegExpReplace($aLines, "^\s*$", "") If IsArray($aLines) Then If $aLines[$i] = "" Then _ArrayDelete($aLines, $i) EndIf For $j = 1 To $aLines[0] GUICtrlSetData($Edit1, $aLines[$j] & @CRLF,1) Next EndIf Next EndFunc ;==>_allfilesetdata Edited September 21, 2018 by youtuber Link to comment Share on other sites More sharing options...
Developers Jos Posted September 21, 2018 Developers Share Posted September 21, 2018 ... and the error is .... ( or are we supposed to guess/test ourselves/ use the Crystal ball) ? 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...
youtuber Posted September 21, 2018 Author Share Posted September 21, 2018 I get this error Spoiler Link to comment Share on other sites More sharing options...
AutoBert Posted September 21, 2018 Share Posted September 21, 2018 When deleting in a array: Always from the end. 1 minute ago, Jos said: .. and the error is .... The usual when deleting in a array from the begin. @youtuber When deleting in a array: Always from the end. Faster solution desc lieorder: Func _allfilesetdata() Local $aFiles = _FileListToArray(@ScriptDir, "*.txt", $FLTA_FILES, True) Local $aLines For $i = 1 To $aFiles[0] _FileReadToArray($aFiles[$i], $aLines) If IsArray($aLines) Then For $j = $aLines[0] To 1 Step -1 If $aLines[$j] = "" Then _ArrayDelete($aLines, $j) Else GUICtrlSetData($Edit1, $aLines[$j]) EndIf Next EndIf Next EndFunc ;==>_allfilesetdata if you want to have right lineorder must be: Func _allfilesetdata() Local $aFiles = _FileListToArray(@ScriptDir, "*.txt", $FLTA_FILES, True) Local $aLines For $i = 1 To $aFiles[0] _FileReadToArray($aFiles[$i], $aLines) If IsArray($aLines) Then For $j = $aLines[0] To 1 Step -1 If $aLines[$j] = "" Then _ArrayDelete($aLines, $j) Next For $j = 1 To $aLines[0] GUICtrlSetData($Edit1, $aLines[$j]) Next EndIf Next EndFunc ;==>_allfilesetdata youtuber 1 Link to comment Share on other sites More sharing options...
Developers Jos Posted September 21, 2018 Developers Share Posted September 21, 2018 No pictures please ... just the text is fine .... and I guess this error is something like: Quote Array variable has incorrect number of subscripts or subscript dimension range exceeded youtuber 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...
Developers Jos Posted September 21, 2018 Developers Share Posted September 21, 2018 1 minute ago, AutoBert said: The usual when deleting in a array from the begin. I know and fully understand the issue but simply want to tell the OP he needs to get his shit together before posting! ( don't tell him I told you ...ok? We keep this our secret ) youtuber 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...
youtuber Posted September 21, 2018 Author Share Posted September 21, 2018 7 minutes ago, Jos said: I know and fully understand the issue but simply want to tell the OP he needs to get his shit together before posting! ( don't tell him I told you ...ok? We keep this our secret ) I think I got it right. Func _allfilesetdata() Local $aFiles = _FileListToArray(@ScriptDir, "*.txt", $FLTA_FILES, True) Local $aLines For $i = 1 To $aFiles[0] _FileReadToArray($aFiles[$i], $aLines) If IsArray($aLines) Then For $j = $aLines[0] To 1 Step -1 If $aLines[$j] = "" Then _ArrayDelete($aLines, $j) Next ;For $j = 1 To $aLines[0] For $j = 1 to UBound($aLines) -1 GUICtrlSetData($Edit1, $aLines[$j] & @CRLF,1) Next EndIf Next EndFunc ;==>_allfilesetdata Link to comment Share on other sites More sharing options...
AdamUL Posted September 21, 2018 Share Posted September 21, 2018 (edited) You can get the array rows deleted faster using the range option of ArrayDelete. Using this option, you can go forward through the array as well. Func _allfilesetdata() Local $aFiles = _FileListToArray(@ScriptDir, "*.txt", $FLTA_FILES, True) Local $aLines Local $sDeleteRows = "" For $i = 1 To $aFiles[0] _FileReadToArray($aFiles[$i], $aLines) If IsArray($aLines) Then For $j = 1 To $aLines[0] If $aLines[$j] = "" Then $sDeleteRows &= $j & ";" Next $sDeleteRows = StringTrimRight($sDeleteRows, 1) ;Remove last ";". _ArrayDelete($aLines, $sDeleteRows) ;Delete multiple rows. $aLines[0] = UBound($aLines) - 1 ;Change $aLines[0] to current array size. For $j = 1 To $aLines[0] GUICtrlSetData($Edit1, $aLines[$j] & @CRLF,1) Next EndIf Next EndFunc ;==>_allfilesetdata Adam Edited September 21, 2018 by AdamUL Bug in code youtuber 1 Link to comment Share on other sites More sharing options...
youtuber Posted September 21, 2018 Author Share Posted September 21, 2018 @AdamUL "C:\Program Files (x86)\AutoIt3\Include\Array.au3" (434) : ==> Array variable has incorrect number of subscripts or subscript dimension range exceeded.: $aArray[$vRange[$i]] = ChrW(0xFAB1) ^ ERROR Link to comment Share on other sites More sharing options...
AdamUL Posted September 21, 2018 Share Posted September 21, 2018 @youtuber Had small bug in code. Updated code above. Adam youtuber 1 Link to comment Share on other sites More sharing options...
mikell Posted September 21, 2018 Share Posted September 21, 2018 My 2 cents You might try something like this, shorter and much faster BTW it also removes blank spaces (if exist) at the beginning of lines Func _allfilesetdata() Local $aFiles = _FileListToArray(@ScriptDir, "*.txt", $FLTA_FILES, True) For $i = 1 To $aFiles[0] $f = FileRead($aFiles[$i]) $f = StringRegExpReplace($f, '(?m)^\s*\R?', "") GUICtrlSetData($Edit1, $f & @CRLF, 1) Next EndFunc ;==>_allfilesetdata youtuber 1 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