Jump to content

Case and If statement help!


 Share

Recommended Posts

Hello there,

I want to make this thing

while 1
Case $Button1
if $Button2 ;Is not pressed
  Then
  MsgBox(0,"Error", "$Button2 is not pressed")
WEnd

$Button2 is disabled when pressed!

GUICtrlSetState($Button2, $GUI_DISABLE)

What i mean is that i want to create a MsgBox while pressing $Button1 in Case $Button2 is not pressed!

Edited by ileandros

I feel nothing.It feels great.

Link to comment
Share on other sites

switch $imaswitchvariable
case $a
;statements excuted on $imaswitchvariable= $a
;...
case $bee
;statements excuted on $imaswitchvariable= $bee
;...
case "liquor store guy"
;statements excuted on $imaswitchvariable= "liquor store guy"
;...
endswitch;end switch $imaswitchvariable

Link to comment
Share on other sites

  • Moderators

ileandros,

If I understand you correctly then this should show you how to do what you want: ;)

#include <GUIConstantsEx.au3>
#include <WindowsConstants.au3>

$hGUI = GUICreate("Test", 500, 500)

$cButton_1 = GUICtrlCreateButton("Button 1", 10, 10, 80, 30)
$cButton_2 = GUICtrlCreateButton("Button 2", 10, 90, 80, 30)

GUISetState(@SW_SHOW)

While 1

    Switch GUIGetMsg()
        Case $GUI_EVENT_CLOSE
            Exit
        Case $cButton_1
            ; Check if button is disabled
            If BitAnd(GUICtrlGetState($cButton_2), $GUI_DISABLE) Then
                MsgBox(0, "Hi", "Button 2 is disabled")
            Else
                MsgBox(0, "Hi", "Button 2 is enabled")
            EndIf
        Case $cButton_2
            ; Disable button
            GUICtrlSetState($cButton_2, $GUI_DISABLE)
    EndSwitch
WEnd

If I have got it wrong then please explain further. :)

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

This was some kind of help but... Here is the situatuation.

$Button2 creates another gui web browser (gui2) in case it is pressed.

$Button1 navigates the web browser gui2 created. (url is picked from the list)

I have also added

$obj = _IEGetObjById($oIE,"test")
$obj.ScrollIntoView()

to the navigate.

In case i press $Button1 while $Button2 is not pressed i get this error

C:UsersdolfiDesktoptestsqd - Copy.au3 (51) : ==> Variable must be of type "Object".:
$obj.ScrollIntoView()
$obj^ ERROR

I want to avoid this error and to create a MsgBox saying that u have to press $Button2 first!!!!

Voila!

I feel nothing.It feels great.

Link to comment
Share on other sites

ileandros,

If I understand you correctly then this should show you how to do what you want: ;)

#include <GUIConstantsEx.au3>
#include <WindowsConstants.au3>

$hGUI = GUICreate("Test", 500, 500)

$cButton_1 = GUICtrlCreateButton("Button 1", 10, 10, 80, 30)
$cButton_2 = GUICtrlCreateButton("Button 2", 10, 90, 80, 30)

GUISetState(@SW_SHOW)

While 1

    Switch GUIGetMsg()
        Case $GUI_EVENT_CLOSE
            Exit
        Case $cButton_1
            ; Check if button is disabled
            If BitAnd(GUICtrlGetState($cButton_2), $GUI_DISABLE) Then
                MsgBox(0, "Hi", "Button 2 is disabled")
            Else
                MsgBox(0, "Hi", "Button 2 is enabled")
            EndIf
        Case $cButton_2
            ; Disable button
            GUICtrlSetState($cButton_2, $GUI_DISABLE)
    EndSwitch
WEnd

If I have got it wrong then please explain further. :)

M23

This is good but i got an issue.

The MsgBox appears as i want to but the problem is it continues appearing even when $Button2 is disable.

Can i make the MsgBox stop/end when $Button2 is pressed/disabled and activate them again in case $Button2 is enabled???

I feel nothing.It feels great.

Link to comment
Share on other sites

  • Moderators

ileandros,

The code already does that - just replace the relevant MsgBox with the code you want to run once the button is pressed/disabled: :)

#include <GUIConstantsEx.au3>
#include <WindowsConstants.au3>

$hGUI = GUICreate("Test", 500, 500)

$cButton_1 = GUICtrlCreateButton("Button 1", 10, 10, 80, 30)
$cButton_2 = GUICtrlCreateButton("Button 2", 10, 90, 80, 30)

$cButton_3 = GUICtrlCreateButton("Re-enable 2", 10, 460, 80, 30)

GUISetState(@SW_SHOW)

While 1

    Switch GUIGetMsg()
        Case $GUI_EVENT_CLOSE
            Exit
        Case $cButton_1
            ; Check if button is disabled
            If BitAnd(GUICtrlGetState($cButton_2), $GUI_DISABLE) Then
                ; Here you put the code that you will run if $cButton_2 is pressed/disabled
            Else
                MsgBox(0, "Hi", "Button 2 is still enabled")
            EndIf
        Case $cButton_2
            ; Disable button
            GUICtrlSetState($cButton_2, $GUI_DISABLE)
        Case $cButton_3
            ; Re-enable button
            GUICtrlSetState($cButton_2, $GUI_ENABLE)
    EndSwitch
WEnd

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

Ouf. I made an example.

Check it out.

#include <ButtonConstants.au3>
#include <GUIConstantsEx.au3>
#include <GUIListBox.au3>
#include <WindowsConstants.au3>
#include <IE.au3>

Local $hGUI2, $oIE, $Button1, $Button2, $Button3, $Button4, $hForm1
_IEErrorHandlerRegister()
$hForm1 = GUICreate("gui1", 230, 170, 230, 230)
$List1 = GUICtrlCreateCombo("", 40,40,150, 100)
GUICtrlSetData(-1,"test1|test2|test3")
GUICtrlSetColor(-1,0x39045A)
$Group1 = GUICtrlCreateGroup("Group 1", 24, 16, 180, 140)
GUICtrlCreateGroup("", -99, -99, 1, 1)
$Button4 = GUICtrlCreateButton("Go!",40,70, 50, 25)
$Button2 = GUICtrlCreateButton("Stop",140,70, 50, 25)
$Button1 = GUICtrlCreateButton("gui2",40,110, 50, 25)
$Button3 = GUICtrlCreateButton("Exit",140,110, 50, 25)
GUISetState(@SW_SHOW)
While 1
$msg = GUIGetMsg(1)
        Switch $msg[1]
            Case $hForm1
                Switch $msg[0]
                    Case $GUI_EVENT_CLOSE
                        ExitLoop
Case $Button2
_IEAction($oIE,"Stop")

Case $Button4
If BitAnd(GUICtrlGetState($Button1), $GUI_DISABLE) Then
                MsgBox(0, "Hi", "Button 1 is disabled")
            Else
                MsgBox(0, "Hi", "Button 1 is enabled")
    EndIf
If GUICtrlRead($List1) = "" Then
MsgBox(0,"Error", "Select from the List")

ElseIf GUICtrlRead($List1) = "test1" Then
_IENavigate($oIE,";Add your url here",1)
$obj = _IEGetObjById($oIE,";Add your id object here")
$obj.ScrollIntoView()
Endif


Case $Button1
                        GUICtrlSetState($Button1, $GUI_DISABLE)
                        gui2()
                EndSwitch
            Case $hGUI2
                Switch $msg[0]
                    Case $GUI_EVENT_CLOSE
                        GUIDelete($hGUI2)
                        GUICtrlSetState($Button1, $GUI_ENABLE)
                EndSwitch
        EndSwitch

WEnd

Func gui2()
$hGUI2 = GUICreate("testgui2", 330, 110, 476, 230)
$oIE = _IECreateEmbedded()
GUICtrlCreateObj($oIE,0,0,330,110)
GUISetState(@SW_SHOW)
EndFunc

Button "Go!" navigates. I tried to swap with the MsgBox as u said but didnt make it.

Edited by ileandros

I feel nothing.It feels great.

Link to comment
Share on other sites

  • Moderators

ileandros,

You could do it like this: :)

#include <ButtonConstants.au3>
#include <GUIConstantsEx.au3>
#include <GUIListBox.au3>
#include <WindowsConstants.au3>
#include <IE.au3>

Local $hGUI2, $oIE, $Button1, $Button2, $Button3, $Button4, $hForm1
_IEErrorHandlerRegister()

$hForm1 = GUICreate("gui1", 230, 170, 230, 230)

$List1 = GUICtrlCreateCombo("", 40, 40, 150, 100)
GUICtrlSetData(-1, "test1|test2|test3")
GUICtrlSetColor(-1, 0x39045A)
$Group1 = GUICtrlCreateGroup("Group 1", 24, 16, 180, 140)
GUICtrlCreateGroup("", -99, -99, 1, 1)
$Button4 = GUICtrlCreateButton("Go!", 40, 70, 50, 25)
$Button2 = GUICtrlCreateButton("Stop", 140, 70, 50, 25)
$Button1 = GUICtrlCreateButton("gui2", 40, 110, 50, 25)
$Button3 = GUICtrlCreateButton("Exit", 140, 110, 50, 25)

GUISetState(@SW_SHOW)

While 1
    $msg = GUIGetMsg(1)
    Switch $msg[1]
        Case $hForm1
            Switch $msg[0]
                Case $GUI_EVENT_CLOSE
                    ExitLoop
                Case $Button2
                    _IEAction($oIE, "Stop")
                Case $Button4
                    ; Is button enabled?
                    If BitAND(GUICtrlGetState($Button1), $GUI_ENABLE) Then
                        ; Yes, so tell user
                        MsgBox(0, "Hi", "You need to press the 'gui2' button  first")
                        ; But if it is disabled we can proceed
                    Else
                        ; Now we se if the combo has a selection
                        If GUICtrlRead($List1) = "" Then
                            ; No, so tell user
                            MsgBox(0, "Error", "Select from the List")
                        ElseIf GUICtrlRead($List1) = "test1" Then
                            _IENavigate($oIE, ";Add your url here", 1)
                            $obj = _IEGetObjById($oIE, ";Add your id object here")
                            $obj.ScrollIntoView()
                        EndIf
                    EndIf

                Case $Button1
                    GUICtrlSetState($Button1, $GUI_DISABLE)
                    gui2()
            EndSwitch
        Case $hGUI2
            Switch $msg[0]
                Case $GUI_EVENT_CLOSE
                    GUIDelete($hGUI2)
                    GUICtrlSetState($Button1, $GUI_ENABLE)
            EndSwitch
    EndSwitch

WEnd

Func gui2()
    $hGUI2 = GUICreate("testgui2", 330, 110, 476, 230)
    $oIE = _IECreateEmbedded()
    GUICtrlCreateObj($oIE, 0, 0, 330, 110)
    GUISetState(@SW_SHOW)
EndFunc   ;==>gui2

But if I may, I think you are going about this the wrong way. I would disable the "Go!" button unless $hGUI2 had been created. That way you do not have a problem. ;)

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 knew it was so damn simple.!!!!!!!!!!!! I'm an idiot.

Yeah that would be a good idea but i need to inform others what to do.

Thats why i'm making MsgBox.

Thank you and plz follow a little bit more this topic in case i need some more assistance!

I feel nothing.It feels great.

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