Sign in to follow this  
Followers 0
esteban

ifthen statment problems

8 posts in this topic

Here's my problem,

I am trying to open a msgbox after a wingettext on notepad. My code looks like this :

$text=Wingettext("test")

if $text="start" then

msgbox(1,"test", "Success!")

endif

I am sure that $text="start" . i simply cant get the if statement to work correctly. can any one help me?

Share this post


Link to post
Share on other sites



Here's my problem,

I am trying to open a msgbox after a wingettext on notepad. My code looks like this :

$text=Wingettext("test")

if $text="start" then

msgbox(1,"test", "Success!")

endif

I am sure that $text="start" . i simply cant get the if statement to work correctly. can any one help me?

Can you give us a screenshot of the AutoIt Window Info Tool and the window?

Share this post


Link to post
Share on other sites

The code works. Your problem is that you are only looking for a window that contains the text you specified. Do you know the exact title of the window you want to get the text from? That would help a lot.


Pink Floyd - The Wall

Share this post


Link to post
Share on other sites

Ensure you are using WinWait() to wait for the window to come along, else WinGetText() may execute too early. Also you may need to account for the carriage return if exists. Only adding @LF would make it work for me.

This works for me.

Run('Notepad')
WinWait('Untitled')
ControlSend('Untitled', '', 'Edit1', 'start'); add some text to notepad
$text = WinGetText('Untitled')
If $text = ('start' & @LF) Then
    MsgBox(0, 'OK', 'success')
EndIf
MsgBox(0, '$test=', '"' & $text & '"'); Check variable contents

:P

Share this post


Link to post
Share on other sites

Many times i find myself using

If StringinStr($text, 'start') Then

that way if there is a line feed or "other" character, you still can get you desired results

8)


NEWHeader1.png

Share this post


Link to post
Share on other sites

Many times i find myself using

If StringinStr($text, 'start') Then

that way if there is a line feed or "other" character, you still can get you desired results

8)

I do that often ...

[center]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.[/center]

Share this post


Link to post
Share on other sites

thank you Valuater, after using StringinStr everything worked. thank you!

Share this post


Link to post
Share on other sites

I would have used StringStripWhiteSpace() to get the "start", because if the line contained "jumpstart" then StringInStr() would also return true. "jumpstart" is a different word.

:P

Share this post


Link to post
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
Sign in to follow this  
Followers 0