Jump to content

Nested If...Then..Else statements


Recommended Posts

Maybe my logic is flawed...but I am having trouble coding a function sort of like this...

IF aFunction() Then
if FileExists("c:\path") Then
if FileExists("c:\path1") Then;;; these If FileExists Then...are checking to see if files have been downloaded...there are about ten of these
if FileExists("c:\path10") Then
MsgBox(64,@ScriptName,"Downloads Complete!")
Else
MsgBox(64,@ScriptName,"Can't get them all!")
EndFunc

In that format it just gives me syntax errors...in this next format it always returns that the download did not complete, but it actually did...

Func gotTermServApps()

If $Lmi=1 Then
MsgBox(64,@ScriptName,"Got LogMeIn!")
Else
MsgBox(64,@ScriptName,"Could not get LogMeIn!")
EndIf

If $reader=True Then
MsgBox(64,@ScriptName,"Got Reader!")
Else
MsgBox(64,@ScriptName,"Could not get Reader!")
EndIf

if $filezilla=True Then
MsgBox(64,@ScriptName,"Got FileZilla!")
Else
MsgBox (64,@ScriptName,"Could not get FileZilla!")
EndIf

If $transact=True Then
Msgbox(64,@ScriptName,"Got TransActPOS!")
Else
MsgBox(64,@ScriptName,"Could not get TransActPOS!")
EndIf

If $openManage=True Then
MsgBox(64,@ScriptName,"Got OpenManage!")
Else
MsgBox(64,@ScriptName,"Could not get OpenManage!")
EndIf

IF $tp86=True Then
MsgBox(64,@ScriptName,"Got ThinPrint Engine 8.6!")
Else
MsgBox(64,@ScriptName,"Could not get ThinPrint Engine 8.6!")
EndIf

If $tp90=True Then
MsgBox(64,@ScriptName,"Got ThinPrint Engine 9.0!")
Else
MsgBox(64,@ScriptName,"Could not get ThinPrint Engine 9.0!")
EndIf

If $chrome=True Then
MsgBox(64,@ScriptName,"Got Chrome!")
Else
MsgBox(64,@ScriptName,"Could not get Chrome!")
EndIf


EndFunc

Although I do not really want a bunch of boxes popping up...just testing the logic really. Any help is appreciated!

The $lmi, $reader, etc are all declared globally outside functions. This is the basic structure of the vars...

global $lmi, $chrome, $filezilla, $mse32, $mse64, $reader, $tp86, $tp90, $tpClient, $transact
$reader=FileExists(@DesktopDir & "\AdbeRdr11002_en_US.exe")

Edited to be more decriptive...

Edited by zsutton92
Link to comment
Share on other sites

how about:

Func something()
    $count = 0
    If aFunction() Then
        if FileExists("c:\path") Then
            $count = $count + 1
        EndIf
        if FileExists("c:\path1") Then;;; these If FileExists Then...are checking to see if files have been downloaded...there are about ten of these
            $count = $count + 1
        EndIf
        if FileExists("c:\path10") Then
            $count = $count + 1
        EndIf
        If $count = 10 Then
            MsgBox(64,@ScriptName,"Downloads Complete!")
        Else
            MsgBox(64,@ScriptName,"Can't get them all!")
        EndIf
    EndIf
EndFunc
Edited by AoRaToS

s!mpL3 LAN Messenger

Current version 2.9.9.1 [04/07/2019]

s!mpL3 LAN Messenger.zip

s!mpL3

Link to comment
Share on other sites

You are missing several EndIf

It should be something like this

$fSuccess = False
IF aFunction() Then
    if FileExists("c:\path") Then
        if FileExists("c:\path1") Then;;; these If FileExists Then...are checking to see if files have been downloaded...there are about ten of these
            if FileExists("c:\path10") Then
                $fSuccess = True
            EndIf
        EndIf
    EndIf
Endif
if $fSuccess Then
    MsgBox(64,@ScriptName,"Downloads Complete!")
Else
    MsgBox(64,@ScriptName,"Can't get them all!")
EndIf

Alternatively you could use this format

$fSuccess = True
IF aFunction() Then
    if Not FileExists("c:\path") Then $fSuccess = False
    if Not FileExists("c:\path1") Then $fSuccess = False
    if Not FileExists("c:\path10") Then $fSuccess = False
Endif
if $fSuccess Then
    MsgBox(64,@ScriptName,"Downloads Complete!")
Else
    MsgBox(64,@ScriptName,"Can't get them all!")
EndIf
Edited by Bowmore

"Programming today is a race between software engineers striving to build bigger and better idiot-proof programs, and the universe trying to build bigger and better idiots. So far, the universe is winning."- Rick Cook

Link to comment
Share on other sites

Otherwise:

Func something()
    If aFunction() Then
        if FileExists("c:\path") Then
            if FileExists("c:\path1") Then;;; these If FileExists Then...are checking to see if files have been downloaded...there are about ten of these
                if FileExists("c:\path10") Then
                    MsgBox(64,@ScriptName,"Downloads Complete!")
                EndIf
            EndIf
        Else
            MsgBox(64,@ScriptName,"Can't get them all!")
        EndIf
    EndIf
EndFunc

s!mpL3 LAN Messenger

Current version 2.9.9.1 [04/07/2019]

s!mpL3 LAN Messenger.zip

s!mpL3

Link to comment
Share on other sites

You are missing several EndIf

It should be something like this

$fSuccess = False
IF aFunction() Then
if FileExists("c:\path") Then
if FileExists("c:\path1") Then;;; these If FileExists Then...are checking to see if files have been downloaded...there are about ten of these
if FileExists("c:\path10") Then
$fSuccess = True
EndIf
EndIf
EndIf
Endif
if $fSuccess Then
MsgBox(64,@ScriptName,"Downloads Complete!")
Else
MsgBox(64,@ScriptName,"Can't get them all!")
EndIf

You are correct, I did not include the EndIf in this write up of the code...but in my actual code, I did include the EndIf's, which resulted in error. I have since scrapped that code since it did not work..
Link to comment
Share on other sites

zsutton92,

This will fix the syntax errors from the first posted code...

If aFunction() Then
    If FileExists("c:\path") Then
        If FileExists("c:\path1") Then;;; these If FileExists Then...are checking to see if files have been downloaded...there are about ten of these
            If FileExists("c:\path10") Then
                MsgBox(64, @ScriptName, "Downloads Complete!")
            Else
                MsgBox(64, @ScriptName, "Can't get them all!")
            EndIf
        EndIf
    EndIf
EndIf
;  EndFunc   <--------------  can't have thi without a func stmt

A far as detecting whether or not downloads completed, if you are using inetget() then use inetgetinfo() in a loop to see if the download was successfull.

kylomas

edit: Holy shit, 4 posts within a minute, damn I'm slow!!!

Edited by kylomas

Forum Rules         Procedure for posting code

"I like pigs.  Dogs look up to us.  Cats look down on us.  Pigs treat us as equals."

- Sir Winston Churchill

Link to comment
Share on other sites

how about:

Func something()
$count = 0
If aFunction() Then
if FileExists("c:\path") Then
$count = $count + 1
EndIf
if FileExists("c:\path1") Then;;; these If FileExists Then...are checking to see if files have been downloaded...there are about ten of these
$count = $count + 1
EndIf
if FileExists("c:\path10") Then
$count = $count + 1
EndIf
If $count = 10 Then
MsgBox(64,@ScriptName,"Downloads Complete!")
Else
MsgBox(64,@ScriptName,"Can't get them all!")
EndIf
EndIf
EndFunc

Hmm..thats an idea..I'll try that out.
Link to comment
Share on other sites

So this...

Func gotTermServApps()
$count=0
If $Lmi= True Then
$count=$count + 1
EndIf

If $reader=True Then
$count=$count + 1
EndIf

if $filezilla=True Then
$count=$count + 1
EndIf

If $transact=True Then
$count=$count + 1
EndIf

If $openManage=True Then
$count=$count + 1
EndIf

IF $tp86=True Then
$count=$count + 1
EndIf

If $tp90=True Then
$count=$count + 1
EndIf

If $chrome=True Then
$count=$count + 1
EndIf

if $count=8 Then
MsgBox(64,@ScriptName,"All Downloads Complete!")
Else
MsgBox(64,@ScriptName,"Can't get them all!")
EndIf
EndFunc

Returns the MsgBox that says "Can't get them all!"...I am using a mixture of InetGet and FileCopy, but the actual checking procedure just checks if the file exists on the desktop...does it matter what method it used to get the file instead of just seeing if the file is there? Or are my If statements flawed?

Edit...This method doesn't seem to work..

Edited by zsutton92
Link to comment
Share on other sites

You are missing several EndIf

It should be something like this

$fSuccess = False
IF aFunction() Then
if FileExists("c:\path") Then
if FileExists("c:\path1") Then;;; these If FileExists Then...are checking to see if files have been downloaded...there are about ten of these
if FileExists("c:\path10") Then
$fSuccess = True
EndIf
EndIf
EndIf
Endif
if $fSuccess Then
MsgBox(64,@ScriptName,"Downloads Complete!")
Else
MsgBox(64,@ScriptName,"Can't get them all!")
EndIf

Alternatively you could use this format

$fSuccess = True
IF aFunction() Then
if Not FileExists("c:\path") Then $fSuccess = False
if Not FileExists("c:\path1") Then $fSuccess = False
if Not FileExists("c:\path10") Then $fSuccess = False
Endif
if $fSuccess Then
MsgBox(64,@ScriptName,"Downloads Complete!")
Else
MsgBox(64,@ScriptName,"Can't get them all!")
EndIf

So I want to use the opposite of what I am looking for? If the file exists, I want it to return false?
Link to comment
Share on other sites

So I want to use the opposite of what I am looking for? If the file exists, I want it to return false?

Reversing the logic allows the code to be more compact. $fSucess is initially set to True if any of the files do not exist it is set to False.

The end result is the same you have checked that all the downloaded files exist on the disk.

"Programming today is a race between software engineers striving to build bigger and better idiot-proof programs, and the universe trying to build bigger and better idiots. So far, the universe is winning."- Rick Cook

Link to comment
Share on other sites

Are you downloading in the foreground or background?

kylomas

I don't specify either one...I just use FileCopy.

are you checking if the download finished?

Just checking that the file is there

.

Reversing the logic allows the code to be more compact. $fSucess is initially set to True if any of the files do not exist it is set to False.

The end result is the same you have checked that all the downloaded files exist on the disk.

Oh..neat...I'll try that out.

Link to comment
Share on other sites

This returns the "Can't get them all!!" MsgBox after running....all applications are present on the desktop,

Func gotApps()
$fSuccess = False
IF getApps() Then
if $lmi Then
if $reader Then
if $filezilla Then
if $transact then
if $openManage then
if $tp86 then
if $tp90 then
if $chrome then
$fSuccess = True
EndIf
EndIf
EndIf
Endif
EndIf
EndIf
EndIf
EndIf
EndIf
if $fSuccess Then
MsgBox(64,@ScriptName,"Downloads Complete!")
Else
MsgBox(64,@ScriptName,"Can't get them all!!")
EndIf
EndFunc

I am wondering now, if it may be something do with the @DesktopDir path....does this path lead to the All Users Desktop, or the specific user at the time?

Edited by zsutton92
Link to comment
Share on other sites

  • Moderators

So why not simplify, and comment out all but one If Statement? Then work through them one at a time to see where you're having problems?

"Profanity is the last vestige of the feeble mind. For the man who cannot express himself forcibly through intellect must do so through shock and awe" - Spencer W. Kimball

How to get your question answered on this forum!

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