Jump to content

Lots of If/Thens in my script


Recommended Posts

:whistle:

In my script, I have a lot of IF/Thens to test the results of my functions. I could use Case Selects but that doesn't really clean up my code much.

Is there perhaps a better way to code all of these If/Then's in my project? I was kinda thinking of creating somekind of GLOBAL function but each result branches into different subbranches as well.

Something perhaps like this:

TestResult($Error, $ActiontoPerformonfailure, $ActiontoPerformonsuccess, $MessagetoDisplay)

Function TestResult(ByRef $a, ByRef $b, ByRef $c)

Select

Case $a = 0

$ActiontoPerformonSuccess

Case $a = 1

msgbox(0,"Error", $Messagetodisplay)

$ActiontoPerformonFailure

EndFunction

Thanks!

Digital Chaos - Life as we know it today.I'm a Think Tank. Problem is, my tank is empty.The Quieter you are, the more you can HearWhich would you choose - Peace without Freedom or Freedom without Peace?Digital Chaos Macgyver ToolkitCompletely Dynamic MenuSQLIte controlsAD FunctionsEXCEL UDFPC / Software Inventory UDFPC / Software Inventory 2GaFrost's Admin Toolkit - My main competitor :)Virtual SystemsVMWAREMicrosoft Virtual PC 2007

Link to comment
Share on other sites

My first program is LOADED with if/then statements, there are over 2000 lines of code

http://www.autoitscript.com/forum/index.ph...opic=11334&hl=#

my second project has only (approx) 30 if/then statements and is filled with function calls

http://www.autoitscript.com/forum/index.ph...opic=13024&hl=#

in the first project, the if/then staements allowed me to make nice commentary and the program folds very nicely in SciTE.

in the second, it is HARD CODED... no comments and no spaces

I suggest running "tidy" ( from SciTE Menu) and..

As long as your program functions correctly, looks clean, is understandable to you ( and possibly others) and is'nt too slow ( some dev's like "speed" in their scripts) then you've done well...

this is not the answer you were looking for, but maybe it could shed some light.

8)

NEWHeader1.png

Link to comment
Share on other sites

If you are using the beta, take a look at the new Switch structure as well.

David Nuttall
Nuttall Computer Consulting

An Aquarius born during the Age of Aquarius

AutoIt allows me to re-invent the wheel so much faster.

I'm off to write a wizard, a wonderful wizard of odd...

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