Jump to content

How to reduce the number If..Then?


Recommended Posts

Hello people,

The more is use autoit the more "advanded" settings i want to start using.

At the moment we got quicktime 7.0.3.50 installed and i want to make a installer for quicktime 7.1.

The problem i am running in to is the misuse of If...Then ..

Example :

If FileExists("c:\Program Files\QuickTime\quicktime.exe") Then
$var = RegRead("HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows\CurrentVersion\Uninstall\{3868A8EE-5051-4DB0-8DF6-4F4B8A98D083}","DisplayVersion")
$answer = MsgBox(0x24, 'Quicktime Update:', 'Currently Quicktime ' & $var & ' is installed' & @CRLF & 'Do you want to install Quicktime 7.1?')

If $answer = 7 Then
Exit    
ElseIf $answer = 6 Then
Run("msiexec /x {3868A8EE-5051-4DB0-8DF6-4F4B8A98D083} /QN")
DirRemove("c:\Program Files\QuickTime\",1)
EndIf

RunWait('msiexec /i ISScript11.Msi /qn')
RunWait('msiexec /i QuickTime.msi ISSETUPDRIVEN=1 /qn')
etc..

At the moment there is one EndIf missing.

Could someone point me into the right direction (teach me a different way of thinking ?)

Edited by Ruigerock
Link to comment
Share on other sites

maybe

If FileExists("c:\Program Files\QuickTime\quicktime.exe") Then
    $var = RegRead("HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows\CurrentVersion\Uninstall\{3868A8EE-5051-4DB0-8DF6-4F4B8A98D083}", "DisplayVersion")
    If MsgBox(0x24, 'Quicktime Update:', 'Currently Quicktime ' & $var & ' is installed' & @CRLF & 'Do you want to install Quicktime 7.1?') = 7 Then Exit
    Run("msiexec /x {3868A8EE-5051-4DB0-8DF6-4F4B8A98D083} /QN")
    DirRemove("c:\Program Files\QuickTime\", 1)
EndIf

RunWait('msiexec /i ISScript11.Msi /qn')
RunWait('msiexec /i QuickTime.msi ISSETUPDRIVEN=1 /qn')
;etc..

8)

NEWHeader1.png

Link to comment
Share on other sites

In addition to SciTe, it looks like you would benefit from learning the SELECT and SWITCH statements (SWITCH only available in the beta). Take a look at the helpfile.

Dale

Free Internet Tools: DebugBar, AutoIt IE Builder, HTTP UDF, MODIV2, IE Developer Toolbar, IEDocMon, Fiddler, HTML Validator, WGet, curl

MSDN docs: InternetExplorer Object, Document Object, Overviews and Tutorials, DHTML Objects, DHTML Events, WinHttpRequest, XmlHttpRequest, Cross-Frame Scripting, Office object model

Automate input type=file (Related)

Alternative to _IECreateEmbedded? better: _IECreatePseudoEmbedded  Better Better?

IE.au3 issues with Vista - Workarounds

SciTe Debug mode - it's magic: #AutoIt3Wrapper_run_debug_mode=Y

Doesn't work needs to be ripped out of the troubleshooting lexicon. It means that what you tried did not produce the results you expected. It begs the questions 1) what did you try?, 2) what did you expect? and 3) what happened instead?

Reproducer: a small (the smallest?) piece of stand-alone code that demonstrates your trouble

Link to comment
Share on other sites

@gafrost : Yes i'm using Scite but i never explored the extra functions like tidy text and syntax, i'll have a look @ the help file

@Valuater : Cool! It's totally something i never would have thought of, nice technique .. thanks

@DaleHohm : Indeed, i will start using the SELECT or SWITCH statements for more specific statements.

Do you perhaps have some SELECT or SWITCH examples i can have a look at?

Link to comment
Share on other sites

$i = 1

Select

Case $i = 1

MsgBox ( 1, "I", "I equals 1" )

Case $i = 2

MsgBox ( 1, "I", "I equals 2" )

Case Else

MsgBox ( 1, "I", "I equals something other then 1 or 2!" )

EndSelect

Link to comment
Share on other sites

I know :D

A new one

$example = InputBox ( "Input", "Input A B or C" )

Select
    Case $example = "A"
    MsgBox ( 1, "Example", "You inputted A" )
    Case $example = "B"
    MsgBox ( 1, "Example", "You inputted B" )
    Case $example = "C"
    MsgBox ( 1, "Example", "You inputted C" )
    Case Else
    MsgBox ( 1, "Example", "You didnt input A B or C" )
EndSelect

$example = InputBox ( "Input", "Input A B or C" )

If $example = "A" Then
    MsgBox ( 1, "Example", "You inputted A" )
ElseIf $example = "B" Then
    MsgBox ( 1, "Example", "You inputted B" )
ElseIf $example = "C" Then
    MsgBox ( 1, "Example", "You inputted C" )
Else
    MsgBox ( 1, "Example", "You didnt input A B or C" )
EndIf

It will ask twice, one uses Ifs one uses Select.

Edited by Chip
Link to comment
Share on other sites

Hi there, thanks for the examples.

I've tried the following adjustment and it works!

If FileExists("c:\Program Files\QuickTime\QuickTimePlayer.exe") Then

;The binary file whose version we will check.
$AppBinFile = "c:\Program Files\QuickTime\QuickTimePlayer.exe"
$CurrentVer = FileGetVersion ( $AppBinFile )

Select
    Case $CurrentVer = "7.0.3.50"
    ;CAB code from 7.0.3.50
    Run("msiexec /x {3868A8EE-5051-4DB0-8DF6-4F4B8A98D083} /QN")
    DirRemove("c:\Program Files\QuickTime\",1)
    Case $CurrentVer = "7.0.0.0"
    ;CAB code from 7.0.0.0 (fictional)
    Run("msiexec /x {2009A8EE-5051-4DB0-8DF6-4F4B8A98D083} /QN")
    DirRemove("c:\Program Files\QuickTime\",1)
    Case $CurrentVer = "7.1.0.0" 
    ;CAB code from 7.1.0.0 (fictional)
    Run("msiexec /x {1114A8EE-5051-4DB0-8DF6-4F4B8A98D083} /QN")
    DirRemove("c:\Program Files\QuickTime\",1)
    Case Else
    MsgBox ( 1, "Sorry", "No Quicktime / Known version Quicktime was found" )
    Exit
EndSelect

EndIf

;Installation newest quicktime 
;Run("QuicktimeInstaller.exe /S /v/qn") etc..

The select worked perfectly, in stead of multiple IF ..Then the Case did the job!:D

Too bad the uninstallation of Quicktime itself gave an missing dll error at my computer :D

Anybody knows how to fix this new problem :wacko: ??

Edited by Ruigerock
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...