kor Posted August 25, 2011 Share Posted August 25, 2011 I have an automated output from a database program that spits out a text file with a series of values tab separated. However it spits out a blank line at the very end of the file which messes up my script when I create the array from all the data. Is there a command that I can run to delete the last line of a file if it is blank? I'm looking in the "File" commands but I can't find anything that would allow me to set the position to the last line in a file.. and then delete the last line. Bonus points if someone can show me what I would need to do to check if the line is blank or not. Link to comment Share on other sites More sharing options...
Moderators Melba23 Posted August 25, 2011 Moderators Share Posted August 25, 2011 kor, It would probably be easier to amend the array once you have created it. What does the added line do to your array? 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...
kor Posted August 25, 2011 Author Share Posted August 25, 2011 kor,It would probably be easier to amend the array once you have created it. What does the added line do to your array?M23If that is the case, how do I code a loop to figure out what the last N line is in my array and delete it? I can figure out how to check if the line is blank in the array. Link to comment Share on other sites More sharing options...
Moderators Melba23 Posted August 25, 2011 Moderators Share Posted August 25, 2011 kor,UBound will tell you how many elements you have in your array - the last element is 1 less than the returned value (because the first element is [0]) and you can feed that value into _ArrayDelete. 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...
kor Posted August 25, 2011 Author Share Posted August 25, 2011 kor, UBound will tell you how many elements you have in your array - the last element is 1 less than the returned value (because the first element is [0]) and you can feed that value into _ArrayDelete. M23 For $i = 0 To UBound($aRaw) - 1 If $aRaw[$i][0] = "" Then _ArrayDelete($aRaw[$i]) Next ? Link to comment Share on other sites More sharing options...
Moderators Melba23 Posted August 25, 2011 Moderators Share Posted August 25, 2011 kor,If you are going to delete lines from an array you should always start from the bottom and work up or else you could end up with an array smaller than the loop size and get the dreaded "index error": For $i = UBound($aRaw) - 1 To 0 Step -1 ; <<<<<<< If $aRaw[$i][0] = "" Then _ArrayDelete($aArray, $i) ; <<<<<< Look in the Help file for the syntax for _ArrayDelete!!!!!! NextBut I thought you only wanted to delete the last line? _ArrayDelete($aRaw, UBound($aRaw) - 1)All clear? 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...
kor Posted August 25, 2011 Author Share Posted August 25, 2011 kor, If you are going to delete lines from an array you should always start from the bottom and work up or else you could end up with an array smaller than the loop size and get the dreaded "index error": For $i = UBound($aRaw) - 1 To 0 Step -1 ; <<<<<<< If $aRaw[$i][0] = "" Then _ArrayDelete($aArray, $i) ; <<<<<< Look in the Help file for the syntax for _ArrayDelete!!!!!! Next But I thought you only wanted to delete the last line? _ArrayDelete($aRaw, UBound($aRaw) - 1) All clear? M23 got it! thanks. 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