Jump to content

Recommended Posts

Posted

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

 

Autoit Error.png

  • Moderators
Posted

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

Public_Domain.png.2d871819fcb9957cf44f4514551a2935.png 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 columns
ChooseFileFolder ---- Single and multiple selections from specified path treeview listing
Date_Time_Convert -- Easily convert date/time formats, including the language used
ExtMsgBox --------- A highly customisable replacement for MsgBox
GUIExtender -------- Extend and retract multiple sections within a GUI
GUIFrame ---------- Subdivide GUIs into many adjustable frames
GUIListViewEx ------- Insert, delete, move, drag, sort, edit and colour ListView items
GUITreeViewEx ------ Check/clear parent and child checkboxes in a TreeView
Marquee ----------- Scrolling tickertape GUIs
NoFocusLines ------- Remove the dotted focus lines from buttons, sliders, radios and checkboxes
Notify ------------- Small notifications on the edge of the display
Scrollbars ----------Automatically sized scrollbars with a single command
StringSize ---------- Automatically size controls to fit text
Toast -------------- Small GUIs which pop out of the notification area

 

Posted

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

Posted

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.

 

 

  • Moderators
Posted

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

Public_Domain.png.2d871819fcb9957cf44f4514551a2935.png 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 columns
ChooseFileFolder ---- Single and multiple selections from specified path treeview listing
Date_Time_Convert -- Easily convert date/time formats, including the language used
ExtMsgBox --------- A highly customisable replacement for MsgBox
GUIExtender -------- Extend and retract multiple sections within a GUI
GUIFrame ---------- Subdivide GUIs into many adjustable frames
GUIListViewEx ------- Insert, delete, move, drag, sort, edit and colour ListView items
GUITreeViewEx ------ Check/clear parent and child checkboxes in a TreeView
Marquee ----------- Scrolling tickertape GUIs
NoFocusLines ------- Remove the dotted focus lines from buttons, sliders, radios and checkboxes
Notify ------------- Small notifications on the edge of the display
Scrollbars ----------Automatically sized scrollbars with a single command
StringSize ---------- Automatically size controls to fit text
Toast -------------- Small GUIs which pop out of the notification area

 

Posted

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.

  • Moderators
Posted

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

Public_Domain.png.2d871819fcb9957cf44f4514551a2935.png 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 columns
ChooseFileFolder ---- Single and multiple selections from specified path treeview listing
Date_Time_Convert -- Easily convert date/time formats, including the language used
ExtMsgBox --------- A highly customisable replacement for MsgBox
GUIExtender -------- Extend and retract multiple sections within a GUI
GUIFrame ---------- Subdivide GUIs into many adjustable frames
GUIListViewEx ------- Insert, delete, move, drag, sort, edit and colour ListView items
GUITreeViewEx ------ Check/clear parent and child checkboxes in a TreeView
Marquee ----------- Scrolling tickertape GUIs
NoFocusLines ------- Remove the dotted focus lines from buttons, sliders, radios and checkboxes
Notify ------------- Small notifications on the edge of the display
Scrollbars ----------Automatically sized scrollbars with a single command
StringSize ---------- Automatically size controls to fit text
Toast -------------- Small GUIs which pop out of the notification area

 

Posted

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
 
 

 

Posted

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])

 

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 account

Sign in

Already have an account? Sign in here.

Sign In Now
  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...