Jump to content

If statement not working


Recommended Posts

I would like to understand why the If statement doesn't skip the code.  At the time the If statement runs $title = 0

$title = WinGetTitle("Delete items?", "")
WinActivate($title, "")
$text = WinGetText("", "")
$text = StringStripCR($text)
$TextLine = StringSplit($text, @LF)

If $title = "Delete items?" Then
    WinWait("Delete items?", "Folders and files no")
    If Not WinActive("Delete items?", "Folders and files no") Then WinActivate("Delete items?", "Folders and files no")
    WinWaitActive("Delete items?", "Folders and files no")
    Send("{SHIFTDOWN}{TAB}{SHIFTUP}{SPACE}{TAB}{ENTER}{ENTER}{ENTER}{ENTER}")
EndIf

Thank you,

Docfxit

Running AutoIt ver. 3.3.10.2

Win7 64bit

Link to comment
Share on other sites

Using the title, to return the title...

I'd suggest looking into using window and control handles for more robust execution.

WinGetHandle
ControlGetHandle
ControlFocus

ControlSetText
ControlClick







To directly answer your question, you are comparing an integer of 0, to a string, which will pass.

Run this, and see what you should do...also, the internet helpfile for winGetTitle is not correct...it returns 0 on failure, not an empty string.

ConsoleWrite((0="delete something")& @crlf)
ConsoleWrite((string(0)="delete something")& @crlf)
ConsoleWrite(WinGetTitle("going to fail")& @crlf)
Edited by jdelaney
IEbyXPATH-Grab IE DOM objects by XPATH IEscriptRecord-Makings of an IE script recorder ExcelFromXML-Create Excel docs without excel installed GetAllWindowControls-Output all control data on a given window.
Link to comment
Share on other sites

Thanks for the reply...

I'm not understanding what you are trying to show me.

When I run this:

ConsoleWrite((0="delete something")& @crlf)
ConsoleWrite((string(0)="delete something")& @crlf)
ConsoleWrite(WinGetTitle("going to fail")& @crlf)

I get results in the console window:

True

False

I have no idea what is happening.

Thanks,

Docfxit

Edited by Docfxit
Link to comment
Share on other sites

I'm showing you what happens when you compare strings with integers (won't have your expected results), and integers converted to strings with strings (will have your expected results).

Look at the differences.

IEbyXPATH-Grab IE DOM objects by XPATH IEscriptRecord-Makings of an IE script recorder ExcelFromXML-Create Excel docs without excel installed GetAllWindowControls-Output all control data on a given window.
Link to comment
Share on other sites

I added some code:

ConsoleWrite("1 - " & (0="delete something")& @crlf)
ConsoleWrite("2 - " & (string(0)="delete something")& @crlf)
ConsoleWrite("3 - " & WinGetTitle("going to fail")& @crlf)

 

Now I get output that looks like this:

1 - True
2 - False
3 - 0

I am going to take a guess that what you are trying to tell me is:

1 - True          This isn't working
2 - False         This is working
3 - 0                This isn't working

Is that correct?

Docfxit

Link to comment
Share on other sites

What that example demonstrates is this: http://www.autoitscript.com/autoit3/docs/intro/lang_datatypes.htm

More specifically, the "If a string is used as a" parts in the first page.

This wonderful site allows debugging and testing regular expressions (many flavors available). An absolute must have in your bookmarks.
Another excellent RegExp tutorial. Don't forget downloading your copy of up-to-date pcretest.exe and pcregrep.exe here
RegExp tutorial: enough to get started
PCRE v8.33 regexp documentation latest available release and currently implemented in AutoIt beta.

SQLitespeed is another feature-rich premier SQLite manager (includes import/export). Well worth a try.
SQLite Expert (freeware Personal Edition or payware Pro version) is a very useful SQLite database manager.
An excellent eBook covering almost every aspect of SQLite3: a must-read for anyone doing serious work.
SQL tutorial (covers "generic" SQL, but most of it applies to SQLite as well)
A work-in-progress SQLite3 tutorial. Don't miss other LxyzTHW pages!
SQLite official website with full documentation (may be newer than the SQLite library that comes standard with AutoIt)

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