Jump to content
Sign in to follow this  
HockeyFan

Nested IF Statements

Recommended Posts

HockeyFan

:)

Can someone help me with a nested if statement???

I need to check the existance of four files before a install is run. If the file is there...do nothing...if it's not there display message prompt and exit.

So far, all I have is a bunch of If...then statements. Please help me clean this up! :D

If FileExists("C:\Software\McAfeeUpdate\MVSA1.exe") Then
    $X = 1
Else
    MsgBox(0,"Run Error!", "Please run McAfeeUdate.exe file to install update.",60)
    Exit
EndIf
If FileExists("C:\Software\McAfeeUpdate\MVSA2.exe") Then
    $X = 2
Else
    MsgBox(0,"Run Error!", "Please run McAfeeUdate.exe file to install update.",60)
    Exit
EndIf
If FileExists("C:\Software\McAfeeUpdate\MVSA3.exe") Then
    $X = 3
Else
    MsgBox(0,"Run Error!", "Please run McAfeeUdate.exe file to install update.",60)
    Exit
EndIf
If FileExists("C:\Software\McAfeeUpdate\MVSA4.exe") Then
    $X = 4
Else
    MsgBox(0,"Run Error!", "Please run McAfeeUdate.exe file to install update.",60)
    Exit
EndIf

Thanks! :evil:

Share this post


Link to post
Share on other sites
blindwig

You don't need nested IFs for that. Maybe a single IF nested in a loop, but that's about it:

For $X = 1 to 4
    If Not FileExists("C:\Software\McAfeeUpdate\MVSA" & $X & ".exe") Then ExitLoop
Next
If $X < 5 Then MsgBox(0,"Run Error!", "Please run McAfeeUdate.exe file to install update.",60)
Edited by blindwig

Share this post


Link to post
Share on other sites
Swimming_Bird

AFAIK you can nest as many as you want

If Blah Then
    This that
    If Blah Then
        IF Blah Then Blahahdfalhdsafhd
    Else
        Blahdlfasdf 
    EndIf
ElseIf
    Blah
Else
    Blah
Endif

You can also use a case structure

Select
    Case $1=1
        Blah
    Case $2=2
        blah
EndSelect

what i would do however is

Dim $x[5]
$x[1]=File1
$x[2]=file2
.....
For $dis = 1 to 5
    If Not FileExists($x[$dis]) Then 
        MsgBox(0,"Run Error!", "Please run McAfeeUdate.exe file to install update.",60)
        Exit
    EndIf
Next
Edited by Swimming_BIrd

Share this post


Link to post
Share on other sites
HockeyFan

what i would do however is

Dim $x[5]
$x[1]=File1
$x[2]=file2
.....
For $dis = 1 to 5
    If Not FileExists($x[$dis]) Then 
        MsgBox(0,"Run Error!", "Please run McAfeeUdate.exe file to install update.",60)
        Exit
    EndIf
Next

<{POST_SNAPBACK}>

Thanks Swimming_BIrd...I like it!! :)

Share this post


Link to post
Share on other sites
HockeyFan

You don't need nested IFs for that.  Maybe a single IF nested in a loop, but that's about it:

For $X = 1 to 4
    If Not FileExists("C:\Software\McAfeeUpdate\MVSA" & $X & ".exe") Then ExitLoop
Next
If $X < 5 Then MsgBox(0,"Run Error!", "Please run McAfeeUdate.exe file to install update.",60)

<{POST_SNAPBACK}>

Thanks for your input blindwig! :)

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  

×