Jump to content

if/elseif function


Recommended Posts

#include <Process.au3>
#include <File.au3>
#include <IE.au3>
Opt("WinTitleMatchMode",3)

test()

func test()
$title = WinGetTitle("[active]")
ConsoleWrite($title & @CRLF)

$x = "755 settings"
$y = "712D settings"
$z = "852 settings"
$w = "855 settings"
if string($title) = $x Or $w then
 consolewrite("got here" & CRLF)
elseif string($title) = $y Or $z then
 consolewrite("got there" & CRLF)
else
 consolewrite("Try again" & CRLF)
end func

console output:

712 settings

got here

why did it print got here and not there??

wintitlematchmode is set to 3 which should be exact match...

Link to comment
Share on other sites

#include <Process.au3>
#include <File.au3>
#include <IE.au3>
Opt("WinTitleMatchMode",3)

test()

func test()
$title = WinGetTitle("[active]")
ConsoleWrite($title & @CRLF)

$x = "755 settings"
$y = "712D settings"
$z = "852 settings"
$w = "855 settings"
if string($title) = $x Or $w then
consolewrite("got here" & CRLF)
elseif string($title) = $y Or $z then
consolewrite("got there" & CRLF)
else
consolewrite("Try again" & CRLF)
EndIf; <- this is what you were missing.
end func

Link to comment
Share on other sites

No, it's not, run the modified script and didn't work.

I need a way to match the entire title string and not partial.

- right now it's printing in comparison to the first 7xx instead of 712

#include <Process.au3>
#include <File.au3>
#include <IE.au3>
Opt("WinTitleMatchMode",3)

test()

func test()
$title = WinGetTitle("[active]")
ConsoleWrite($title & @CRLF)

$x = "755 settings"
$y = "712D settings"
$z = "852 settings"
$w = "855 settings"
if string($title) = $x Or $w then
consolewrite("got here" & @CRLF)
elseif string($title) = $y Or $z then
consolewrite("got there" & @CRLF)
else
consolewrite("Try again" & CRLF)
EndIf; <- this is what you were missing.
endfunc
Edited by diikee
Link to comment
Share on other sites

This is your error:

elseif string($title) = $y Or $z then

I guess it should be

elseif string($title) = $y Or string($title) = $z then

In the first form that statement was always true since $z has a value.

EDIT: the same thing with:

if string($title) = $x Or $w then

if string($title) = $x Or string($title) = $w then
Edited by enaiman

SNMP_UDF ... for SNMPv1 and v2c so far, GetBulk and a new example script

wannabe "Unbeatable" Tic-Tac-Toe

Paper-Scissor-Rock ... try to beat it anyway :)

Link to comment
Share on other sites

WinGetTitle returns a string, so no need to convert the var $title to a string and you might want double equal signs for case sensitive matching - or maybe not :-)

Opt("WinTitleMatchMode", 3)

test()

Func test()
 $title = WinGetTitle("[active]")
 ConsoleWrite($title & @CRLF)

 $x = "755 settings"
 $y = "712D settings"
 $z = "852 settings"
 $w = "855 settings"
 If $title == $x Or $title == $w Then
  ConsoleWrite("got here" & @CRLF)
 ElseIf $title == $y Or $title == $z Then
  ConsoleWrite("got there" & @CRLF)
 Else
  ConsoleWrite("Try again" & @CRLF)
 EndIf
EndFunc   ;==>test

[size="1"][font="Arial"].[u].[/u][/font][/size]

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