Jump to content

_stringbetween with clipput() and clipget() causing static array values


Recommended Posts

Hello all!

I'm working on a project that copies data from a web page and pastes it into another application. When using an array to break down the data into the useful pieces I've noticed that as the next page of data is loaded into the script logic that the data from the previous web page is "stuck" (for lack of a better word) in either the array or the clipboard and being pasted repeatedly over multiple accounts in my application. I'm not sure if this is an issue with my error handling or what the root cause may be. Perhaps there is a way that I can empty out the arrays on each cycle after they have been used to prevent this from happening. I'm attaching some sample data to illustrate the different formats that I'm working with, since all of the headers are not present on each web page. My code is attached as well.

Sorry for the long-winded-ness of my post, I just wanted to be as descriptive as possible. Thank you all for any assistance that you can provide.

Cheers.

Here is my code:

$report = ClipGet()
$search1 = "Previous Phones:"
$search2 = "1st Degree Relatives Phones:"
$search3 = "2nd Degree Relatives Phones:"
$search4 = "Neighbor Phones:"
$search5 = "Possible Associates Phones:"
$search6 = "Previous Phone Numbers"

$Prev = _StringBetween($report, $search1, $search2)
If @error Then $Prev = _StringBetween($report, $search1, $search3)
If @error Then $Prev = _StringBetween($report, $search1, $search4)
If @error Then $Prev = _StringBetween($report, $search1, $search5)
If @error Then $Prev = _StringBetween($report, $search1, $search6)
If @error Then $Prev = ""

$1stDeg = _StringBetween($report, $search2, $search3)
If @error Then $1stDeg = _StringBetween($report, $search2, $search4)
If @error Then $1stDeg = _StringBetween($report, $search2, $search5)
If @error Then $1stDeg = _StringBetween($report, $search2, $search6)
If @error Then $1stDeg = ""

$2ndDeg = _StringBetween($report, $search3, $search4)
If @error Then $2ndDeg = _StringBetween($report, $search3, $search4)
If @error Then $2ndDeg = _StringBetween($report, $search3, $search4)
If @error Then $2ndDeg = ""

$Assoc = _StringBetween($report, $search5, $search6)
If @error Then $Assoc = ""

Sleep(2000)

ClipPut("")
Sleep(250)
_ArrayToClip($Prev)
WinActivate("Account")
Send("^a")
Sleep(250)
Send("r{TAB}")
Sleep(250)
Send("ni{TAB}{TAB}")
Sleep(250)
Send("Previous Phones{ENTER}")
Sleep(250)
Send("^v{TAB}")
Sleep(250)
Send("{ENTER}")
Sleep(7500)

ClipPut("")
Sleep(250)
_ArrayToClip($1stDeg)
WinActivate("Account")
Send("^a")
Sleep(250)
Send("r{TAB}")
Sleep(250)
Send("ni{TAB}{TAB}")
Sleep(250)
Send("1st Degree Relatives Phones{ENTER}")
Sleep(250)
Send("^v{TAB}")
Sleep(250)
Send("{ENTER}")
Sleep(7500)

ClipPut("")
Sleep(250)
_ArrayToClip($2ndDeg)
WinActivate("Account")
Send("^a")
Sleep(250)
Send("r{TAB}")
Sleep(250)
Send("ni{TAB}{TAB}")
Sleep(250)
Send("2nd Degree Relatives Phones{ENTER}")
Sleep(250)
Send("^v{TAB}")
Sleep(250)
Send("{ENTER}")
Sleep(7500)

ClipPut("")
Sleep(250)
_ArrayToClip($Assoc)
WinActivate("Account")
Send("^a")
Sleep(250)
Send("r{TAB}")
Sleep(250)
Send("ni{TAB}{TAB}")
Sleep(250)
Send("Associates Phones{ENTER}")
Sleep(250)
Send("^v{TAB}")
Sleep(250)
Send("{ENTER}")
Sleep(7500)
Send("^x")

Sample data #1:

Phone Summary 
Phones at Address:
480-967
480-968


Previous Phones:
480-247
602-750
 

1st Degree Relatives Phones:
217-483
 

2nd Degree Relatives Phones:
217-483
 

Neighbor Phones:
480-219
480-219


Possible Associates Phones:
480-275
480-214


Previous Phone Numbers

Sample data #2

Phone Summary 
Phones at Address:
480-967
480-968


Previous Phones:
480-247
602-750
 

Neighbor Phones:
480-219
480-219


Previous Phone Numbers

Edit - typos

Edited by ToddH
Link to comment
Share on other sites

What is in the clipboard? Sample data #1 or #2?

How it should look on the other application?

Br,

UEZ

Please don't send me any personal message and ask for support! I will not reply!

Selection of finest graphical examples at Codepen.io

The own fart smells best!
Her 'sikim hıyar' diyene bir avuç tuz alıp koşma!
¯\_(ツ)_/¯  ٩(●̮̮̃•̃)۶ ٩(-̮̮̃-̃)۶ૐ

Link to comment
Share on other sites

What is in the clipboard? Sample data #1 or #2?

How it should look on the other application?

Br,

UEZ

Sometimes it will be like data1 and sometimes like data2. If the _stringbetween causes an error through all possibilities I would like the array to contain either an empty value or the text "None".

I've been tinkering around with the code and have made a couple modifications, but am now getting the following errors:

nt.au3 (68) : ==> Subscript used with non-Array variable.:

If @error Then $2ndDeg[0] = "None"

If @error Then $2ndDeg^ ERROR

modified code

$report = ClipGet()
$search1 = "Previous Phones:"
$search2 = "1st Degree Relatives Phones:"
$search3 = "2nd Degree Relatives Phones:"
$search4 = "Neighbor Phones:"
$search5 = "Possible Associates Phones:"
$search6 = "Previous Phone Numbers"
Dim $Prev[1]
Dim $1stDeg[1]
Dim $2ndDeg[1]
Dim $Assoc[1]
$Prev[0] = "None"
$1stDeg[0] = "None"
$2ndDeg[0] = "None"
$Assoc[0] = "None"


$Prev = _StringBetween($report, $search1, $search2)
If @error Then $Prev = _StringBetween($report, $search1, $search3)
If @error Then $Prev = _StringBetween($report, $search1, $search4)
If @error Then $Prev = _StringBetween($report, $search1, $search5)
If @error Then $Prev = _StringBetween($report, $search1, $search6)
If @error Then $Prev[0] = "None"
;_ArrayDisplay($Prev, "prev array")

$1stDeg = _StringBetween($report, $search2, $search3)
If @error Then $1stDeg = _StringBetween($report, $search2, $search4)
If @error Then $1stDeg = _StringBetween($report, $search2, $search5)
If @error Then $1stDeg = _StringBetween($report, $search2, $search6)
If @error Then $1stDeg[0] = "None"

$2ndDeg = _StringBetween($report, $search3, $search4)
If @error Then $2ndDeg = _StringBetween($report, $search3, $search4)
If @error Then $2ndDeg = _StringBetween($report, $search3, $search4)
If @error Then $2ndDeg[0] = "None"

$Assoc = _StringBetween($report, $search5, $search6)
If @error Then $Assoc[0] = "None"

_ArrayToClip($Prev)
MsgBox(0, "prev", ClipGet())
_ArrayToClip($1stDeg)
MsgBox(0, "1st", ClipGet())
_ArrayToClip($2ndDeg)
MsgBox(0, "2nd", ClipGet())
_ArrayToClip($Assoc)
MsgBox(0, "assoc", ClipGet())

Thanks again for trying to help!!

Link to comment
Share on other sites

  • Moderators

If it's @error, then $2ndDeg is not an array

Try something like:

If @error Then
    Dim $2ndDeg[1]; replace 1 with whatever you really need
    $2ndDeg[0] = "None"
EndIf

Common sense plays a role in the basics of understanding AutoIt... If you're lacking in that, do us all a favor, and step away from the computer.

Link to comment
Share on other sites

If it's @error, then $2ndDeg is not an array

Try something like:

If @error Then
    Dim $2ndDeg[1]; replace 1 with whatever you really need
    $2ndDeg[0] = "None"
EndIf

Perfect. Works like a charm. Looks like my array declarations were too early in the code and needed to be implemented into the error checking as you suggested. Thank you both so much for your quick responses!!

Link to comment
Share on other sites

How about a more sensible way to collect those lines in the first place (the two files contain your example data):

#include <File.au3>

Global $aFiles[2] = [@ScriptDir & "\Test1.txt", @ScriptDir & "\Test2.txt"]
Global $aLines, $sSection

For $f = 0 To UBound($aFiles) - 1
    _FileReadToArray($aFiles[$f], $aLines)
    If @error Then ContinueLoop

    ConsoleWrite("File read:  " & $aFiles[$f] & @LF)
    For $n = 1 To $aLines[0]
        If StringRegExp($aLines[$n], "\d{3,}\-\d{3,}", 0) Then
            ; Phone no.
            ConsoleWrite($sSection & "  " & $aLines[$n] & @LF)
        Else
            ; Possible section title (if not blank)
            If StringStripWS($aLines[$n], 8) Then $sSection = StringStripWS($aLines[$n], 3)
        EndIf
    Next
Next

Whenever a line matches the RegExp (3 or more digits, a dash, then 3 or more digits) it is assumed to be a phone number. If not a phone number, the previous non-blank text is assumed to have been the section title.

This script just outputs to the console for demo. You can collect the data in a file, array, or whatever you want.

:)

Edited by PsaltyDS
Valuater's AutoIt 1-2-3, Class... Is now in Session!For those who want somebody to write the script for them: RentACoder"Any technology distinguishable from magic is insufficiently advanced." -- Geek's corollary to Clarke's law
Link to comment
Share on other sites

How about a more sensible way to collect those lines in the first place (the two files contain your example data):

#include <File.au3>

Global $aFiles[2] = [@ScriptDir & "\Test1.txt", @ScriptDir & "\Test2.txt"]
Global $aLines, $sSection

For $f = 0 To UBound($aFiles) - 1
    _FileReadToArray($aFiles[$f], $aLines)
    If @error Then ContinueLoop

    ConsoleWrite("File read:  " & $aFiles[$f] & @LF)
    For $n = 1 To $aLines[0]
        If StringRegExp($aLines[$n], "\d{3,}\-\d{3,}", 0) Then
            ; Phone no.
            ConsoleWrite($sSection & "  " & $aLines[$n] & @LF)
        Else
            ; Possible section title (if not blank)
            If StringStripWS($aLines[$n], 8) Then $sSection = StringStripWS($aLines[$n], 3)
        EndIf
    Next
Next

Whenever a line matches the RegExp (3 or more digits, a dash, then 3 or more digits) it is assumed to be a phone number. If not a phone number, the previous non-blank text is assumed to have been the section title.

This script just outputs to the console for demo. You can collect the data in a file, array, or whatever you want.

:)

PsaltyDS

Thank you for for suggestion and the code, unfortunately it wouldn't be feasible in this instance for two reasons. The first being that aside from this example, the text files don't actually exist. I'm manipulating data located on the clipboard that was copied from a web page. Secondly, there are phone numbers that I don't wish to include in my output based on headers that I've excluded in the logic of my array. Not to mention that there is data duplication on the web page that I don't want in my output either. But, I do welcome your feedback.

:)

Link to comment
Share on other sites

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
 Share

  • Recently Browsing   0 members

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