Jump to content

If...Then


Recommended Posts

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 by morepewpew
Link to comment
Share on other sites

  • Moderators

morepewpew,

What have you tried that has not worked?

M23

Public_Domain.png.2d871819fcb9957cf44f4514551a2935.png 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 columns
ChooseFileFolder ---- Single and multiple selections from specified path treeview listing
Date_Time_Convert -- Easily convert date/time formats, including the language used
ExtMsgBox --------- A highly customisable replacement for MsgBox
GUIExtender -------- Extend and retract multiple sections within a GUI
GUIFrame ---------- Subdivide GUIs into many adjustable frames
GUIListViewEx ------- Insert, delete, move, drag, sort, edit and colour ListView items
GUITreeViewEx ------ Check/clear parent and child checkboxes in a TreeView
Marquee ----------- Scrolling tickertape GUIs
NoFocusLines ------- Remove the dotted focus lines from buttons, sliders, radios and checkboxes
Notify ------------- Small notifications on the edge of the display
Scrollbars ----------Automatically sized scrollbars with a single command
StringSize ---------- Automatically size controls to fit text
Toast -------------- Small GUIs which pop out of the notification area

 

Link to comment
Share on other sites

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

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 - 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 (NEW 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

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 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 - 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 (NEW 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

  • Moderators

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 by Melba23
Wrong control in code - sorry!

Public_Domain.png.2d871819fcb9957cf44f4514551a2935.png 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 columns
ChooseFileFolder ---- Single and multiple selections from specified path treeview listing
Date_Time_Convert -- Easily convert date/time formats, including the language used
ExtMsgBox --------- A highly customisable replacement for MsgBox
GUIExtender -------- Extend and retract multiple sections within a GUI
GUIFrame ---------- Subdivide GUIs into many adjustable frames
GUIListViewEx ------- Insert, delete, move, drag, sort, edit and colour ListView items
GUITreeViewEx ------ Check/clear parent and child checkboxes in a TreeView
Marquee ----------- Scrolling tickertape GUIs
NoFocusLines ------- Remove the dotted focus lines from buttons, sliders, radios and checkboxes
Notify ------------- Small notifications on the edge of the display
Scrollbars ----------Automatically sized scrollbars with a single command
StringSize ---------- Automatically size controls to fit text
Toast -------------- Small GUIs which pop out of the notification area

 

Link to comment
Share on other sites

  • Moderators

morepewpew,

Quote

How can I fix this?

What do you think might be a good thing to do?

M23

Public_Domain.png.2d871819fcb9957cf44f4514551a2935.png 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 columns
ChooseFileFolder ---- Single and multiple selections from specified path treeview listing
Date_Time_Convert -- Easily convert date/time formats, including the language used
ExtMsgBox --------- A highly customisable replacement for MsgBox
GUIExtender -------- Extend and retract multiple sections within a GUI
GUIFrame ---------- Subdivide GUIs into many adjustable frames
GUIListViewEx ------- Insert, delete, move, drag, sort, edit and colour ListView items
GUITreeViewEx ------ Check/clear parent and child checkboxes in a TreeView
Marquee ----------- Scrolling tickertape GUIs
NoFocusLines ------- Remove the dotted focus lines from buttons, sliders, radios and checkboxes
Notify ------------- Small notifications on the edge of the display
Scrollbars ----------Automatically sized scrollbars with a single command
StringSize ---------- Automatically size controls to fit text
Toast -------------- Small GUIs which pop out of the notification area

 

Link to comment
Share on other sites

  • Moderators

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

Public_Domain.png.2d871819fcb9957cf44f4514551a2935.png 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 columns
ChooseFileFolder ---- Single and multiple selections from specified path treeview listing
Date_Time_Convert -- Easily convert date/time formats, including the language used
ExtMsgBox --------- A highly customisable replacement for MsgBox
GUIExtender -------- Extend and retract multiple sections within a GUI
GUIFrame ---------- Subdivide GUIs into many adjustable frames
GUIListViewEx ------- Insert, delete, move, drag, sort, edit and colour ListView items
GUITreeViewEx ------ Check/clear parent and child checkboxes in a TreeView
Marquee ----------- Scrolling tickertape GUIs
NoFocusLines ------- Remove the dotted focus lines from buttons, sliders, radios and checkboxes
Notify ------------- Small notifications on the edge of the display
Scrollbars ----------Automatically sized scrollbars with a single command
StringSize ---------- Automatically size controls to fit text
Toast -------------- Small GUIs which pop out of the notification area

 

Link to comment
Share on other sites

  • Moderators

MichaelHB,

Ooops, SciTE autocomplete strikes again! Thanks.

M23

Public_Domain.png.2d871819fcb9957cf44f4514551a2935.png 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 columns
ChooseFileFolder ---- Single and multiple selections from specified path treeview listing
Date_Time_Convert -- Easily convert date/time formats, including the language used
ExtMsgBox --------- A highly customisable replacement for MsgBox
GUIExtender -------- Extend and retract multiple sections within a GUI
GUIFrame ---------- Subdivide GUIs into many adjustable frames
GUIListViewEx ------- Insert, delete, move, drag, sort, edit and colour ListView items
GUITreeViewEx ------ Check/clear parent and child checkboxes in a TreeView
Marquee ----------- Scrolling tickertape GUIs
NoFocusLines ------- Remove the dotted focus lines from buttons, sliders, radios and checkboxes
Notify ------------- Small notifications on the edge of the display
Scrollbars ----------Automatically sized scrollbars with a single command
StringSize ---------- Automatically size controls to fit text
Toast -------------- Small GUIs which pop out of the notification area

 

Link to comment
Share on other sites

  • Moderators

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

Public_Domain.png.2d871819fcb9957cf44f4514551a2935.png 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 columns
ChooseFileFolder ---- Single and multiple selections from specified path treeview listing
Date_Time_Convert -- Easily convert date/time formats, including the language used
ExtMsgBox --------- A highly customisable replacement for MsgBox
GUIExtender -------- Extend and retract multiple sections within a GUI
GUIFrame ---------- Subdivide GUIs into many adjustable frames
GUIListViewEx ------- Insert, delete, move, drag, sort, edit and colour ListView items
GUITreeViewEx ------ Check/clear parent and child checkboxes in a TreeView
Marquee ----------- Scrolling tickertape GUIs
NoFocusLines ------- Remove the dotted focus lines from buttons, sliders, radios and checkboxes
Notify ------------- Small notifications on the edge of the display
Scrollbars ----------Automatically sized scrollbars with a single command
StringSize ---------- Automatically size controls to fit text
Toast -------------- Small GUIs which pop out of the notification area

 

Link to comment
Share on other sites

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 by Trong

Regards,
 

Link to comment
Share on other sites

  • Moderators

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

Public_Domain.png.2d871819fcb9957cf44f4514551a2935.png 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 columns
ChooseFileFolder ---- Single and multiple selections from specified path treeview listing
Date_Time_Convert -- Easily convert date/time formats, including the language used
ExtMsgBox --------- A highly customisable replacement for MsgBox
GUIExtender -------- Extend and retract multiple sections within a GUI
GUIFrame ---------- Subdivide GUIs into many adjustable frames
GUIListViewEx ------- Insert, delete, move, drag, sort, edit and colour ListView items
GUITreeViewEx ------ Check/clear parent and child checkboxes in a TreeView
Marquee ----------- Scrolling tickertape GUIs
NoFocusLines ------- Remove the dotted focus lines from buttons, sliders, radios and checkboxes
Notify ------------- Small notifications on the edge of the display
Scrollbars ----------Automatically sized scrollbars with a single command
StringSize ---------- Automatically size controls to fit text
Toast -------------- Small GUIs which pop out of the notification area

 

Link to comment
Share on other sites

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

  • Moderators

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

Public_Domain.png.2d871819fcb9957cf44f4514551a2935.png 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 columns
ChooseFileFolder ---- Single and multiple selections from specified path treeview listing
Date_Time_Convert -- Easily convert date/time formats, including the language used
ExtMsgBox --------- A highly customisable replacement for MsgBox
GUIExtender -------- Extend and retract multiple sections within a GUI
GUIFrame ---------- Subdivide GUIs into many adjustable frames
GUIListViewEx ------- Insert, delete, move, drag, sort, edit and colour ListView items
GUITreeViewEx ------ Check/clear parent and child checkboxes in a TreeView
Marquee ----------- Scrolling tickertape GUIs
NoFocusLines ------- Remove the dotted focus lines from buttons, sliders, radios and checkboxes
Notify ------------- Small notifications on the edge of the display
Scrollbars ----------Automatically sized scrollbars with a single command
StringSize ---------- Automatically size controls to fit text
Toast -------------- Small GUIs which pop out of the notification area

 

Link to comment
Share on other sites

@Melba32

For example, my bad script:

#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

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