Jump to content

While Not question


gahhon
 Share

Recommended Posts

While Not _Login()
    _Initial_Check()
WEnd

Func _Login()
    Local $FLAG_LOGIN = _Password_Check()

    If @error = 1 Then
        _Close_Application()
    ElseIf @error = 2 Then
        _Metro_MsgBox(0, "", $FLAG_LOGIN)
        Return False
    Else ; $FLAG_LOGIN return TRUE
        _Metro_MsgBox(0, "", "Access granted!")
        Return True
    EndIf
EndFunc

 I do have a question regarding the While Not Loop.

According to the code I post above, While Not _Login() is similar to While _Login() = False right?

Which mean when _Login() return False and it will execute the _Initial_Check() function, but somehow the logic is not right and I also don't understand why While Not _Login() loop is executed as expected.

What I wanna achieve is when _Login() is not success, which mean return False then it continue loop the _Login() function until it return True

When It return True only execute the _Initial_Check() function.

Please kindly clarify. Thanks

Link to comment
Share on other sites

On 14/01/2019 at 3:23 PM, Subz said:

You could try something like the following:

Local $bLogin = False
While $bLogin = False
    $bLogin = _Login()
    Sleep(500) ;~ Sleep 500ms and try again
WEnd
_Initial_Check()

 

I think I know why the logic wrong and the wrong logic is works as expected.

While Not _Login()
    _Initial_Check()
WEnd

GUISetState(@SW_SHOW)
While 1
    $nMsg = GUIGetMsg()
    Switch $nMsg
        Case $GUI_EVENT_CLOSE, $GUI_CLOSE_BUTTON, $BTN_EXIT
            _GUIDisable($GUI_MAIN, 0, 30)
            _Close_Application()
        Case $GUI_MINIMIZE_BUTTON
            GUISetState(@SW_MINIMIZE, $GUI_MAIN)
        Case $BTN_LOCKED
            _Lock_Folder()
        Case $BTN_UNLOCKED
            _Unlock_Folder()
        Case $OVERRIDE_FOLDER
            _GUIDisable($GUI_MAIN, 0, 30)
            _Override_Folder()
            _GUIDisable($GUI_MAIN)
    EndSwitch
WEnd

Func _Login()
    Local $FLAG_LOGIN = _Password_Check()

    If @error = 1 Then
        _Close_Application()
    ElseIf @error = 2 Then
        _Metro_MsgBox(0, "", $FLAG_LOGIN)
        Return False
    Else
        _Metro_MsgBox(0, "", "Access granted!")
        Return True
    EndIf
EndFunc

Firstly, While Not _Login() is equivalent to While _Login() = False.

So if _Login() returne False, it go into the While Loop and execute _Initial_Check() but the _Initial_Check() does not return any True/False. Therefore, it continue loop the _Login() function.
So if _Login() return True, it will exit the While Loop and execute the GUI setting.

I am finally understand of it. Thanks lot.

But then I modify my code into like this instead,

While Not _Login()
    _Login()
WEnd

_Initial_Check()

;GUI SETTINGS

When I enter few times wrong password it show Access Denied as expected, but after that I enter correct password it show Access granted and loop 1 more time of _Login()?
As I have tested out, I using Enter Key and Mouse Click result are different.
Enter Key: Result as expected
Mouse Click: Few Time wrong, then enter correct one. It show Access Granted and ask for password again
Any idea?

Edited by gahhon
Link to comment
Share on other sites

On 16/01/2019 at 3:51 PM, Bilgus said:

This should do what you want...

Yeah, logically it should do what I want.

But when the application prompt for password to login, I use mouse click the LOGIN instead of using ENTER key,

then it show "Access Granted" and re-prompt the password for login again.

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

×
×
  • Create New...