Jump to content
Sign in to follow this  
JayFran

I know its simple but...

Recommended Posts

JayFran

can someone guide me in the right direction. all I want to do is, when the username or password field is empty, a message box appears then returns to the user tp input window again. I only posted a snippet of my code since im only working on that part of it right now.

any help is greatly appreciated.

$pass=0
$pass = InputBox("Password", "Enter Password:", "", "*")
;$len_pass = StringLen(0) 
If $pass = "" Then
MsgBox(4096, "ISM Login", "Password in incorrect or blank")
Return 
EndIf

Share this post


Link to post
Share on other sites
water

Something like:

While 1 = 1
    $pass = InputBox("Password", "Enter Password:", "", "*")
    If $pass = "" Then
        MsgBox(4096, "ISM Login", "Password in incorrect or blank")
    Else
        ExitLoop
    EndIf
WEnd

My UDFs and Tutorials:

Spoiler

UDFs:
Active Directory (NEW 2018-10-19 - Version 1.4.10.0) - Download - General Help & Support - Example Scripts - Wiki
OutlookEX (2018-10-31 - Version 1.3.4.1) - Download - General Help & Support - Example Scripts - Wiki
ExcelChart (2017-07-21 - Version 0.4.0.1) - Download - General Help & Support - Example Scripts
PowerPoint (2017-06-06 - Version 0.0.5.0) - Download - General Help & Support
Excel - Example Scripts - Wiki
Word - Wiki
 
Tutorials:

ADO - Wiki

 

Share this post


Link to post
Share on other sites
JayFran

Thanks. Works great! One last question, if the cancel key is clicked is their anything that can kill the whole script? or atleast quit/stop the script altogether?

Share this post


Link to post
Share on other sites
water

Thanks. Works great! One last question, if the cancel key is clicked is their anything that can kill the whole script? or atleast quit/stop the script altogether?

Most of the functions return data as a return value or set @error. If you press Cancel InputBox sets @error=1 (according to the help file ;))

So your script would look like:

While 1 = 1
    $pass = InputBox("Password", "Enter Password:", "", "*")
    If @error = 1 Then Exit
    If $pass = "" Then
        MsgBox(4096, "ISM Login", "Password in incorrect or blank")
    Else
        ExitLoop
    EndIf
WEnd
Edited by water

My UDFs and Tutorials:

Spoiler

UDFs:
Active Directory (NEW 2018-10-19 - Version 1.4.10.0) - Download - General Help & Support - Example Scripts - Wiki
OutlookEX (2018-10-31 - Version 1.3.4.1) - Download - General Help & Support - Example Scripts - Wiki
ExcelChart (2017-07-21 - Version 0.4.0.1) - Download - General Help & Support - Example Scripts
PowerPoint (2017-06-06 - Version 0.0.5.0) - Download - General Help & Support
Excel - Example Scripts - Wiki
Word - Wiki
 
Tutorials:

ADO - Wiki

 

Share this post


Link to post
Share on other sites
JayFran

Most of the functions return data as a return value or set @error. If you press Cancel InputBox sets @error=1 (according to the help file :))

So your script would look like:

While 1 = 1
    $pass = InputBox("Password", "Enter Password:", "", "*")
    If @error = 1 Then Exit
    If $pass = "" Then
        MsgBox(4096, "ISM Login", "Password in incorrect or blank")
    Else
        ExitLoop
    EndIf
WEnd

Wow, it works perfect! I was looking thru the help files for about an hour or so today, thats how I how even begin to develop an idea of how the script should look. but Im still learning my way around the help files and with the whole scripting. Much Respect Water ;)

Share this post


Link to post
Share on other sites
water

Glad it works.

A good place to start learning AutoIt is the Wiki.


My UDFs and Tutorials:

Spoiler

UDFs:
Active Directory (NEW 2018-10-19 - Version 1.4.10.0) - Download - General Help & Support - Example Scripts - Wiki
OutlookEX (2018-10-31 - Version 1.3.4.1) - Download - General Help & Support - Example Scripts - Wiki
ExcelChart (2017-07-21 - Version 0.4.0.1) - Download - General Help & Support - Example Scripts
PowerPoint (2017-06-06 - Version 0.0.5.0) - Download - General Help & Support
Excel - Example Scripts - Wiki
Word - Wiki
 
Tutorials:

ADO - Wiki

 

Share this post


Link to post
Share on other sites
AdmiralAlkex

Same thing but 4 lines shorter ;)

Do
    $pass = InputBox("Password", "Enter Password:", "", "*")
    If @error = 1 Then Exit
    If $pass = "" Then MsgBox(4096, "ISM Login", "Password in incorrect or blank")
Until $pass <> ""

Share this post


Link to post
Share on other sites
JayFran

Same thing but 4 lines shorter ;)

Do
    $pass = InputBox("Password", "Enter Password:", "", "*")
    If @error = 1 Then Exit
    If $pass = "" Then MsgBox(4096, "ISM Login", "Password in incorrect or blank")
Until $pass <> ""

Nice! Okay... so I wrote so more code for the string formatting. It halfway works, I think the format is correct but something just isnt right still. Would appreciate your help or anyone else's. Here is the user name & password portion of the code.

While 1 = 1
    $user = InputBox("Login", "Enter Username:")
    If @error = 1 Then Exit
    If $user = "" Then
    MsgBox(5, "ISM Login", "Please Enter User Name")
        Else
    ExitLoop
    EndIf
WEnd

$u_string = StringRegExp($user, "[:alnum:]|[:alpha][@][us][.][website][.][com]", 1)
If @error = 1 Then
    MsgBox(5, "ISM Login", "Please Check the format of the username" & @CRLF & "Example: username@us.ibm.com")
    Exit
    EndIf

While 1 = 1
    $pass = InputBox("Password", "Enter Password:", "", "*")
    If @error = 1 Then Exit
    If $pass = "" Then
        MsgBox(5, "ISM Login", "Password in incorrect or blank")
    Else
        ExitLoop
    EndIf
WEnd

Share this post


Link to post
Share on other sites
Remnant

Nice! Okay... so I wrote so more code for the string formatting. It halfway works, I think the format is correct but something just isnt right still. Would appreciate your help or anyone else's. Here is the user name & password portion of the code.

$u_string = StringRegExp($user, "[:alnum:]|[:alpha][@][us][.][website][.][com]", 1)
If @error = 1 Then
    MsgBox(5, "ISM Login", "Please Check the format of the username" & @CRLF & "Example: username@us.ibm.com")
    Exit
    EndIf

Heya,

Your middle block of code (Quoted) will terminate if the username is not in the correct format. presumably you would prefer if the user had the option to re-enter the information? To do this, combine it with your initial loop.

Share this post


Link to post
Share on other sites
JayFran

Heya,

Your middle block of code (Quoted) will terminate if the username is not in the correct format. presumably you would prefer if the user had the option to re-enter the information? To do this, combine it with your initial loop.

Correct. When I try to do that I'm still having a problem. It either take any format and goes to the next step or it continually loops if no username or password is entered but I still hit cancel it will not exit. Also the format does the samething depending on the arrangement of lines. Heres what I've come up with.

While 1 = 1
    $user = InputBox("Login", "Enter Username:")
    $u_string = StringRegExp($user, "[:alnum:]|[:alpha][@][us][.][ibm][.][com]", 1)
    If $u_string = 0 Then
    MsgBox(5, "ISM Login", "Please Check the format of the username" & @CRLF & "Example: username@us.ibm.com")
    Else
    EndIf
    If $user = "" Then
    MsgBox(5, "ISM Login", "Please Enter User Name")
        Else
    ExitLoop
EndIf
Do 
    Until $u_string = $user
WEnd



While 1 = 1
    $pass = InputBox("Password", "Enter Password:", "", "*")
    If @error = 1 Then Exit
    If $pass = "" Then
        MsgBox(5, "ISM Login", "Password in incorrect or blank")
    Else
        ExitLoop
    EndIf
WEnd

Share this post


Link to post
Share on other sites
JayFran

I just debug this script a little, I found that my StringRegExp is set @ zero. I have to do some more investigating to do.

Share this post


Link to post
Share on other sites
AlmarM

Same thing but 4 lines shorter :)

Do
    $pass = InputBox("Password", "Enter Password:", "", "*")
    If @error = 1 Then Exit
    If $pass = "" Then MsgBox(4096, "ISM Login", "Password in incorrect or blank")
Until $pass <> ""

While InputBox("Password", "Enter password:", "", "*") <> "password"
    If @error = 1 Then Exit
    MsgBox(16, "ERROR", "Wrong / blank password, try again.")
WEnd

Another way. Sorry, I just had to. ;)


Minesweeper

A minesweeper game created in autoit, source available.

_Mouse_UDF

An UDF for registering functions to mouse events, made in pure autoit.

2D Hitbox Editor

A 2D hitbox editor for quick creation of 2D sphere and rectangle hitboxes.

Share this post


Link to post
Share on other sites
JayFran

Here's with my final version looks like with the restrictions on the user name. Works perfectly. Feel free to use or comment.

; =================================================================================================
;                                           #UserName# 
; =================================================================================================
Do
    $user = InputBox("Login", "Enter Username:")
    If @error = 1 Then Exit
    If $user = "" Then MsgBox(16, "ISM Login", "Please Enter User Name")
    Until $user <> ""
    
$u_string = StringRegExp($user, "[a-z][0-9][@]{1}[u]{1}[s]{1}[.]{1}[i]{1}[b]{1}[m]{1}[.]{1}[c]{1}[o]{1}[m]{1}", 2)
If @error  Then
    MsgBox(5, "ISM Login", "Please Check the format of the username" & @CRLF & "Example: username@us.ibm.com")
    Exit
EndIf

; =================================================================================================
;                                           #Password# 
; =================================================================================================
Do
    $pass = InputBox("Password", "Enter Password:", "", "*")
    If @error = 1 Then Exit
    If $pass = "" Then MsgBox(16, "ISM Login", "Password in incorrect or blank")
    Until $pass <> ""
    
; =================================================================================================
;                                           #Ticket Numbers# 
; =================================================================================================
Do
$t_number = InputBox("Ticket Number", "Enter Ticket Number:" & @CRLF & "Example:C0000")
If @error = 1 Then Exit
If $t_number = "" Then MsgBox(16, "ISM Login", "Enter Ticket Number:")
Until $t_number <> ""

$t_string = StringRegExp($t_number, "[C](?i){1}[0-9]{4}", 1)
 If @error = 1 Then 
     MsgBox(5, "ISM Login", "Error in Ticket number")
     Exit
     EndIf
Edited by JayFran

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  

×