Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Repeat dialog box 2

Status
Not open for further replies.

finitesimian

Programmer
Feb 11, 2006
29
US
I am in the process of creating a script that opens a dialog box for password entry. I need my dialog to be able to handle errors, and open itself back up again when they happen. Is there a way to do this?

Here is one example:
In this script, the user is attempting to enter and reenter the new password. The script needs to take the two passwords entered, make sure they match, and if they don't, pops up a messagebox, then repeats the dialog.

Code:
   'above this line, all of the normal default declarations were made....
   '----------------------------------------------

   Dim password As String
   password = "whatever_the_password_is"
   Dim usrname As String
   usrname = "test_user_1919"

'Begins dialog box for updating the password        
   Begin Dialog newdlg2 251, 54, "Updating password for: " & usrname
   OkButton  194, 3, 50, 14
   CancelButton  194, 21, 50, 14
   TextBox NoEcho  100, 6, 79, 11, .TextBox2
   TextBox NoEcho  100, 23, 79, 11, .TextBox22
   Text  31, 6, 58, 9, "OLD PASSWORD:"
   Text  31, 23, 62, 9, "NEW PASSWORD:"
   TextBox NoEcho  100, 38, 79, 11, .TextBox221
   Text  21, 38, 70, 9, "REPEAT PASSWORD:"
   End Dialog
    
   Dim mydialog2 As newdlg2
   On Error Resume Next
   
   'puts old password in first textbox
   mydialog2.TextBox2 = passwrd
      
   Dialog mydialog2
   If Err=102 Then
           Stop
   End If 

   'obtains entries from dialog box
   Dim pass1 As String
   pass1 = mydialog.textbox22
   Dim pass2 As String
   pass2 = mydialog.textbox221
 
   'compares the two
   If pass1 <> pass2 Then
   msgbox "Passwords do not match. Please reenter passwords"
   'from here it needs to rerun the dialog box if possible
   End if 
   
   'assuming it never triggered the error, it continues from here...
   Sess0.Screen.MoveTo 1,2
   Sess0.Sendkeys(pass1 & pass2 & "<Enter>")
   stop


BTW-- in the help section, I noted a function called "Goto"--- will this work in this scenario?
 
A lot can be done to this to improve it but here's the idea

Code:
Declare Function FileDlgFunction(identifier$, action, suppvalue)
Dim bPassMatch

Sub Main()

    Begin Dialog dbChangePass 251, 54, "Updating password for: You ", .FileDlgFunction
        OkButton  194, 3, 50, 14
        CancelButton  194, 21, 50, 14
        TextBox 100, 6, 79, 11, .OldPass
        TextBox NoEcho  100, 23, 79, 11, .NewPass
        TextBox NoEcho  100, 38, 79, 11, .ConfNewPass
        Text  31, 6, 58, 9, "OLD PASSWORD:"
        Text  31, 23, 62, 9, "NEW PASSWORD:"
        Text  21, 38, 70, 9, "REPEAT PASSWORD:"
    End Dialog
    
    Dim mydialog as dbChangePass

    On Error Resume Next
    While not bPassMatch
        Dialog mydialog
    Wend    
    

End Sub

Function FileDlgFunction(identifier$, action, suppvalue)
   Select Case action
     Case 1 'dialog box initialized
     Case 2 'button or control value changed
        If DlgText$(3) <> DlgText$(4) then
            msgbox "Passwords do not match. Please reenter passwords"
        Else
            bPassMatch = true
        End If
     Case 3 'text or combo box changed
     Case 4 'control focus changed
     Case 5 'idle
         DoEvents
  End Select
End Function

[thumbsup2] Wow, I'm having amnesia and deja vu at the same time.
I think I've forgotten this before.


 
Small improvement on the prior code. It gets rid of the need to use a boolean and loop the dialogbox. With this code the dialogbox will dtay open until you tell it to close.

Code:
Declare Function FileDlgFunction(identifier$, action, suppvalue)

Sub Main()
    Begin Dialog dbChangePass 251, 70, "Updating password for: You ", .FileDlgFunction
        OkButton  194, 3, 50, 14, .BtnOk
        CancelButton  194, 21, 50, 14, .BtnCancel
        Text  31, 6, 150, 9, "OLD PASSWORD:"
        TextBox 100, 6, 79, 11, .OldPass
        Text  31, 23, 150, 9, "NEW PASSWORD:"
        TextBox NoEcho  100, 23, 79, 11, .NewPass
        Text  21, 38, 150, 9, "REPEAT PASSWORD:"
        TextBox NoEcho  100, 38, 79, 11, .ConfNewPass
        Text  5, 53, 240, 9, "", .ErrMsg
    End Dialog
    
    Dim mydialog as dbChangePass
    On Error Resume Next
    Dialog mydialog
End Sub

Function FileDlgFunction(identifier$, action, suppvalue)
   FileDlgFunction = True
   Select Case action
     Case 1 'dialog box initialized
     Case 2 'button or control value changed
        Select Case identifier
        Case "BtnOk"
            If DlgText$("NewPass") <> DlgText$("ConfNewPass") then
                DlgText("ErrMsg"), "Passwords do not match."
            Else
                FileDlgFunction = False
            End If
        Case "BtnCancel"
            FileDlgFunction = False
        End Select
     Case 3 'text or combo box changed
     Case 4 'control focus changed
     Case 5 'idle
         DoEvents
  End Select
End Function
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top