Terenz Posted October 13, 2016 Share Posted October 13, 2016 (edited) Hello, I have three variable can be True or False. I was build a Select...Case...EndSelect in this way: Global $A = 0, $B = 0, $C = 0 Select Case $A = 0 And $B = 0 And $C = 0 ; do a thing Case $A = 0 And $B = 0 And $C = 1 ; etc EndSelect There is a more efficent way to write the code or i just need to set all the eight possible combination? And in what order? Since some operation are in common ( like when $A is True in 4 different Case ) i was thinking there is a better way to write this. Thanks Edited October 13, 2016 by Terenz Nothing is so strong as gentleness. Nothing is so gentle as real strength Link to comment Share on other sites More sharing options...
Moderators JLogan3o13 Posted October 13, 2016 Moderators Share Posted October 13, 2016 (edited) With 8 combinations the way you're going about it seems most likely. I would start, personally, with looking at whether I could shorten the code any; do any of them cause me to call the same function, for example. If you were running the same function or call if any of them equal 1, you could do something like this: Local $A = 0, $B = 0, $C = 1 Local $x = ($A + $B + $C) Switch $x Case 0 ConsoleWrite("X = 0" & @CRLF) Case 1 ConsoleWrite("X >= 1" & @CRLF) EndSwitch But that doesn't seem to fit in with your end goal. Edited October 13, 2016 by JLogan3o13 "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 More sharing options...
Terenz Posted October 13, 2016 Author Share Posted October 13, 2016 (edited) Unfortunately no, since is not for any of them but depends. If is A is a thing, B another one and C another still. The function i'll do when A = True don't change if also B or C are True or False for this reason i'd like to avoid all that Cases or most of the code is equal. Global $A = 1, $B = 0, $C = 0 Select Case $A = 1 And $B = 0 And $C = 0 _MyFuncForA(1) ; example ; do a thing Case $A = 1 And $B = 1 And $C = 0 _MyFuncForA(1) ; example _MyFuncForB(1) ; example ; etc EndSelect Edited October 13, 2016 by Terenz Nothing is so strong as gentleness. Nothing is so gentle as real strength Link to comment Share on other sites More sharing options...
Moderators JLogan3o13 Posted October 13, 2016 Moderators Share Posted October 13, 2016 So then, what about something short and sweet? Global $A = 1, $B = 0, $C = 0 If $A Then _MyFuncForA($A) If $B Then _MyFuncForB($B) If $C Then _MyFuncForC($C) SorryButImaNewbie 1 "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 More sharing options...
LarsJ Posted October 13, 2016 Share Posted October 13, 2016 Switch True Case $A And $B And $C ConsoleWrite("1" & @CRLF) Case $A And $B ConsoleWrite("2" & @CRLF) Case $A And $C ConsoleWrite("3" & @CRLF) Case $B And $C ConsoleWrite("4" & @CRLF) Case $A ConsoleWrite("5" & @CRLF) Case $B ConsoleWrite("6" & @CRLF) Case $C ConsoleWrite("7" & @CRLF) Case Else ConsoleWrite("8" & @CRLF) EndSwitch Controls, File Explorer, ROT objects, UI Automation, Windows Message MonitorCompiled code: Accessing AutoIt variables, DotNet.au3 UDF, Using C# and VB codeShell menus: The Context menu, The Favorites menu. Shell related: Control Panel, System Image ListsGraphics related: Rubik's Cube, OpenGL without external libraries, Navigating in an image, Non-rectangular selectionsListView controls: Colors and fonts, Multi-line header, Multi-line items, Checkboxes and icons, Incremental searchListView controls: Virtual ListViews, Editing cells, Data display functions Link to comment Share on other sites More sharing options...
LarsJ Posted October 13, 2016 Share Posted October 13, 2016 New idea. Here you can prioritize the most likely events: Switch $A+$B+$C Case 3 ConsoleWrite("1" & @CRLF) Case 2 Switch True Case $A And $B ConsoleWrite("2" & @CRLF) Case $A And $C ConsoleWrite("3" & @CRLF) Case $B And $C ConsoleWrite("4" & @CRLF) EndSwitch Case 1 Switch True Case $A ConsoleWrite("5" & @CRLF) Case $B ConsoleWrite("6" & @CRLF) Case $C ConsoleWrite("7" & @CRLF) EndSwitch Case 0 ConsoleWrite("8" & @CRLF) EndSwitch Controls, File Explorer, ROT objects, UI Automation, Windows Message MonitorCompiled code: Accessing AutoIt variables, DotNet.au3 UDF, Using C# and VB codeShell menus: The Context menu, The Favorites menu. Shell related: Control Panel, System Image ListsGraphics related: Rubik's Cube, OpenGL without external libraries, Navigating in an image, Non-rectangular selectionsListView controls: Colors and fonts, Multi-line header, Multi-line items, Checkboxes and icons, Incremental searchListView controls: Virtual ListViews, Editing cells, Data display functions Link to comment Share on other sites More sharing options...
spudw2k Posted October 13, 2016 Share Posted October 13, 2016 Does it have to be boolean? Would a binary approach help? Global Enum Step *2 $iA, $iB, $iC ;Global $iA = 1, $iB = 2, $iC = 4 $X = $iA + $iC Select Case $X = 1 ;$iA Case $X = 2 ;$iB Case $X = 3 ;$iA + $iB Case $X = 4 ;$iC Case $X = 5 ;$iA + $iC Case $X = 6 ;$iB + $iC Case $X = 7 ;$iA + $iB + $iC EndSelect Spoiler Things I've Made: Always On Top Tool ◊ AU History ◊ Deck of Cards ◊ HideIt ◊ ICU ◊ Icon Freezer ◊ Ipod Ejector ◊ Junos Configuration Explorer ◊ Link Downloader ◊ MD5 Folder Enumerator ◊ PassGen ◊ Ping Tool ◊ Quick NIC ◊ Read OCR ◊ RemoteIT ◊ SchTasksGui ◊ SpyCam ◊ System Scan Report Tool ◊ System UpTime ◊ Transparency Machine ◊ VMWare ESX Builder Misc Code Snippets: ADODB Example ◊ CheckHover ◊ Detect SafeMode ◊ DynEnumArray ◊ GetNetStatData ◊ HashArray ◊ IsBetweenDates ◊ Local Admins ◊ Make Choice ◊ Recursive File List ◊ Remove Sizebox Style ◊ Retrieve PNPDeviceID ◊ Retrieve SysListView32 Contents ◊ Set IE Homepage ◊ Tickle Expired Password ◊ Transpose Array Projects: Drive Space Usage GUI ◊ LEDkIT ◊ Plasma_kIt ◊ Scan Engine Builder ◊ SpeeDBurner ◊ SubnetCalc Cool Stuff: AutoItObject UDF ◊ Extract Icon From Proc ◊ GuiCtrlFontRotate ◊ Hex Edit Funcs ◊ Run binary ◊ Service_UDF 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