Jump to content
DigDeep

OR statement not working

Recommended Posts

DigDeep

Not sure, what is wrong with the below statement that it always shows the msgbox as: Application installed successfully.

Is there anything wrong to write the OR statement as per below or any improvised way to write it?

Select
        Case $Date > "10" Or $ProcessVer = "2.5" Or $ProcessVer = '2.0' Or Not FileExists("FilePath")
            $Verify = "Appllication not exists."
        Case Else
            $Verify = "Appllication installed successfully."
    EndSelect
    
    MsgBox(0, "", $Verify)

 

Share this post


Link to post
Share on other sites
TheSaint

Perhaps you need to use AND or nest some elements together in brackets?

Using ELSE on its own is pretty ambiguous, and is always the case that is true, if none of the first case is true.

Not knowing the rest of your code etc it is hard to gauge where you might have an issue.

From my point of view, "FilePath" has no meaning, as like it is, it isn't a path.


AutoIt.4.Life Clubrooms - Life is like a Donut (secret key)

Make sure brain is in gear before opening mouth!
Remember, what is not said, can be just as important as what is said.

Spoiler

What is the Secret Key? Life is like a Donut

If I put effort into communication, I expect you to read properly & fully, or just not comment.
Ignoring those who try to divert conversation with irrelevancies.
If I'm intent on insulting you or being rude, I will be obvious, not ambiguous about it.
I'm only big and bad, to those who have an over-active imagination.

I may have the Artistic Liesense ;) to disagree with you. TheSaint's Toolbox (be advised many downloads are not working due to ISP screwup with my storage)

userbar.png

Share this post


Link to post
Share on other sites
Juvigy

What is the value of $Date ? Put a checkbox or consolewrite to see the value. Also the type is important - sometimes Autoit converts between number and string and comparison is very different than what you would expect.

Share this post


Link to post
Share on other sites
DigDeep

@ TheSaint

This is a dummy example I have shows here so I have just mentioned as "FilePath". In the actual code, filepath has the correct value of the path where file should exist.

So, what you are suggesting is to mention as per below?

$Date > "10"
$ProcessVer = "2.5"
$ProcessVer = "2.0" 
$File = FileExists("FilePath")

Select
        Case Not $Date And $ProcessVer And $File
            $Verify = "Appllication not exists."
        Case $Date And $ProcessVer And $File
            $Verify = "Appllication installed successfully."
    EndSelect
    
    MsgBox(0, "", $Verify)

 

 

Edited by sunshinesmile84

Share this post


Link to post
Share on other sites
DigDeep

@Juvigy

$Date is the date modified of a particular file.

If I write these individually then it works properly. But if I write them in multiples of OR that when it does not identify.

What I am looking with the OR statement is... it would check all the fields.. if $Date is more or Version is not equal to 2.5 or 2.0 or the file itself does not exist then will display the message as "App does not exist."

 

; This is another way the code works propelry. But this makes the codes larger.

Select
        Case $Date > "10" 
            $Verify = "Appllication not exists."
        Case $ProcessVer = "2.5" 
            $Verify = "Appllication not exists."        
        Case $ProcessVer = '2.0'
            $Verify = "Appllication not exists."        
        Case Not FileExists("FilePath")
            $Verify = "Appllication not exists."
            
        Case Else
            $Verify = "Appllication installed successfully."
    EndSelect
    
    MsgBox(0, "", $Verify)

 

Share this post


Link to post
Share on other sites
Jos

This doesn't look right:

$Date > "10"

What is the exact content of date and you are doing a greater than test with the String 10!
When it contains a proper date value you could compare it to another date value with DateDiff() or something.

Jos

  • Like 1

Visit the SciTE4AutoIt3 Download page for the latest versions  - Beta files                                How to post scriptsource        Forum Rules
 
Live for the present,
Dream of the future,
Learn from the past.
  :)

Share this post


Link to post
Share on other sites
jguinch

Try to use number instead of string for comparisons :

Select
    Case Number($Date) > 10 And Number($ProcessVer) = 2 And FileExists("FilePath")
        $Verify = "Appllication installed successfully."
    Case Else
        $Verify = "Appllication not exists."
EndSelect
    
MsgBox(0, "", $Verify)

 

Share this post


Link to post
Share on other sites
Juvigy

If $Date  is something like '10/12/2015' and you are doing $Date > "10"  - it wont work  as expected and return the same result no matter how the date changes.

Share this post


Link to post
Share on other sites
TheSaint

How did I miss the string "10" ? :>


AutoIt.4.Life Clubrooms - Life is like a Donut (secret key)

Make sure brain is in gear before opening mouth!
Remember, what is not said, can be just as important as what is said.

Spoiler

What is the Secret Key? Life is like a Donut

If I put effort into communication, I expect you to read properly & fully, or just not comment.
Ignoring those who try to divert conversation with irrelevancies.
If I'm intent on insulting you or being rude, I will be obvious, not ambiguous about it.
I'm only big and bad, to those who have an over-active imagination.

I may have the Artistic Liesense ;) to disagree with you. TheSaint's Toolbox (be advised many downloads are not working due to ISP screwup with my storage)

userbar.png

Share this post


Link to post
Share on other sites
DigDeep

@Jos

Yes $Date value is DateDiff() here... that's why I gave it as > 10. which means "more than 10 days.

Share this post


Link to post
Share on other sites
Juvigy

There is a great difference between

$Date > "10"

and

$Date > 10

 

Share this post


Link to post
Share on other sites
DigDeep

@jguinch

Correcting your code little bit. '<' instead of '>' :)

But by putting And statement... does this not mean that only if all the 3 checks are true that $Date is less than 10 And Version is = 2 and File exists then it would pass ?

What I needed was if any of the 3 checks are false then it would fail else success.

 

Select
    Case Number($Date) < 10 And Number($ProcessVer) = 2 And FileExists("FilePath")
        $Verify = "Appllication installed successfully."
    Case Else
        $Verify = "Appllication not exists."
EndSelect
    
MsgBox(0, "", $Verify)

Edited by sunshinesmile84

Share this post


Link to post
Share on other sites
Juvigy

This works:

Select
    Case 11 > 10 OR 3 = 2 or 3<4
        $Verify = "Appllication installed successfully."
    Case Else
        $Verify = "Appllication not exists."
EndSelect
ConsoleWrite($Verify&@CRLF)

So the problem is with the values and types of your variables. As you can see OR is working perfectly

Share this post


Link to post
Share on other sites
DigDeep

@Juvigy

This is little confusing... You are telling to use OR but when I check in SciTe, when I type in 'O' it suggests me to use Or.

Share this post


Link to post
Share on other sites
sdfaheemuddin

Can you use If Else statement

Share this post


Link to post
Share on other sites
sdfaheemuddin

 

If $Date > "10" Or $ProcessVer = "2.5" Or $ProcessVer = '2.0' Or Not FileExists("FilePath") Then
            $Verify = "Appllication not exists."
Else
            $Verify = "Appllication installed successfully."
EndIf
    
    MsgBox(0, "", $Verify)

 

Edited by sdfaheemuddin

Share this post


Link to post
Share on other sites
Geir1983

Isnt Case better suited to test an Integer value? "IF" more suited to this sort of boolean test?

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

×