Jump to content

More than one if elseif else control problems?


Recommended Posts

I can not control how do I do it right?

#include <ButtonConstants.au3>
#include <EditConstants.au3>
#include <GUIConstantsEx.au3>
#include <StaticConstants.au3>
#include <WindowsConstants.au3>
$Form1 = GUICreate("Form1", 800, 217)

$Input1 = GUICtrlCreateInput("", 74, 48, 649, 21);E-mail entry
$Input3 = GUICtrlCreateInput("", 74, 160, 649, 21);E-mail Verification
$Input4 = GUICtrlCreateInput("", 344, 128, 377, 21);$Input3Control = "asdf"

$Button1 = GUICtrlCreateButton("Button1", 74, 184, 75, 25)
GUISetState(@SW_SHOW)

While 1
    $nMsg = GUIGetMsg()
    Switch $nMsg
        Case $GUI_EVENT_CLOSE
            Exit

        Case $Button1
            $Input3Control = "asdf"
            $aReadMail = GUICtrlRead($Input1)
            $aRegex = StringRegExp($aReadMail, '^[a-zA-Z0-9._%+-]+@[a-zA-Z0-9.-]+\.[a-zA-Z]{2,63}$', 3)
            $inputcontrol3 = guictrlread($Input3)
            $inputcontrol4 = GUICtrlRead($Input4)
            
                If guictrlread($input1) = "" or guictrlread($Input3) = "" Or guictrlread($Input4) = "" Then
                MsgBox(48,"Error","Please fill in all fields!",5)
                ElseIf Not IsArray($aRegex) or $aReadMail <> $inputcontrol4 Then
                MsgBox(48,"Error","This is not an email!",5)
                If IsArray($aRegex) Then
                MsgBox(64,"Ok","No Problem",5)
                ElseIf Not IsArray($aRegex) Then
                MsgBox(48,"Error","E-mail verification is wrong",5)
                ElseIf $inputcontrol3 == $Input3Control Then
                MsgBox(48,"Error","$Input3Control Did not match!",5)
                EndIf
                EndIf
    EndSwitch
WEnd

 

Link to comment
Share on other sites

  • Moderators

What about a Select statement, to make it easier for you. It will also help you pinpoint where things are going wrong so you can inform the user, rather than just a blanket statement. Like so:

#include <ButtonConstants.au3>
#include <EditConstants.au3>
#include <GUIConstantsEx.au3>
#include <StaticConstants.au3>
#include <WindowsConstants.au3>
$Form1 = GUICreate("Form1", 800, 217)

$Input1 = GUICtrlCreateInput("", 74, 48, 649, 21);E-mail entry
$Input3 = GUICtrlCreateInput("", 74, 160, 649, 21);E-mail Verification
$Input4 = GUICtrlCreateInput("", 344, 128, 377, 21);$Input3Control = "asdf"

$Button1 = GUICtrlCreateButton("Button1", 74, 184, 75, 25)
GUISetState(@SW_SHOW)

While 1
    $nMsg = GUIGetMsg()
    Switch $nMsg
        Case $GUI_EVENT_CLOSE
            Exit

        Case $Button1
            $Input3Control = "asdf"
            $aReadMail = GUICtrlRead($Input1)
            $aRegex = StringRegExp($aReadMail, '^[a-zA-Z0-9._%+-]+@[a-zA-Z0-9.-]+\.[a-zA-Z]{2,63}$', 3)
            $inputcontrol3 = guictrlread($Input3)
            $inputcontrol4 = GUICtrlRead($Input4)
                Select
                    Case GUICtrlRead($input1) = ""
                        MsgBox(48, "Error - Missing Field", "Please enter an email address")
                    Case GUICtrlRead($Input3) <> GUICtrlRead($Input1)
                        MsgBox(48, "Error - Missing Field", "Email address and verification don't match")
                    Case GUICtrlRead($Input4) = ""
                        MsgBox(48, "Error - Missing Field", "Please enter text")
                    Case Else
                        ;Rest of If statements
                EndSelect
    EndSwitch
WEnd

I would suggest revisiting your other If statements, as they are throwing false positives. But this should at least give you an idea of a cleaner way

"Profanity is the last vestige of the feeble mind. For the man who cannot express himself forcibly through intellect must do so through shock and awe" - Spencer W. Kimball

How to get your question answered on this forum!

Link to comment
Share on other sites

There is still a problem :(

If it is not correct the last reason is giving the okay message!

Spoiler

yVGq3eKbTSmIQ1l2frtGjw.png

#include <ButtonConstants.au3>
#include <EditConstants.au3>
#include <GUIConstantsEx.au3>
#include <StaticConstants.au3>
#include <WindowsConstants.au3>
$Form1 = GUICreate("Form1", 800, 217)

$Input1 = GUICtrlCreateInput("Input1@hotmail.com", 74, 48, 649, 21);E-mail entry
$Input3 = GUICtrlCreateInput("Input1@hotmail.c", 344, 128, 377, 21);E-mail Verification
$Input4 = GUICtrlCreateInput("asdf", 74, 160, 649, 21);$Input3Control = "asdf"


$Button1 = GUICtrlCreateButton("Button1", 74, 184, 75, 25)
GUISetState(@SW_SHOW)

While 1
    $nMsg = GUIGetMsg()
    Switch $nMsg
        Case $GUI_EVENT_CLOSE
            Exit

        Case $Button1
            $Input3Control = "asdf"
            $aReadMail = GUICtrlRead($Input1)
            $aRegex = StringRegExp($aReadMail, '^[a-zA-Z0-9._%+-]+@[a-zA-Z0-9.-]+\.[a-zA-Z]{2,63}$', 3)
            $inputcontrol3 = GUICtrlRead($Input3)
            $inputcontrol4 = GUICtrlRead($Input4)
                Select
                    Case GUICtrlRead($input1) = ""
                        MsgBox(48, "Error - Missing Field", "Please enter an email address")
                    Case GUICtrlRead($Input3) <> GUICtrlRead($Input1)
                        MsgBox(48, "Error - Missing Field", "Email address and verification don't match")
                    Case GUICtrlRead($Input4) = ""
                        MsgBox(48, "Error - Missing Field", "Please enter text")
                    Case GUICtrlRead($Input4) <> $Input3Control
                        MsgBox(48, "Error - Missing Field", "Entries are not the same")
                EndSelect
                If IsArray($aRegex) Then
                    MsgBox(64,"Ok","No Problem",5)
                    Else
                    MsgBox(48,"Error","This is not an email!",5)
                    EndIf
    EndSwitch
WEnd

 

Edited by youtuber
Link to comment
Share on other sites

  • Moderators

You will need to wait for one of our Regex gurus to wander by, as I am not great help in that area. That is what I meant when I said you were getting false positives before; the syntax looks wrong but I wouldn't be the best at suggesting alternatives.

"Profanity is the last vestige of the feeble mind. For the man who cannot express himself forcibly through intellect must do so through shock and awe" - Spencer W. Kimball

How to get your question answered on this forum!

Link to comment
Share on other sites

I still have problems, please help me :(

Should it be this way?

#include <ButtonConstants.au3>
#include <EditConstants.au3>
#include <GUIConstantsEx.au3>
#include <StaticConstants.au3>
#include <WindowsConstants.au3>
$Form1 = GUICreate("Form1", 800, 217)

$Input1 = GUICtrlCreateInput("Input1@hotmail.com", 74, 48, 649, 21);E-mail entry
$Input3 = GUICtrlCreateInput("Input1@hotmail.c", 344, 128, 377, 21);E-mail Verification
$Input4 = GUICtrlCreateInput("asdf", 74, 160, 649, 21);$Input3Control = "asdf"

$Button1 = GUICtrlCreateButton("Button1", 74, 184, 75, 25)
GUISetState(@SW_SHOW)
While 1
    $nMsg = GUIGetMsg()
    Switch $nMsg
        Case $GUI_EVENT_CLOSE
            Exit

        Case $Button1
            $Input3Control = "asdf"
            $aReadMail = GUICtrlRead($Input1)
            $aRegex = StringRegExp($aReadMail, '^[a-zA-Z0-9._%+-]+@[a-zA-Z0-9.-]+\.[a-zA-Z]{2,63}$', 3)
            $inputcontrol3 = GUICtrlRead($Input3)
            $inputcontrol4 = GUICtrlRead($Input4)
                Select
                    Case GUICtrlRead($input1) = ""
                        MsgBox(48, "Error - Missing Field", "Please enter an email address")
                    Case GUICtrlRead($Input3) <> GUICtrlRead($Input1)
                        MsgBox(48, "Error - Missing Field", "Email address and verification don't match")
                    Case GUICtrlRead($Input4) = ""
                        MsgBox(48, "Error - Missing Field", "Please enter text")
                    Case GUICtrlRead($Input4) <> $Input3Control
                        MsgBox(48, "Error - Missing Field", "Entries are not the same")
                        If Not IsArray($aRegex) Then
                             MsgBox(48,"Error","This is not an email!",5)
                        ElseIf IsArray($aRegex) Then
                    MsgBox(64,"Ok","No Problem",5)
                    EndIf
                EndSelect
    EndSwitch
WEnd

 

Link to comment
Share on other sites

Hi.

I don't know exactly what you try. I guess you want to try these:

#include <ButtonConstants.au3>
#include <EditConstants.au3>
#include <GUIConstantsEx.au3>
#include <StaticConstants.au3>
#include <WindowsConstants.au3>
$Form1 = GUICreate("Form1", 800, 217)

$Input1 = GUICtrlCreateInput("Input1@hotmail.com", 74, 48, 649, 21);E-mail entry
$Input3 = GUICtrlCreateInput("Input1@hotmail.c", 344, 128, 377, 21);E-mail Verification
$Input4 = GUICtrlCreateInput("asdf", 74, 160, 649, 21);$Input3Control = "asdf"

$Button1 = GUICtrlCreateButton("Button1", 74, 184, 75, 25)
GUISetState(@SW_SHOW)
While 1
    $nMsg = GUIGetMsg()
    Switch $nMsg
        Case $GUI_EVENT_CLOSE
            Exit

        Case $Button1
            $Input3Control = "asdf"
            $aReadMail = GUICtrlRead($Input1)
            $aRegex = StringRegExp($aReadMail, '^[a-zA-Z0-9._%+-]+@[a-zA-Z0-9.-]+\.[a-zA-Z]{2,63}$', 3)
            $inputcontrol3 = GUICtrlRead($Input3)
            $inputcontrol4 = GUICtrlRead($Input4)
                Select
                    Case Not IsArray($aRegex)
                        MsgBox(48,"Error","This is not an email!",5)
                    Case GUICtrlRead($input1) = ""
                        MsgBox(48, "Error - Missing Field", "Please enter an email address")
                    Case GUICtrlRead($Input3) <> GUICtrlRead($Input1)
                        MsgBox(48, "Error - Missing Field", "Email address and verification don't match")
                    Case GUICtrlRead($Input4) = ""
                        MsgBox(48, "Error - Missing Field", "Please enter text")
                    Case GUICtrlRead($Input4) <> $inputcontrol3
                        MsgBox(48, "Error - Missing Field", "Entries are not the same")
                    Case Else
                        MsgBox(64,"Ok","No Problem",5)
                EndSelect
    EndSwitch
WEnd

First you want to check if email adress is correct so have should do it the first case. (Because cases will be done from top to bottom. If one case matches no further conditions will be tested.) And at the last case you typed '$Input3Control' but it is not existing. You meant '$inputcontrol3'?

Regards, Conrad

Edited by Simpel
spelling
SciTE4AutoIt = 3.7.3.0   AutoIt = 3.3.14.2   AutoItX64 = 0   OS = Win_10   Build = 19044   OSArch = X64   Language = 0407/german
H:\...\AutoIt3\SciTE     H:\...\AutoIt3      H:\...\AutoIt3\Include     (H:\ = Network Drive)

   88x31.png  Any of my own code posted anywhere on the forum is available for use by others without any restriction of any kind.

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