Realm Posted April 24, 2010 Posted April 24, 2010 (edited) While reading a txt file via FileReadLine all lines are read into a 7 element array. if it were to come across a line not equal to 7 elements, how could I script it to skip that line and restart the loop without exit or exitloop which stops the script. an Example of script: expandcollapse popupWhile 1 $Data = FileReadLine($File) If @error = -1 Then ExitLoop $pos = StringInStr($Data,'",',Default,1) If @error Then ConsoleWrite("Error on line " & @ScriptLineNumber-2 & @CRLF) ContinueLoop EndIf $Data = StringReplace($Data,'"','') If @error Then ConsoleWrite("Error on line " & @ScriptLineNumber-2 & @CRLF) ContinueLoop EndIf $CardName = StringLeft($Data,$pos-2) If @error Then ConsoleWrite("Error on line " & @ScriptLineNumber-2 & @CRLF) ContinueLoop EndIf $Data = StringTrimLeft($Data,$pos-2) If @error Then ConsoleWrite("Error on line " & @ScriptLineNumber-2 & @CRLF) ContinueLoop EndIf $Data = StringSplit($Data, ",") If @error Then ConsoleWrite("Error on line " & @ScriptLineNumber-2 & @CRLF) ContinueLoop EndIf $Data[1] = $Name IF $Data[0] <> 7 Then ; <<---- IF found to not equal 7 elements then ConsoleWrite("Error on line " & @ScriptLineNumber-2 & @CRLF) ; I need to skip current readline and restart loop ContinueLoop EndIf ;<<--- Select Case $Data[7] = "" $Section = "One" _ArrayInsert($Data,4,"X") Case $Data[7] = "No" $Section = "Two" Case $Data[7] = "Yes" $Section = "Three" Case Else ConsoleWrite("Unexpected carddata for " & $Data[1] & @CRLF) EndSelect WEnd Edited April 24, 2010 by Realm My Contributions: Unix Timestamp: Calculate Unix time, or seconds since Epoch, accounting for your local timezone and daylight savings time. RegEdit Jumper: A Small & Simple interface based on Yashied's Reg Jumper Function, for searching Hives in your registry.
Moderators Melba23 Posted April 24, 2010 Moderators Posted April 24, 2010 Realm,What you have using ContinueLoop should work. This simplified script works for me: $hFile = FileOpen("test.txt") $i = 0 While 1 $sData = FileReadLine($hFile) $i += 1 If @error = -1 Then ExitLoop $aData = StringSplit($sData, ",") If $aData[0] <> 7 Then ConsoleWrite("Error on line " & $i & @CRLF) ContinueLoop EndIf ConsoleWrite("Line " & $i & " OK" & @CRLF) WEnd FileClose($hFile)using this file:1,2,3,4,5,6,7 1,2,3,4,5,6,7 1,2,3,4,5,7 1,2,3,4,5,6,7 1,2,3,4,5,6,7I get:Line 1 OK Line 2 OK Error on line 3 Line 4 OK Line 5 OKM23P.S. Top Tip: Look at how I have used small letters (s, a, h) to indicate what the variable holds. It makes a script much easier to read - I was unsure at one point just what $Data was holding. 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
Realm Posted April 24, 2010 Author Posted April 24, 2010 sorry maybe i should have explained the entire script function more. This is ultimately reading lines from a text file, than looking up values from an ini file. so when it pulls $data line, and it is corrupted with a missing comma or element. it stops the script at the first case statement. There is alot more code after the Case EndSelect statements but before the actual Wend. What I need is for it to begin the loop over and skip the current line when it detects an error, continueloop allows the error to pass to the case statement which ultimately errors and exits, not what i need. My Contributions: Unix Timestamp: Calculate Unix time, or seconds since Epoch, accounting for your local timezone and daylight savings time. RegEdit Jumper: A Small & Simple interface based on Yashied's Reg Jumper Function, for searching Hives in your registry.
Moderators Melba23 Posted April 24, 2010 Moderators Posted April 24, 2010 Realm,continueloop allows the error to pass to the case statementThat is not what happens. From the Help file (and shown in the example code I posted):ContinueLoop will continue execution of the loop at the expression testing statement (that is the While, Until or Next statement).So you miss out everything from the ContinueLoop onwards and restart at the While. The code I posted does exactly that - you do not get the "OK" ConsoleWrite if the ContinueLoop is activated as the loop jumps over it to continue at the initial While.As I said in my first post, your code should work as the ContinueLoop should bypass the Select statement. If it does not, then there is something else happening. Perhaps a bit more debugging code might help - or you need to post a bit more code (such as an extract of your file which fails) so we can test some more. 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
Realm Posted April 24, 2010 Author Posted April 24, 2010 Sorry, I had a call function inside the part of the script before, where I was asking for the restart of the loop, and at the end of the function, I had statement to Exit. Sorry my fault. Thanks for your help Melba23. Please forgive me Noobishness. My Contributions: Unix Timestamp: Calculate Unix time, or seconds since Epoch, accounting for your local timezone and daylight savings time. RegEdit Jumper: A Small & Simple interface based on Yashied's Reg Jumper Function, for searching Hives in your registry.
Moderators Melba23 Posted April 24, 2010 Moderators Posted April 24, 2010 Realm, No probs - glad you got it sorted. 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
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