Sign in to follow this  
Followers 0
carteblanche619

Switch Case Help

8 posts in this topic

Why is this code not working the way its supposed to???

Where am I going wrong???

Plz Help

#include <Constants.au3>
#include <GuiToolbar.au3>
#include <ButtonConstants.au3>
#include <EditConstants.au3>
#include <GUIConstantsEx.au3>
#include <GuiStatusBar.au3>
#include <ProgressConstants.au3>
#include <StaticConstants.au3>
#include <TabConstants.au3>
#include <WindowsConstants.au3>
#include <IE.au3> 
#include <String.au3>
#include <Misc.au3>
      
      #Region ### START Koda GUI section ### Form=
      $FirstRun = GUICreate("Dialog", 306, 226, 346, 262, BitOR($WS_SYSMENU,$WS_POPUP))
      GUICtrlCreateGroup("", 8, 1, 289, 185)
      GUICtrlCreateLabel("Welcome User,", 24, 16, 77, 17)
      GUICtrlCreateLabel("Kindly enter a password", 24, 72, 219, 17)
      $FirstRunPass1 = GUICtrlCreateInput("", 32, 96, 241, 21, BitOR($GUI_SS_DEFAULT_INPUT,$ES_CENTER,$ES_PASSWORD))
      $FirstRunPass2 = GUICtrlCreateInput("", 32, 152, 241, 21, BitOR($GUI_SS_DEFAULT_INPUT,$ES_CENTER,$ES_PASSWORD))
      GUICtrlCreateLabel("Re-enter the same password again", 24, 128, 168, 17)
      GUICtrlCreateGroup("", -99, -99, 1, 1)
      $OK = GUICtrlCreateButton("&OK", 65, 195, 75, 25)
      $Cancel = GUICtrlCreateButton("&Cancel", 162, 195, 75, 25)
      GUISetState(@SW_SHOW)
      #EndRegion ### END Koda GUI section ###

      
   While 1
       $nMsg = GUIGetMsg()
       Switch $nMsg
            Case $GUI_EVENT_CLOSE, $Cancel
               Exit
            Case $OK, _IsPressed("0D")
               
               $FirstRunPass1Value = GUICtrlRead($FirstRunPass1)
               $FirstRunPass2Value = GUICtrlRead($FirstRunPass2)
               $Match = StringCompare($FirstRunPass1Value, $FirstRunPass2Value,1)
               If $Match = 0 Then
                  MsgBox(64, "Done", "Passwords match successfully.")
                  ;;Do Something
                  Exit
               Else
                  MsgBox(16, "Error", "Passwords don't match. Please enter again")
               EndIf
       EndSwitch
   WEnd

Share this post


Link to post
Share on other sites



Sorry about the number of includes...this code is a part from large piece of code :/

Share this post


Link to post
Share on other sites

Why is this code not working the way its supposed to???

Where am I going wrong???

Plz Help

 

Care to share what the code is supposed to do that isn't working or are you expecting us to just understand? ;)

Jos


Visit the SciTE4AutoIt3 Download page for the latest versions        Beta files                                                          Forum Rules
 
Live for the present,
Dream of the future,
Learn from the past.
  :)

Share this post


Link to post
Share on other sites

What?

When you launch this code, it terminates saying Passwords don't match successfully

while what I want is that it should wait until I press OK or Enter("_IsPressed("0D")")

Share this post


Link to post
Share on other sites

I think you have a problem in this line:

Case $OK, _IsPressed("0D")

You can not ask for _IsPressed() with GuiGetMsg(). You must ask for _IsPressed outside the switch-statement.


Best Regards BugFix  

Share this post


Link to post
Share on other sites

What?

When you launch this code, it terminates saying Passwords don't match successfully

while what I want is that it should wait until I press OK or Enter("_IsPressed("0D")")

Not sure why you first ask what I want and then still supply the answer to the question...

Get rid of the _IsPressed() on the case statement and set the OK button as default so when you press Enter you also fire the Ok button.

Jos

1 person likes this

Visit the SciTE4AutoIt3 Download page for the latest versions        Beta files                                                          Forum Rules
 
Live for the present,
Dream of the future,
Learn from the past.
  :)

Share this post


Link to post
Share on other sites

But this works perfectly fine

#include <Constants.au3>
#include <GuiToolbar.au3>
#include <ButtonConstants.au3>
#include <EditConstants.au3>
#include <GUIConstantsEx.au3>
#include <GuiStatusBar.au3>
#include <ProgressConstants.au3>
#include <StaticConstants.au3>
#include <TabConstants.au3>
#include <WindowsConstants.au3>
#include <IE.au3> 
#include <String.au3>
#include <Misc.au3>
      
      #Region ### START Koda GUI section ### Form=
      $FirstRun = GUICreate("Dialog", 306, 226, 346, 262, BitOR($WS_SYSMENU,$WS_POPUP))
      GUICtrlCreateGroup("", 8, 1, 289, 185)
      GUICtrlCreateLabel("Welcome User,", 24, 16, 77, 17)
      GUICtrlCreateLabel("Kindly enter a password", 24, 72, 219, 17)
      $FirstRunPass1 = GUICtrlCreateInput("", 32, 96, 241, 21, BitOR($GUI_SS_DEFAULT_INPUT,$ES_CENTER,$ES_PASSWORD))
      $FirstRunPass2 = GUICtrlCreateInput("", 32, 152, 241, 21, BitOR($GUI_SS_DEFAULT_INPUT,$ES_CENTER,$ES_PASSWORD))
      GUICtrlCreateLabel("Re-enter the same password again", 24, 128, 168, 17)
      GUICtrlCreateGroup("", -99, -99, 1, 1)
      $OK = GUICtrlCreateButton("&OK", 65, 195, 75, 25)
      $Cancel = GUICtrlCreateButton("&Cancel", 162, 195, 75, 25)
      GUISetState(@SW_SHOW)
      #EndRegion ### END Koda GUI section ###
      
While 1
$nMsg = GUIGetMsg()
       Select
            Case $nMsg = $GUI_EVENT_CLOSE Or $nMsg = $Cancel
               Exit
            Case $nMsg = $OK Or _IsPressed("0D")
               
               $FirstRunPass1Value = GUICtrlRead($FirstRunPass1)
               $FirstRunPass2Value = GUICtrlRead($FirstRunPass2)
               $Match = StringCompare($FirstRunPass1Value, $FirstRunPass2Value,1)
               If $Match = 0 Then
                  MsgBox(64, "Done", "Passwords match successfully.")
                  ;;Do Something
                  Exit
               Else
                  MsgBox(16, "Error", "Passwords don't match. Please enter again")
               EndIf
       EndSelect
The reason I am switching from select case to switch case for all GUIs is that I am trying to handle multiple GUIs...so I cannot use switch somewhere and somewhere select...so I have to make this work out using switch

Share this post


Link to post
Share on other sites

KK... $BS_DEFPUSHBUTTON worked fine for me

Thanks Jos :)

***Solved***

Share this post


Link to post
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
Sign in to follow this  
Followers 0