DarkBoost Posted June 15, 2009 Share Posted June 15, 2009 Wondering what a more efficient way to tackle this? I have been previously been doing: If $string = $string[1] And $string = $string[2] And etc... $string = StringSplit("cat|dog|bird|mouse|snake|horse|cow|pig|chicken", "|") If $string = (all of the above strings) Then MsgBox(0, "", "Farm Animals") Else MsgBox(0,"", "Nothing") EndIf Link to comment Share on other sites More sharing options...
nht3004 Posted June 15, 2009 Share Posted June 15, 2009 Wondering what a more efficient way to tackle this? I have been previously been doing: If $string = $string[1] And $string = $string[2] And etc... $string = StringSplit("cat|dog|bird|mouse|snake|horse|cow|pig|chicken", "|") If $string = (all of the above strings) Then MsgBox(0, "", "Farm Animals") Else MsgBox(0,"", "Nothing") EndIfUse EXP pattern or use basic if..else script with AND or use For loop for(loop=0; loop<infinity; loop++) { alert('I love you'); } Link to comment Share on other sites More sharing options...
James Posted June 15, 2009 Share Posted June 15, 2009 Wondering what a more efficient way to tackle this? I have been previously been doing: If $string = $string[1] And $string = $string[2] And etc...Use a For Next loop: $string = StringSplit("cat|dog|bird|mouse|snake|horse|cow|pig|chicken", "|") $input = InputBox("Farm Animals", "What farm animal?") For $i = 0 to Ubound($string) - 1 If($input == $string[i]) Then MsgBox(0, "", "Farm Animals") Else MsgBox(0, "", "Nothing") EndIf Next Blog - Seriously epic web hosting - Twitter - GitHub - Cachet HQ Link to comment Share on other sites More sharing options...
James Posted June 15, 2009 Share Posted June 15, 2009 Damn C++, I've wrapped the expression in parenthesis. Blog - Seriously epic web hosting - Twitter - GitHub - Cachet HQ Link to comment Share on other sites More sharing options...
DarkBoost Posted June 15, 2009 Author Share Posted June 15, 2009 Damn C++, I've wrapped the expression in parenthesis.I like your energy but won't this provide the message box the amount of times that is included in the string which if the string was to be 50+ entries would become quite annoying? Link to comment Share on other sites More sharing options...
James Posted June 15, 2009 Share Posted June 15, 2009 I like your energy but won't this provide the message box the amount of times that is included in the string which if the string was to be 50+ entries would become quite annoying?You're not explaining yourself very well. Blog - Seriously epic web hosting - Twitter - GitHub - Cachet HQ Link to comment Share on other sites More sharing options...
DarkBoost Posted June 15, 2009 Author Share Posted June 15, 2009 You're not explaining yourself very well. I never do... Here is a better scenario which I hope explains better!? expandcollapse popupOpt("MustDeclareVars", 1) Opt("GUIOnEventMode", 1) #Include <GUIConstantsEx.au3> Global $data = "cat|dog|bird|mouse|snake|horse|cow|pig|chicken";currently 9 entries - update 'Func _button()' if adding more... Global $string = StringSplit($data, "|") Global $combo GUICreate("", 300, 100) GUISetOnEvent($GUI_EVENT_CLOSE, "_events") GUISetOnEvent($GUI_EVENT_MINIMIZE, "_events") $combo = GUICtrlCreateCombo("", 20, 20, 260, 20) GUICtrlSetData($combo, $data, "|") GUICtrlCreateButton("check", 130, 50, 50, 20) GUICtrlSetOnEvent(-1, "_button") GUISetState() Do Until GUIGetMsg() = $GUI_EVENT_CLOSE Func _button() If GUICtrlRead($combo) = $string[1] Or GUICtrlRead($combo) = $string[2] Or GUICtrlRead($combo) = $string[3] Or GUICtrlRead($combo) = $string[4] Or GUICtrlRead($combo) = $string[5] Or GUICtrlRead($combo) = $string[6] Or GUICtrlRead($combo) = $string[7] Or GUICtrlRead($combo) = $string[8] Or GUICtrlRead($combo) = $string[9] Then MsgBox(0, "", "Farm Animals") Else MsgBox(0,"", "Nothing") EndIf EndFunc;==> Button Func _events() Select Case @GUI_CtrlId = $GUI_EVENT_CLOSE Exit Case @GUI_CtrlId = $GUI_EVENT_MINIMIZE GUISetState(@SW_MINIMIZE) EndSelect EndFunc;==> Events Link to comment Share on other sites More sharing options...
James Posted June 15, 2009 Share Posted June 15, 2009 I never do... Here is a better scenario which I hope explains better!?I'll take a look. Blog - Seriously epic web hosting - Twitter - GitHub - Cachet HQ Link to comment Share on other sites More sharing options...
James Posted June 15, 2009 Share Posted June 15, 2009 Done. expandcollapse popupOpt("MustDeclareVars", 1) Opt("GUIOnEventMode", 1) #include <GUIConstantsEx.au3> Global $data = "cat|dog|bird|mouse|snake|horse|cow|pig|chicken";currently 9 entries - update 'Func _button()' if adding more... Global $string = StringSplit($data, "|") Global $combo GUICreate("", 300, 100) GUISetOnEvent($GUI_EVENT_CLOSE, "_events") GUISetOnEvent($GUI_EVENT_MINIMIZE, "_events") $combo = GUICtrlCreateCombo("", 20, 20, 260, 20) GUICtrlSetData($combo, $data, "|") GUICtrlCreateButton("check", 130, 50, 50, 20) GUICtrlSetOnEvent(-1, "_button") GUISetState() Do Until GUIGetMsg() = $GUI_EVENT_CLOSE Func _button() For $i = 0 To UBound($string) - 1 If GuiCtrlRead($combo) = $string[$i] Then MsgBox(0, "", "Farm Animals") ExitLoop Else ContinueLoop EndIf Next EndFunc ;==>_button Func _events() Select Case @GUI_CtrlId = $GUI_EVENT_CLOSE Exit Case @GUI_CtrlId = $GUI_EVENT_MINIMIZE GUISetState(@SW_MINIMIZE) EndSelect EndFunc ;==>_events Have fun. Blog - Seriously epic web hosting - Twitter - GitHub - Cachet HQ Link to comment Share on other sites More sharing options...
DarkBoost Posted June 15, 2009 Author Share Posted June 15, 2009 yeah the FOR loop was the obvious solution i was just wondering if there was another way to condense the IF statement without running a loop. Wondering why you are using "UBound($string) - 1" instead of "$string[0]" as this provides the total entries within the array? I am still learning and just wondering if there was an advantage of using one over the other? Link to comment Share on other sites More sharing options...
KaFu Posted June 15, 2009 Share Posted June 15, 2009 Wondering why you are using "UBound($string) - 1" instead of "$string[0]" as this provides the total entries within the array? $string[0] provides the total entries within the array only, if set with "UBound($string) - 1" within the UDF (or by other means, e.g. a counter), stringsplit is on of those func's that do, but $sting[0] can also be the first entry of the array. OS: Win10-22H2 - 64bit - German, AutoIt Version: 3.3.16.1, AutoIt Editor: SciTE, Website: https://funk.eu AMT - Auto-Movie-Thumbnailer (2022-Nov-26) BIC - Batch-Image-Cropper (2023-Apr-01) COP - Color Picker (2009-May-21) DCS - Dynamic Cursor Selector (2024-Feb-16) HMW - Hide my Windows (2018-Sep-16) HRC - HotKey Resolution Changer (2012-May-16) ICU - Icon Configuration Utility (2018-Sep-16) SMF - Search my Files (2023-Jun-03) - THE file info and duplicates search tool SSD - Set Sound Device (2017-Sep-16) Link to comment Share on other sites More sharing options...
Malkey Posted June 15, 2009 Share Posted June 15, 2009 Here are two ways of doing it. ; Local $string = StringSplit("cat|dog|bird|mouse|snake|horse|cow|pig|chicken", "|") Local $res Do $res = "Nothing" Local $input = InputBox("Farm Animals", "What farm animal?") If @error = 1 Then Exit For $i = 0 To UBound($string) - 1 If ($input == $string[$i]) Then $res = "Farm Animals" Next MsgBox(0, "", $res) Until Not Sleep(10) ;or ; Local $string = "cat|dog|bird|mouse|snake|horse|cow|pig|chicken" Local $res Do $res = "Nothing" Local $input = InputBox("Farm Animals", "What farm animal?") If @error = 1 Then Exit If StringInStr($string, $input) <> 0 Then $res = "Farm Animals" MsgBox(0, "", $res) Until Not Sleep(10) ; Link to comment Share on other sites More sharing options...
James Posted June 15, 2009 Share Posted June 15, 2009 DarkBoost, it's loops or lots of if/end ifs... Still loops though Malkey. Blog - Seriously epic web hosting - Twitter - GitHub - Cachet HQ Link to comment Share on other sites More sharing options...
KaFu Posted June 15, 2009 Share Posted June 15, 2009 Here are two ways of doing it. Nice method of combining loops with sleep , never saw or thought about that before. while sleep(500) ConsoleWrite(TimerInit() & @crlf) wend OS: Win10-22H2 - 64bit - German, AutoIt Version: 3.3.16.1, AutoIt Editor: SciTE, Website: https://funk.eu AMT - Auto-Movie-Thumbnailer (2022-Nov-26) BIC - Batch-Image-Cropper (2023-Apr-01) COP - Color Picker (2009-May-21) DCS - Dynamic Cursor Selector (2024-Feb-16) HMW - Hide my Windows (2018-Sep-16) HRC - HotKey Resolution Changer (2012-May-16) ICU - Icon Configuration Utility (2018-Sep-16) SMF - Search my Files (2023-Jun-03) - THE file info and duplicates search tool SSD - Set Sound Device (2017-Sep-16) Link to comment Share on other sites More sharing options...
Malkey Posted June 16, 2009 Share Posted June 16, 2009 Nice method of combining loops with sleep , never saw or thought about that before. while sleep(500) ConsoleWrite(TimerInit() & @crlf) wendDitto, I saw it in a monoceres's script. 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