Jump to content

Recommended Posts

Posted

Hi all, I have detailed my problem below.

Trying to use AutoIt to:

- Open a program

- Get a specific piece of text from the "Visible Text" of the program window

- Press a button depending on what the specific piece of text is

The visible text is the following:

___________________________________

NagPage

1

&3

&2

&1

&Registration info

Program &information

___________________________________

The only line that changes is the 2nd line of text. It can be 1, 2 or 3 and displays at random when the program is opened.

-----

My question is: (After storing the visible text in a variable i.e.

$Text = WinGetText("", "")
) How then do I get the 2nd line of text and act according?

-----

Obviously I will need to use a conditional statement, but I can't figure out how to somehow either get the 2nd line or parse it from the variable.

Any help would be much appreciated.

Posted (edited)

I think the following function can help you:

StringSplit: Splits up a string into substrings depending on the given delimiters.

Return: Returns an array, by default the first element ($array[0]) contains the number of strings returned, the remaining elements ($array[1], $array[2], etc.) contain the delimited strings.

Possible code to your case:

$Array = StringSplit ($Text, "&" ,0)

$Array[1] will probably have '1' value or some thing like that, if not you can split it again with the correct delimiters until it becomes the value that you expected.

Edited by Juraci
Posted

Thanks for your pointers Juraci.

I split the Window Text by each new line (when carriage return/line feed characters are encountered)

I used the following code to achieve this:

$array = StringSplit ($text, @CRLF ,0)

"1" is at $array[2] so I used an ElseIf statement to act according to what was stored in position 2 of the array.

This solves my issue. So thanks again!

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...