MariusN Posted October 12, 2013 Share Posted October 12, 2013 Hi guys...Is there a shorter way of coding the following code ---> If $read1 = 4 And $read2 = 4 And $read3 = 4 And $read4 = 4 And $read5 = 4 And $read6 = 4 Then ...tia Link to comment Share on other sites More sharing options...
water Posted October 12, 2013 Share Posted October 12, 2013 If you have to check 4 variables you have to check 4 variables. No shorter way I can think of. MariusN 1 My UDFs and Tutorials: Spoiler UDFs: Active Directory (NEW 2024-07-28 - Version 1.6.3.0) - Download - General Help & Support - Example Scripts - Wiki ExcelChart (2017-07-21 - Version 0.4.0.1) - Download - General Help & Support - Example Scripts OutlookEX (2021-11-16 - Version 1.7.0.0) - Download - General Help & Support - Example Scripts - Wiki OutlookEX_GUI (2021-04-13 - Version 1.4.0.0) - Download Outlook Tools (2019-07-22 - Version 0.6.0.0) - Download - General Help & Support - Wiki PowerPoint (2021-08-31 - Version 1.5.0.0) - Download - General Help & Support - Example Scripts - Wiki Task Scheduler (2022-07-28 - Version 1.6.0.1) - Download - General Help & Support - Wiki Standard UDFs: Excel - Example Scripts - Wiki Word - Wiki Tutorials: ADO - Wiki WebDriver - Wiki Link to comment Share on other sites More sharing options...
Moderators Melba23 Posted October 12, 2013 Moderators Share Posted October 12, 2013 MariusN,Depending on the possible values of the variables you might be able to use:If ($read1 + $read2 + $read3 + $read4 + $read5 + $read6) = 24 ThenObviously that will only work if the values are always numeric AND the value of each variable cannot be more than 4. M23 MariusN 1 Any of my own code posted anywhere on the forum is available for use by others without any restriction of any kind Open spoiler to see my UDFs: Spoiler ArrayMultiColSort ---- Sort arrays on multiple columnsChooseFileFolder ---- Single and multiple selections from specified path treeview listingDate_Time_Convert -- Easily convert date/time formats, including the language usedExtMsgBox --------- A highly customisable replacement for MsgBoxGUIExtender -------- Extend and retract multiple sections within a GUIGUIFrame ---------- Subdivide GUIs into many adjustable framesGUIListViewEx ------- Insert, delete, move, drag, sort, edit and colour ListView itemsGUITreeViewEx ------ Check/clear parent and child checkboxes in a TreeViewMarquee ----------- Scrolling tickertape GUIsNoFocusLines ------- Remove the dotted focus lines from buttons, sliders, radios and checkboxesNotify ------------- Small notifications on the edge of the displayScrollbars ----------Automatically sized scrollbars with a single commandStringSize ---------- Automatically size controls to fit textToast -------------- Small GUIs which pop out of the notification area Link to comment Share on other sites More sharing options...
DatMCEyeBall Posted October 12, 2013 Share Posted October 12, 2013 (edited) Depending on the script $read could be an array. Global $read[6] ; ... code to set values here $fCondition = True For $i = 0 to 5 If $read[$i] <> 4 then $fCondition = False Exitloop EndIf Next If $fCondition then ; Code here EndIf Of course that's not shorter... Edited October 12, 2013 by DatMCEyeBall MariusN 1 "Just be fred, all we gotta do, just be fred." -Vocaliod "That is a Hadouken. A KAMEHAMEHA would have taken him 13 days and 54 episodes to form." - Roden Hoxha @tabhooked Clock made of cursors ♣ Desktop Widgets ♣ Water Simulation Link to comment Share on other sites More sharing options...
Guest Posted October 12, 2013 Share Posted October 12, 2013 i also want shorter way for this: If $TerminateKey = "OFF" Or $TerminateKey = "F1" Or $TerminateKey = "F2" Or $TerminateKey = "F3" Or $TerminateKey = "F4" Or $TerminateKey = "F5" Or $TerminateKey = "F6" Or $TerminateKey = "F8" Or $TerminateKey = "F8" Or $TerminateKey = "F9" Or $TerminateKey = "F10" Or $TerminateKey = "F11" Or $TerminateKey = "F12" Then Link to comment Share on other sites More sharing options...
DatMCEyeBall Posted October 12, 2013 Share Posted October 12, 2013 (edited) Global $sTerminateKeys[13] = ; Keys here For $i = 0 To 12 If $TerminateKey = $sTerminateKeys[$i] Then ; Do something Exitloop EndIf Next Same solution as above. Edited October 12, 2013 by DatMCEyeBall "Just be fred, all we gotta do, just be fred." -Vocaliod "That is a Hadouken. A KAMEHAMEHA would have taken him 13 days and 54 episodes to form." - Roden Hoxha @tabhooked Clock made of cursors ♣ Desktop Widgets ♣ Water Simulation Link to comment Share on other sites More sharing options...
Guest Posted October 12, 2013 Share Posted October 12, 2013 more shorter way : this is my Function expandcollapse popup; Example 1 If _IfAndOr("a","a|a|a|a","and") = 1 Then ; This equal to - if a = a And a = a And a = a And a = a MsgBox(0,"","Condition exist") Else MsgBox(0,"","Condition Not exist") EndIf ; Example 2 If _IfAndOr("a","a|a|a|b","and") = 1 Then ; This equal to - if a = a And a = a And a = a And a = b MsgBox(0,"","Condition exist") Else MsgBox(0,"","Condition Not exist") EndIf ; Example 3 If _IfAndOr("a","a|b|c|d","or") = 1 Then ; This equal to - if a = a Or a = b Or a = c Or a = b MsgBox(0,"","Condition exist") Else MsgBox(0,"","Condition Not exist") EndIf Func _IfAndOr($MainVariable,$Variables,$mode) Local $Output = 0 , $count = 0 $var = StringSplit($Variables,"|",1) For $a = 1 To $var[0] If $mode = "or" Then If $MainVariable = $var[$a] Then $Output = 1 ExitLoop EndIf ElseIf $mode = "and" Then If $MainVariable = $var[$a] Then $count = $count+1 If $count = $var[0] Then $Output = 1 EndIf Next Return $Output EndFunc Link to comment Share on other sites More sharing options...
dragan Posted October 12, 2013 Share Posted October 12, 2013 $TerminateKey = "F10" MsgBox(0, $TerminateKey, _IsTerminateKeyOK($TerminateKey)) $TerminateKey = "OFF" MsgBox(0, $TerminateKey, _IsTerminateKeyOK($TerminateKey)) $TerminateKey = "F13" MsgBox(0, $TerminateKey, _IsTerminateKeyOK($TerminateKey)) Func _IsTerminateKeyOK($trmKey) Switch $trmKey Case "OFF", "F1", "F2", "F3", "F4", "F5", "F6", "F7", "F8", "F9", "F10", "F11", "F12" Return True EndSwitch Return False EndFunc ;================================================ dim $Read[7] = [0, 4, 4, 4, 4, 4, 4];$Read[1] = 4, $Read[2] = 4, $Read[3] = 4, $Read[4] = 4, $Read[5] = 4, $Read[6] = 4 MsgBox(0, 'Array equal to 4', _IsReadArrayEqualTo($Read, 4)) Func _IsReadArrayEqualTo($theArray, $theNumber) for $i = 1 to UBound($theArray)-1 if $theArray[$i] <> $theNumber Then Return False Next Return True EndFunc Link to comment Share on other sites More sharing options...
jchd Posted October 12, 2013 Share Posted October 12, 2013 Hi guys...Is there a shorter way of coding the following code ---> If $read1 = 4 And $read2 = 4 And $read3 = 4 And $read4 = 4 And $read5 = 4 And $read6 = 4 Then ...tia If by "shorter" you mean "easier to shoot myself in the foot", then yes there are a fair number of ways. Among them: If $read1 & $read2 & $read3 & $read4 & $read5 & $read6 = "444444" Then But of course there are many other ways to setup creative bugs. MariusN and water 2 This wonderful site allows debugging and testing regular expressions (many flavors available). An absolute must have in your bookmarks.Another excellent RegExp tutorial. Don't forget downloading your copy of up-to-date pcretest.exe and pcregrep.exe hereRegExp tutorial: enough to get startedPCRE v8.33 regexp documentation latest available release and currently implemented in AutoIt beta. SQLitespeed is another feature-rich premier SQLite manager (includes import/export). Well worth a try.SQLite Expert (freeware Personal Edition or payware Pro version) is a very useful SQLite database manager.An excellent eBook covering almost every aspect of SQLite3: a must-read for anyone doing serious work.SQL tutorial (covers "generic" SQL, but most of it applies to SQLite as well)A work-in-progress SQLite3 tutorial. Don't miss other LxyzTHW pages!SQLite official website with full documentation (may be newer than the SQLite library that comes standard with AutoIt) Link to comment Share on other sites More sharing options...
Guest Posted October 12, 2013 Share Posted October 12, 2013 for you: ; Example 1 Local $read1 = 4 , $read2 = 4 , $read3 = 4 , $read4 = 1 , $read5 = 4 If _IfAndOr(4,$read1&"|"&$read2&"|"&$read3&"|"&$read4&"|"&$read5,"and") = 1 Then ; This equal to - if a = a And a = a And a = a And a = a MsgBox(0,"","Condition exist") Else MsgBox(0,"","Condition Not exist") EndIf ; Example 2 Local $read1 = 4 , $read2 = 4 , $read3 = 4 , $read4 = 4 , $read5 = 4 If _IfAndOr(4,$read1&"|"&$read2&"|"&$read3&"|"&$read4&"|"&$read5,"and") = 1 Then ; This equal to - if a = a And a = a And a = a And a = a MsgBox(0,"","Condition exist") Else MsgBox(0,"","Condition Not exist") EndIf Func _IfAndOr($MainVariable,$Variables,$mode) Local $Output = 0 , $count = 0 $var = StringSplit($Variables,"|",1) For $a = 1 To $var[0] If $mode = "or" Then If $MainVariable = $var[$a] Then $Output = 1 ExitLoop EndIf ElseIf $mode = "and" Then If $MainVariable = $var[$a] Then $count = $count+1 If $count = $var[0] Then $Output = 1 EndIf Next Return $Output EndFunc Link to comment Share on other sites More sharing options...
junkew Posted October 12, 2013 Share Posted October 12, 2013 is the intention really shorter or more readable? if $read1=4 and _ $read2=4 and _ $read3=4 and _ $read4=4 and _ $read5=4 _ Then consolewrite("All are four") EndIf for the functionkeys you just could do $TerminateKey="F111" if stringregexp($TerminateKey,"(OFF)|(F[0-9])",0)=1 Then consolewrite("We matched 1" & @CRLF) EndIf If stringinstr("OFF,F1,F2,F3,F4,F5,F6,F7,F8,F9,F10,F11,F12", $TerminateKey) > 0 Then consolewrite("We matched 2" & @CRLF) EndIf I do not know if AutoIT can handle matrix comparison directly (for sure it will not be shorter http://www.extremeoptimization.com/QuickStart/CSharp/MatrixVectorOperations.aspx MariusN 1 FAQ 31 How to click some elements, FAQ 40 Test automation with AutoIt, Multithreading CLR .NET Powershell CMDLets Link to comment Share on other sites More sharing options...
junkew Posted October 12, 2013 Share Posted October 12, 2013 if bitor($read1,$read2,$read3,$read4,$read5,$read6)=4 Then consolewrite("Yes its four") endIf MariusN 1 FAQ 31 How to click some elements, FAQ 40 Test automation with AutoIt, Multithreading CLR .NET Powershell CMDLets Link to comment Share on other sites More sharing options...
Guest Posted October 12, 2013 Share Posted October 12, 2013 (edited) is the intention really shorter or more readable? if $read1=4 and _ $read2=4 and _ $read3=4 and _ $read4=4 and _ $read5=4 _ Then consolewrite("All are four") EndIf for the functionkeys you just could do $TerminateKey="F111" if stringregexp($TerminateKey,"(OFF)|(F[0-9])",0)=1 Then consolewrite("We matched 1" & @CRLF) EndIf If stringinstr("OFF,F1,F2,F3,F4,F5,F6,F7,F8,F9,F10,F11,F12", $TerminateKey) > 0 Then consolewrite("We matched 2" & @CRLF) EndIf I do not know if AutoIT can handle matrix comparison directly (for sure it will not be shorter http://www.extremeoptimization.com/QuickStart/CSharp/MatrixVectorOperations.aspx Thank you.But I developed myself this solution: $TerminateKey="F6" If _IfAndOr($TerminateKey,"OFF|F1|F2|F3|F4|F5|F6|F7|F8|F9|F10|F11|F12","or") = 1 Then MsgBox(0,"","Condition exist") Else MsgBox(0,"","Condition Not exist") EndIf Func _IfAndOr($MainVariable,$Variables,$mode) Local $Output = 0 , $count = 0 $var = StringSplit($Variables,"|",1) For $a = 1 To $var[0] If $mode = "or" Then If $MainVariable = $var[$a] Then $Output = 1 ExitLoop EndIf ElseIf $mode = "and" Then If $MainVariable = $var[$a] Then $count = $count+1 If $count = $var[0] Then $Output = 1 EndIf Next Return $Output EndFunc It works great Edited October 12, 2013 by Guest Link to comment Share on other sites More sharing options...
BrewManNH Posted October 12, 2013 Share Posted October 12, 2013 But that doesn't come close to answering the question of making a one liner shorter. Your code turned making toast in a toaster to making toast with something that Rube Goldberg would have shuddered to contemplate. DatMCEyeBall 1 If I posted any code, assume that code was written using the latest release version unless stated otherwise. Also, if it doesn't work on XP I can't help with that because I don't have access to XP, and I'm not going to.Give a programmer the correct code and he can do his work for a day. Teach a programmer to debug and he can do his work for a lifetime - by Chirag GudeHow to ask questions the smart way! I hereby grant any person the right to use any code I post, that I am the original author of, on the autoitscript.com forums, unless I've specifically stated otherwise in the code or the thread post. If you do use my code all I ask, as a courtesy, is to make note of where you got it from. Back up and restore Windows user files _Array.au3 - Modified array functions that include support for 2D arrays. - ColorChooser - An add-on for SciTE that pops up a color dialog so you can select and paste a color code into a script. - Customizable Splashscreen GUI w/Progress Bar - Create a custom "splash screen" GUI with a progress bar and custom label. - _FileGetProperty - Retrieve the properties of a file - SciTE Toolbar - A toolbar demo for use with the SciTE editor - GUIRegisterMsg demo - Demo script to show how to use the Windows messages to interact with controls and your GUI. - Latin Square password generator Link to comment Share on other sites More sharing options...
jchd Posted October 12, 2013 Share Posted October 12, 2013 if bitor($read1,$read2,$read3,$read4,$read5,$read6)=4 Then consolewrite("Yes its four") endIf A good example about how to shoot yourself in the foot. Make $read1 = 4, $read2 to $read6 = 0 and you're set This wonderful site allows debugging and testing regular expressions (many flavors available). An absolute must have in your bookmarks.Another excellent RegExp tutorial. Don't forget downloading your copy of up-to-date pcretest.exe and pcregrep.exe hereRegExp tutorial: enough to get startedPCRE v8.33 regexp documentation latest available release and currently implemented in AutoIt beta. SQLitespeed is another feature-rich premier SQLite manager (includes import/export). Well worth a try.SQLite Expert (freeware Personal Edition or payware Pro version) is a very useful SQLite database manager.An excellent eBook covering almost every aspect of SQLite3: a must-read for anyone doing serious work.SQL tutorial (covers "generic" SQL, but most of it applies to SQLite as well)A work-in-progress SQLite3 tutorial. Don't miss other LxyzTHW pages!SQLite official website with full documentation (may be newer than the SQLite library that comes standard with AutoIt) Link to comment Share on other sites More sharing options...
MariusN Posted October 12, 2013 Author Share Posted October 12, 2013 Ok thx guys...i came to the conclusion the one i used IS the shortest way, lol Thx for all the replies and help though Link to comment Share on other sites More sharing options...
Guest Posted October 12, 2013 Share Posted October 12, 2013 But that doesn't come close to answering the question of making a one liner shorter. Your code turned making toast in a toaster to making toast with something that Rube Goldberg would have shuddered to contemplate. I do not understand why. this line: If _IfAndOr($TerminateKey,"F1|F2|F3|F4|F5|F6|F7|F8|F9|F10|F11|F12","or") = 1 Then does not seem to you shorter than this line ?: If $ TerminateKey = "OFF" Or $ TerminateKey = "F1" Or $ TerminateKey = "F2" Or $ TerminateKey = "F3" Or $ TerminateKey = "F4" Or $ TerminateKey = "F5" Or $ TerminateKey = "F6" Or $ TerminateKey = "F8" Or $ TerminateKey = "F8" Or $ TerminateKey = "F9" Or $ TerminateKey = "F10" Or $ TerminateKey = "F11" Or $ TerminateKey = "F12" Then? and this line (Suggested by junkew) : If stringinstr("OFF,F1,F2,F3,F4,F5,F6,F7,F8,F9,F10,F11,F12", $TerminateKey) > 0 Then is a bad Idea. At first it seemed a good idea. But on second thought, it will also work when $TerminateKey = "," or $TerminateKey = "OFF,F1,F2,F3,F4,F5,F6,F7,F8,F9,F10,F11,F12" or $TerminateKey = "F" or $TerminateKey = Number from 1 to 12 or $TerminateKey = "F10,F11" .. a lot of bugs can Happen with this line. Link to comment Share on other sites More sharing options...
MariusN Posted October 12, 2013 Author Share Posted October 12, 2013 MariusN, Depending on the possible values of the variables you might be able to use: If ($read1 + $read2 + $read3 + $read4 + $read5 + $read6) = 24 Then Obviously that will only work if the values are always numeric AND the value of each variable cannot be more than 4. M23 ...good one...thx Melba Link to comment Share on other sites More sharing options...
Gianni Posted October 12, 2013 Share Posted October 12, 2013 Hi guys...Is there a shorter way of coding the following code ---> If $read1 = 4 And $read2 = 4 And $read3 = 4 And $read4 = 4 And $read5 = 4 And $read6 = 4 Then ...tia Yes!, there is a way to shorten: If $read1=4 And $read2=4 And $read3=4 And $read4=4 And $read5=4 And $read6=4 Then remove the spaces before and after the = sign ....... Danyfirex 1 Chimp small minds discuss people average minds discuss events great minds discuss ideas.... and use AutoIt.... Link to comment Share on other sites More sharing options...
Gianni Posted October 12, 2013 Share Posted October 12, 2013 MariusN, Depending on the possible values of the variables you might be able to use: If ($read1 + $read2 + $read3 + $read4 + $read5 + $read6) = 24 Then Obviously that will only work if the values are always numeric AND the value of each variable cannot be more than 4. M23 another similar way without the need to check the sum: if ($read1 = 4) * ($read2 = 4) * ($read3 = 4) * ($read4 = 4) * ($read5 = 4) * ($read6 = 4) Then Shrapnel 1 Chimp small minds discuss people average minds discuss events great minds discuss ideas.... and use AutoIt.... 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