HockeyFan Posted July 22, 2005 Share Posted July 22, 2005 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! 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! Link to comment Share on other sites More sharing options...
blindwig Posted July 22, 2005 Share Posted July 22, 2005 (edited) 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 July 22, 2005 by blindwig My UDF Threads:Pseudo-Hash: Binary Trees, Flat TablesFiles: Filter by Attribute, Tree List, Recursive Find, Recursive Folders Size, exported to XMLArrays: Nested, Pull Common Elements, Display 2dSystem: Expand Environment Strings, List Drives, List USB DrivesMisc: Multi-Layer Progress Bars, Binary FlagsStrings: Find Char(s) in String, Find String in SetOther UDF Threads I Participated:Base64 Conversions Link to comment Share on other sites More sharing options...
Swimming_Bird Posted July 22, 2005 Share Posted July 22, 2005 (edited) 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 July 22, 2005 by Swimming_BIrd Link to comment Share on other sites More sharing options...
HockeyFan Posted July 22, 2005 Author Share Posted July 22, 2005 what i would do however isDim $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!! Link to comment Share on other sites More sharing options...
HockeyFan Posted July 22, 2005 Author Share Posted July 22, 2005 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! Link to comment Share on other sites More sharing options...
Recommended Posts
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 accountSign in
Already have an account? Sign in here.
Sign In Now