CPatching Posted January 27, 2016 Share Posted January 27, 2016 Hello, I designed a script to get data from a specific file using _betweenstring command and try to write that data in a text file using filewrite command multiple time in a single script. In 1st attempt it works fine and write the data easily in a text file. In 2nd attempt it give error to write same data into different text file. picture of error and codes are written hereunder for ready reference; ;---------First Attempt to use filewrite and it successfully write the content in text file----------------------- $file = fileopen(@scriptdir & "\source01.txt", 10) $IE = xxxxxxxxxxxxxxxxxxxxxxxxxx $source = xxxxxxxxxxxxxxxxxxx FileWrite($file, $source) $target_source = _StringBetween($source, 'Markanderson', 'Death in December') FileWrite ( "kat01.txt", $target_source[0]) ;---------2nd Attempt to use filewrite and it give error----------------------- $file = fileopen(@scriptdir & "\source01.txt", 10) $IE = xxxxxxxxxxxxxxxxxxxxxxxxxx $source = xxxxxxxxxxxxxxxxxxx FileWrite($file, $source) $target_source = _StringBetween($source, 'Markanderson', 'Death in December') Sleep (10000) FileWrite ( "kat02.txt", $target_source[1]) Thanks Link to comment Share on other sites More sharing options...
Moderators Melba23 Posted January 27, 2016 Moderators Share Posted January 27, 2016 CPatching, Welcome to the AutoIt forums. There is obviously only the single return from the _StringBetween function so that the array only holds a [0] element - hence the error when trying to access the non-existent [1] element. Try using _ArrayDisplay on $target_source to see if that is indeed the case. 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...
CPatching Posted January 27, 2016 Author Share Posted January 27, 2016 Thanks Melba23, I'm familiar with _StringBetween function and it help me to do what i wanted to do but I'm not familiar with function _ArrayDisplay and not so sure about it how it'll work and how can i code to make it possible for me. Thank Link to comment Share on other sites More sharing options...
AutoBert Posted January 27, 2016 Share Posted January 27, 2016 (edited) A look in the help is helfull. Edited January 27, 2016 by AutoBert Link to comment Share on other sites More sharing options...
CPatching Posted January 27, 2016 Author Share Posted January 27, 2016 The function _ArrayDisplay is looking really difficult but it has lot of functions/ keys to perform and it never make sense for me to fulfill my need; The functions _StringBetween is really simple for me and it has starting and ending point to pick a specific part from a particular text such as; https://www.autoitscript.com/autoit3/docs/libfunctions/_StringBetween.htm But the command _ArraryDisplay is very complex to use for me even i tried to study examples as well but unable to understand; #include <Array.au3> _ArrayDisplay ( Const ByRef $aArray [, $sTitle = "ArrayDisplay" [, $sArrayRange = "" [, $iFlags = 0 [, $vUser_Separator = Default [, $sHeader = Default [, $iMax_ColWidth = Default [, $iAlt_Color = Default [, $hUser_Function = ""]]]]]]]] ) Anyone here, please help me to understand this command to use as an alternate of _StringBetween function. Link to comment Share on other sites More sharing options...
Moderators Melba23 Posted January 27, 2016 Moderators Share Posted January 27, 2016 CPatching, I suggested using _ArrayDisplay to check if you were indeed only getting a single value returned by _StringBetween, not as an alternative to the function itself. You would use it like this: ;---------First Attempt to use filewrite and it successfully write the content in text file----------------------- $file = fileopen(@scriptdir & "\source01.txt", 10) $IE = xxxxxxxxxxxxxxxxxxxxxxxxxx $source = xxxxxxxxxxxxxxxxxxx FileWrite($file, $source) $target_source = _StringBetween($source, 'Markanderson', 'Death in December') _ArrayDisplay($target_source, "First attempt", Default, 8) FileWrite ( "kat01.txt", $target_source[0]) ;---------2nd Attempt to use filewrite and it give error----------------------- $file = fileopen(@scriptdir & "\source01.txt", 10) $IE = xxxxxxxxxxxxxxxxxxxxxxxxxx $source = xxxxxxxxxxxxxxxxxxx FileWrite($file, $source) $target_source = _StringBetween($source, 'Markanderson', 'Death in December') _ArrayDisplay($target_source, "Second attempt", Default, 8) FileWrite ( "kat02.txt", $target_source[1]) Now you will get a dialog appear each time showing the content of the returned array from _StringBetween - and my guess is that you only ever have a single element so that you crash when trying to read the [1] element on the second pass. 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...
CPatching Posted January 27, 2016 Author Share Posted January 27, 2016 Hey Melba23, It's working for me and it shows data before writing text file in both 1st and 2nd attempt. But in 2nd attempt it give error like "There's nothing to show exit script or continue" like this error. I just wanted to ask that is there any way so I can use StringBetween function several time in a single script or is there any other function that can help me to make things possible. Thanks for your time and concerns. Link to comment Share on other sites More sharing options...
Moderators Melba23 Posted January 27, 2016 Moderators Share Posted January 27, 2016 CPatching, The error you get is because it seems that _StringBetween finds nothing to return on the second pass - which can only mean that $source has been modified so that the required content no longer exists. But as you have redacted the manner in which you get the content into $source, there is little I can do to explain why this might be happening. 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...
AutoBert Posted January 27, 2016 Share Posted January 27, 2016 1. and 2. attampt are searching with same parameters in the same variable, so 2. attempt must have the same result as 1. Trying it this way: Spoiler $IE = xxxxxxxxxxxxxxxxxxxxxxxxxx $source = xxxxxxxxxxxxxxxxxxx FileWrite($file, $source) $target_source = _StringBetween($source, 'Markanderson', 'Death in December') If IsArray($target_source) Then _ArrayDisplay($target_source, "Target source", Default, 8) For $i = 0 to UBound($target_source)-1 ;loop through all elemets in array FileWrite ( "kat01.txt", $target_source[$i]) MsgBox(0,'',$target_source{$i] Next EndIf Link to comment Share on other sites More sharing options...
CPatching Posted January 30, 2016 Author Share Posted January 30, 2016 Hello Melba23, Finally i found the issue why I'm getting error sometime while using filewrite function along-with_StringBetween command; I noticed that when my script try to browse saved source codes for applying _StringBetween function to find between specified points such as "Markanderson" or "Death in December". When script finds both starting and ending parameters to extract text between above points it'll work fine and when script failed to find these parameters from source codes then it'll stops working and give error for filewrite process. Please guide me how can i use function "if" to avoid this error and help my script to move on if it never find define parameters of _StringBetween. $file = fileopen(@scriptdir & "\source01.txt", 10) $IE = xxxxxxxxxxxxxxxxxxxxxxxxxx $source = xxxxxxxxxxxxxxxxxxx FileWrite($file, $source) $target_source = _StringBetween($source, 'Markanderson', 'Death in December') FileWrite ( "kat01.txt", $target_source[0]) Link to comment Share on other sites More sharing options...
mikell Posted January 30, 2016 Share Posted January 30, 2016 $target_source = _StringBetween($source, 'Markanderson', 'Death in December') If not @error Then FileWrite ( "kat01.txt", $target_source[0]) EndIf 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