morepewpew Posted June 5, 2016 Share Posted June 5, 2016 (edited) Hello, i want to create a List with some information in it. Then there is an inputbox in which the user has to put in one of the items in the list. Now I want the script to check wether the input is an element of the list, if it is, then i want to open e.g. a MsgBox with text "exiting", if it doesnt exist the a MsgBox with text "not exiting". How can I solve this? Edited June 5, 2016 by morepewpew Link to comment Share on other sites More sharing options...
Moderators Melba23 Posted June 5, 2016 Moderators Share Posted June 5, 2016 morepewpew, What have you tried that has not worked? M23 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...
morepewpew Posted June 5, 2016 Author Share Posted June 5, 2016 I already tried: Gloabal $info_1 = "info_1" Gloabal $info_2 = "info_2" Gloabal $info_3 = "info_3" $information = GUICtrlCreateList("", XX, XX, XX, XX) $i_input = Inputbot ("", XX, XX, XX, XX) $selection = String(GUICtrlRead($i_input) _GUICtrlListBox_AddString($information, $info_1) _GUICtrlListBox_AddString($information, $info_2) _GUICtrlListBox_AddString($information, $info_3) If $selection == $info1 Then MsgBox(0, "", "true") Else MsgBox(0, "", "falses) EndIf If $selection == $info2 Then MsgBox(0, "", "true") Else MsgBox(0, "", "falses) EndIf If $selection == $info2 Then MsgBox(0, "", "true") Else MsgBox(0, "", "falses) EndIf and Gloabal $info_1 = "info_1" Gloabal $info_2 = "info_2" Gloabal $info_3 = "info_3" $information = GUICtrlCreateList("", XX, XX, XX, XX) $i_input = Inputbot ("", XX, XX, XX, XX) $selection = String(GUICtrlRead($i_input) _GUICtrlListBox_AddString($information, $info_1) _GUICtrlListBox_AddString($information, $info_2) _GUICtrlListBox_AddString($information, $info_3) If $selection <> $info1 Then MsgBox(0, "", "false") Else MsgBox(0, "", "true) EndIf If $selection <> $info2 Then MsgBox(0, "", "false") Else MsgBox(0, "", "true) EndIf If $selection <> $info2 Then MsgBox(0, "", "false") Else MsgBox(0, "", "true) EndIf Link to comment Share on other sites More sharing options...
water Posted June 5, 2016 Share Posted June 5, 2016 Is Inputbot a typo - means: it should be InputBox? My UDFs and Tutorials: Spoiler UDFs:Active Directory (NEW 2022-02-19 - Version 1.6.1.0) - Download - General Help & Support - Example Scripts - WikiExcelChart (2017-07-21 - Version 0.4.0.1) - Download - General Help & Support - Example ScriptsOutlookEX (2021-11-16 - Version 1.7.0.0) - Download - General Help & Support - Example Scripts - WikiOutlookEX_GUI (2021-04-13 - Version 1.4.0.0) - DownloadOutlook Tools (2019-07-22 - Version 0.6.0.0) - Download - General Help & Support - WikiPowerPoint (2021-08-31 - Version 1.5.0.0) - Download - General Help & Support - Example Scripts - WikiTask Scheduler (NEW 2022-07-28 - Version 1.6.0.1) - Download - General Help & Support - Wiki Standard UDFs:Excel - Example Scripts - WikiWord - Wiki Tutorials:ADO - WikiWebDriver - Wiki Link to comment Share on other sites More sharing options...
water Posted June 5, 2016 Share Posted June 5, 2016 (edited) The script you posted doesn't work: You are missing a quote in Else MsgBox(0, "", "true) before the closing bracket (3 times in your script). Edited June 5, 2016 by water My UDFs and Tutorials: Spoiler UDFs:Active Directory (NEW 2022-02-19 - Version 1.6.1.0) - Download - General Help & Support - Example Scripts - WikiExcelChart (2017-07-21 - Version 0.4.0.1) - Download - General Help & Support - Example ScriptsOutlookEX (2021-11-16 - Version 1.7.0.0) - Download - General Help & Support - Example Scripts - WikiOutlookEX_GUI (2021-04-13 - Version 1.4.0.0) - DownloadOutlook Tools (2019-07-22 - Version 0.6.0.0) - Download - General Help & Support - WikiPowerPoint (2021-08-31 - Version 1.5.0.0) - Download - General Help & Support - Example Scripts - WikiTask Scheduler (NEW 2022-07-28 - Version 1.6.0.1) - Download - General Help & Support - Wiki Standard UDFs:Excel - Example Scripts - WikiWord - Wiki Tutorials:ADO - WikiWebDriver - Wiki Link to comment Share on other sites More sharing options...
Moderators Melba23 Posted June 5, 2016 Moderators Share Posted June 5, 2016 (edited) morepewpew, There are many things about that scribble that would prevent it running - I suggest you make more of an effort in future if you want help. Here is a working script that does what you want: #include <GUIConstantsEx.au3> #include <MsgBoxConstants.au3> #include <GuiListBox.au3> $hGUI = GUICreate("Test", 500, 500) $cInput = GUICtrlCreateInput("", 10, 10, 200, 20) $cCheck = GUICtrlCreateButton("Check", 250, 10, 80, 20) $cInformation = GUICtrlCreateList("", 10, 100, 200, 200) GUICtrlSetData($cInformation, "info_1|info_2|info_3") GUISetState() While 1 Switch GUIGetMsg() Case $GUI_EVENT_CLOSE Exit Case $cCheck $sText = GUICtrlRead($cInput) $iIndex = _GUICtrlListBox_FindString($cInformation, $sText) If $iIndex = -1 Then MsgBox($MB_SYSTEMMODAL, "Checked", "Not exiting") Else MsgBox($MB_SYSTEMMODAL, "Checked", "Exiting") Exit EndIf EndSwitch WEnd Study it and work out how it works - do ask questions if you have any. M23 Edited June 5, 2016 by Melba23 Wrong control in code - sorry! 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...
morepewpew Posted June 5, 2016 Author Share Posted June 5, 2016 Well, that wasn't my whole code... @Melba23 If u click the check button without writing something into the input bot the MsgBox says "Existing".. How can I fix this? Link to comment Share on other sites More sharing options...
Moderators Melba23 Posted June 5, 2016 Moderators Share Posted June 5, 2016 morepewpew, Quote How can I fix this? What do you think might be a good thing to do? M23 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...
morepewpew Posted June 5, 2016 Author Share Posted June 5, 2016 (edited) @Melba23 To be honest I do not find the mistake. Edited June 5, 2016 by morepewpew Link to comment Share on other sites More sharing options...
Moderators Melba23 Posted June 5, 2016 Moderators Share Posted June 5, 2016 morepewpew, I would suggest testing the input content to check that there was something there before checking it against the list. I am sure you can manage to add an If...Then to that code. M23 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...
MichaelHB Posted June 5, 2016 Share Posted June 5, 2016 @Melba23 I believe that the line: $iIndex = _GUICtrlListBox_FindString($cInput, $sText) should be: $iIndex = _GUICtrlListBox_FindString($cInformation, $sText) Link to comment Share on other sites More sharing options...
Moderators Melba23 Posted June 5, 2016 Moderators Share Posted June 5, 2016 MichaelHB, Ooops, SciTE autocomplete strikes again! Thanks. M23 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...
MichaelHB Posted June 5, 2016 Share Posted June 5, 2016 Link to comment Share on other sites More sharing options...
Trong Posted June 5, 2016 Share Posted June 5, 2016 IF ..THEN If $selection = $info1 Then MsgBox(64, "1", "true") ElseIf $selection = $info2 Then MsgBox(64, "2", "true") ElseIf $selection = $info3 Then MsgBox(64, "3", "true") Else MsgBox(48, "", "falses") EndIf Regards, Link to comment Share on other sites More sharing options...
Moderators Melba23 Posted June 5, 2016 Moderators Share Posted June 5, 2016 Trong, That method will work fine for a few items in the list, but will become a serious coding problem if there are more. M23 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...
Trong Posted June 5, 2016 Share Posted June 5, 2016 (edited) If only check exists/not exists _GUICtrlListBox_FindString($ControlID,$StringToSearch, 1) is quickly! If you need to read the data for comparison or for use on further, I will: If single item will be used IF THEN ELSE ! If many items will be used Switch ! Edited June 5, 2016 by Trong Regards, Link to comment Share on other sites More sharing options...
Moderators Melba23 Posted June 5, 2016 Moderators Share Posted June 5, 2016 Trong, So you are suggesting making every item in the list a Case within a Switch? What if there are 100 items in the list? Surely using a single command to check the whole list control has to be the better way? M23 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...
morepewpew Posted June 5, 2016 Author Share Posted June 5, 2016 At the moment I made it like this: #include <GUIConstantsEx.au3> #include <MsgBoxConstants.au3> #include <GuiListBox.au3> $hGUI = GUICreate("Test", 500, 500) $cInput = GUICtrlCreateInput("", 10, 10, 200, 20) $cCheck = GUICtrlCreateButton("Check", 250, 10, 80, 20) $cInformation = GUICtrlCreateList("", 10, 100, 200, 200) GUICtrlSetData($cInformation, "info_1|info_2|info_3") GUISetState() While 1 Switch GUIGetMsg() Case $GUI_EVENT_CLOSE Exit Case $cCheck $sText = GUICtrlRead($cInput) $iIndex = _GUICtrlListBox_FindString($cInformation, $sText) If $sText = "" Then MsgBox($MB_SYSTEMMODAL, "Checked", "Empty Inputbox") ElseIf $iIndex = -1 Then MsgBox($MB_SYSTEMMODAL, "Checked", "Not exiting") Else MsgBox($MB_SYSTEMMODAL, "Checked", "Exiting. Input was: " & $sText) Exit EndIf EndSwitch WEnd I will have a list with about 30 Items, do you think this will work? Link to comment Share on other sites More sharing options...
Moderators Melba23 Posted June 5, 2016 Moderators Share Posted June 5, 2016 morepewpew, Quote do you think this will work? Quite possibly - but why do you not check to see if it works rather then expecting someone else to do so for you? M23 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...
Trong Posted June 5, 2016 Share Posted June 5, 2016 @Melba32 For example, my bad script: expandcollapse popup#include <ButtonConstants.au3> #include <DateTimeConstants.au3> #include <EditConstants.au3> #include <GUIConstantsEx.au3> #include <GUIListBox.au3> #include <StaticConstants.au3> #include <WindowsConstants.au3> Global $hGUI = GUICreate("IF", 490, 431, -1, -1) GUICtrlCreateLabel("Select a Command in list or Enter a Command:", 16, 8, 219, 17) Global $sCommand = GUICtrlCreateInput("", 248, 8, 225, 21) Global $ListCommand = GUICtrlCreateList("", 16, 40, 225, 390) Global $bCheck = GUICtrlCreateButton("Check", 248, 40, 81, 57) GUICtrlSetTip(-1, "Check Command exists in the list!") Global $bExecute = GUICtrlCreateButton("Execute", 344, 40, 129, 57) GUICtrlSetTip(-1, "Leave InputBox blank If the selected Command in the list.") GUICtrlCreateMonthCal("2016/06/06", 248, 260, 229, 164) Global $Icon = GUICtrlCreateIcon(@WindowsDir & "\explorer.exe", -1, 304, 110, 128, 128) ;Data test Local $perList = "Kis|Love|Eat|" For $i = 0 To 99 $perList &= "Command_" & Chr(Random(65, 90, 1)) & Chr(Random(97, 122, 1)) & Chr(Random(48, 57, 1)) & Chr(Random(65, 90, 1)) & Chr(Random(97, 122, 1)) & Chr(Random(48, 57, 1)) & "|" Next GUICtrlSetData($ListCommand, $perList) GUISetState(@SW_SHOW) Global $sText, $xText, $iIndex While 1 Switch GUIGetMsg() Case $GUI_EVENT_CLOSE Exit Case $bCheck $sText = GUICtrlRead($sCommand) If (StringStripWS($sText, 8) = "") Then MsgBox($MB_ICONWARNING, "WARNING", 'Please enter a Command to check!', Default, $hGUI) Else $iIndex = _GUICtrlListBox_FindString($ListCommand, $sText, 1) If $iIndex = -1 Then MsgBox($MB_ICONWARNING, "Info", 'Command "' & $sText & '" is Not exiting!', Default, $hGUI) Else MsgBox($MB_ICONINFORMATION, "Info", 'Command "' & $sText & '" is exiting!', Default, $hGUI) EndIf EndIf Case $bExecute $sText = GUICtrlRead($sCommand) $xText = GUICtrlRead($ListCommand) If (StringStripWS($sText, 8) <> "") And $xText = "" Then Local $ASK = MsgBox($MB_ICONQUESTION + $MB_YESNO, "Execute", 'Command: ' & $sText, Default, $hGUI) If $ASK = 6 Then ExecuteCommand($sText) ElseIf (StringStripWS($sText, 8) = "") And $xText <> "" Then Local $ASK = MsgBox($MB_ICONQUESTION + $MB_YESNO, "Execute", 'Command: ' & $xText, Default, $hGUI) If $ASK = 6 Then ExecuteCommand($xText) Else MsgBox($MB_ICONWARNING, "WARNING", 'Please select or Enter a Command!', Default, $hGUI) EndIf EndSwitch WEnd Func ExecuteCommand($fCommand) Local $sOption, $Option2 Switch $fCommand Case "Kiss" $sOption = "xXxX" $Option2 = "FSAF" Case "Love" $sOption = "YyYyY" $Option2 = "YURTH" Case "Eat" $sOption = "zZzZz" $Option2 = "UYITYIUT" ;~ Case "n" ;~ $sOption="n" ;~ $Option2="n" EndSwitch ;...... MsgBox($MB_ICONINFORMATION, "Execute", 'Command: ' & $fCommand & @CRLF & "Do: " & $sOption & @CRLF & "And do: " & $Option2, Default, $hGUI) EndFunc ;==>ExecuteCommand IF or SWITCH too many is bad, with large data best to use the database. I mean, depending on the case will use the IF or SWITCH or something suitable for the purpose of the script. With the goal of finding as mentioned using _GUICtrlListBox_FindString() is right! Regards, 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