Simple Question 
Author Message
 Simple Question

Hi,

I have a form with a two text boxes: txtUserName and txtPassword, i also
have a two command buttons: cmdSubmit and cmdCancel.

The cmdSubmit is disabled by default, how can I enable it programmatically
when the two text boxes have been filled with valid data (say for example 7
characters in  txtUserName and 8 characters in txtPassword).

Thank you,

Cube



Mon, 08 Dec 2003 18:25:18 GMT  
 Simple Question
Write code in textboxes Change procedures:

Private Sub txtUserName_Change()
  cmdSubmit.Enabled = Len(txtUserName.Text)=7
End Sub
--
HTH,
Alexander Shirshov, MCSD


Quote:
> Hi,

> I have a form with a two text boxes: txtUserName and txtPassword, i also
> have a two command buttons: cmdSubmit and cmdCancel.

> The cmdSubmit is disabled by default, how can I enable it programmatically
> when the two text boxes have been filled with valid data (say for example
7
> characters in  txtUserName and 8 characters in txtPassword).

> Thank you,

> Cube



Mon, 08 Dec 2003 18:26:53 GMT  
 Simple Question
Thank you Alexander but I meant the two textboxes have to contain valid
data. Sorry for not making my question clear the first time.


Quote:
> Write code in textboxes Change procedures:

> Private Sub txtUserName_Change()
>   cmdSubmit.Enabled = Len(txtUserName.Text)=7
> End Sub
> --
> HTH,
> Alexander Shirshov, MCSD



> > Hi,

> > I have a form with a two text boxes: txtUserName and txtPassword, i also
> > have a two command buttons: cmdSubmit and cmdCancel.

> > The cmdSubmit is disabled by default, how can I enable it
programmatically
> > when the two text boxes have been filled with valid data (say for
example
> 7
> > characters in  txtUserName and 8 characters in txtPassword).

> > Thank you,

> > Cube



Mon, 08 Dec 2003 19:16:26 GMT  
 Simple Question
What is valid data?

Anyway, you can check the contents of both textboxes in this sub and enable
the button if it meet your criteria.

My example enables the button if txtUserName contains exactly 7 characters.
--
HTH,
Alexander Shirshov, MCSD


Quote:
> Thank you Alexander but I meant the two textboxes have to contain valid
> data. Sorry for not making my question clear the first time.



> > Write code in textboxes Change procedures:

> > Private Sub txtUserName_Change()
> >   cmdSubmit.Enabled = Len(txtUserName.Text)=7
> > End Sub
> > --
> > HTH,
> > Alexander Shirshov, MCSD



> > > Hi,

> > > I have a form with a two text boxes: txtUserName and txtPassword, i
also
> > > have a two command buttons: cmdSubmit and cmdCancel.

> > > The cmdSubmit is disabled by default, how can I enable it
> programmatically
> > > when the two text boxes have been filled with valid data (say for
> example
> > 7
> > > characters in  txtUserName and 8 characters in txtPassword).

> > > Thank you,

> > > Cube



Mon, 08 Dec 2003 19:16:08 GMT  
 Simple Question

Quote:

>Hi,

>I have a form with a two text boxes: txtUserName and txtPassword, i also
>have a two command buttons: cmdSubmit and cmdCancel.

>The cmdSubmit is disabled by default, how can I enable it programmatically
>when the two text boxes have been filled with valid data (say for example 7
>characters in  txtUserName and 8 characters in txtPassword).

>Thank you,

>Cube

Let's say you have written two routines of your own:

Public Function ValidateUserName (str as String) as Boolean
Public Function ValidatePassword (str as String) as Boolean

Then call code like this in the form with the textboxex and buttons:

Private Sub txtUserName_Change()
    CheckData
End Sub

Private Sub txtPassword_Change()
    CheckData
End Sub

Private Sub CheckData()
    If ValidateUserName(txtUserName) then
        If ValidatePassword(txtPassword) then
            cmdSubmit.Enable = True
        Else
            cmdSubmit.Enable  = False
        End IF
    Else
        cmdSubmit.Enable  = False
    End If      
End Sub



Mon, 08 Dec 2003 19:17:30 GMT  
 Simple Question
May be one way is to declare two public variables.
One like txtUserNameOK and the other txtPasswordOK.

In txtUserName_Change if valid, set txtUserNameOK
to true, and then check to see if txtPasswordOK is true
then enable cmdSubmit, if not leave it alone and got to:

In txtPassword_Change if valid, set txtPasswordOK
to true, and then check to see if txtUserNameOK is true
then enable cmdSubmit, else not.

On Form_Load set both variables to false.

HTH

Regards;
mike
--
My email address has name of a fruit in it.
Please remove the fruit for email replies.


Quote:
> Hi,

> I have a form with a two text boxes: txtUserName and txtPassword, i also
> have a two command buttons: cmdSubmit and cmdCancel.

> The cmdSubmit is disabled by default, how can I enable it programmatically
> when the two text boxes have been filled with valid data (say for example
7
> characters in  txtUserName and 8 characters in txtPassword).

> Thank you,

> Cube



Mon, 08 Dec 2003 19:51:23 GMT  
 Simple Question
Thanks guys it worked


Quote:

> >Hi,

> >I have a form with a two text boxes: txtUserName and txtPassword, i also
> >have a two command buttons: cmdSubmit and cmdCancel.

> >The cmdSubmit is disabled by default, how can I enable it
programmatically
> >when the two text boxes have been filled with valid data (say for example
7
> >characters in  txtUserName and 8 characters in txtPassword).

> >Thank you,

> >Cube

> Let's say you have written two routines of your own:

> Public Function ValidateUserName (str as String) as Boolean
> Public Function ValidatePassword (str as String) as Boolean

> Then call code like this in the form with the textboxex and buttons:

> Private Sub txtUserName_Change()
>     CheckData
> End Sub

> Private Sub txtPassword_Change()
>     CheckData
> End Sub

> Private Sub CheckData()
>     If ValidateUserName(txtUserName) then
>         If ValidatePassword(txtPassword) then
>             cmdSubmit.Enable = True
>         Else
>             cmdSubmit.Enable  = False
>         End IF
>     Else
>         cmdSubmit.Enable  = False
>     End If
> End Sub



Mon, 08 Dec 2003 19:53:55 GMT  
 Simple Question
You can change

     If ValidateUserName(txtUserName) then
         If ValidatePassword(txtPassword) then
             cmdSubmit.Enable = True
         Else
             cmdSubmit.Enable  = False
         End IF
     Else
         cmdSubmit.Enable  = False
     End If

TO

If ValidateUserName(txtUserName) And ValidatePassword(txtPassword) Then
    cmdSubmit.Enable = True
Else
    cmdSubmit.Enable = False
End If

Although its a matter of taste. I always think the second one is easier to
understand.

Adrian



|
| >Hi,
| >
| >I have a form with a two text boxes: txtUserName and txtPassword, i also
| >have a two command buttons: cmdSubmit and cmdCancel.
| >
| >The cmdSubmit is disabled by default, how can I enable it
programmatically
| >when the two text boxes have been filled with valid data (say for example
7
| >characters in  txtUserName and 8 characters in txtPassword).
| >
| >Thank you,
| >
| >
| >Cube
| >
|
| Let's say you have written two routines of your own:
|
| Public Function ValidateUserName (str as String) as Boolean
| Public Function ValidatePassword (str as String) as Boolean
|
|
| Then call code like this in the form with the textboxex and buttons:
|
| Private Sub txtUserName_Change()
|     CheckData
| End Sub
|
| Private Sub txtPassword_Change()
|     CheckData
| End Sub
|
| Private Sub CheckData()
|     If ValidateUserName(txtUserName) then
|         If ValidatePassword(txtPassword) then
|             cmdSubmit.Enable = True
|         Else
|             cmdSubmit.Enable  = False
|         End IF
|     Else
|         cmdSubmit.Enable  = False
|     End If
| End Sub



Mon, 08 Dec 2003 20:21:58 GMT  
 Simple Question
Or even...

cmdSubmit.Enable = ValidateUserName(txtUserName) And
ValidatePassword(txtPassword)

:-) :-)


Quote:
> You can change

>      If ValidateUserName(txtUserName) then
>          If ValidatePassword(txtPassword) then
>              cmdSubmit.Enable = True
>          Else
>              cmdSubmit.Enable  = False
>          End IF
>      Else
>          cmdSubmit.Enable  = False
>      End If

> TO

> If ValidateUserName(txtUserName) And ValidatePassword(txtPassword) Then
>     cmdSubmit.Enable = True
> Else
>     cmdSubmit.Enable = False
> End If

> Although its a matter of taste. I always think the second one is easier to
> understand.

> Adrian




> |
> | >Hi,
> | >
> | >I have a form with a two text boxes: txtUserName and txtPassword, i
also
> | >have a two command buttons: cmdSubmit and cmdCancel.
> | >
> | >The cmdSubmit is disabled by default, how can I enable it
> programmatically
> | >when the two text boxes have been filled with valid data (say for
example
> 7
> | >characters in  txtUserName and 8 characters in txtPassword).
> | >
> | >Thank you,
> | >
> | >
> | >Cube
> | >
> |
> | Let's say you have written two routines of your own:
> |
> | Public Function ValidateUserName (str as String) as Boolean
> | Public Function ValidatePassword (str as String) as Boolean
> |
> |
> | Then call code like this in the form with the textboxex and buttons:
> |
> | Private Sub txtUserName_Change()
> |     CheckData
> | End Sub
> |
> | Private Sub txtPassword_Change()
> |     CheckData
> | End Sub
> |
> | Private Sub CheckData()
> |     If ValidateUserName(txtUserName) then
> |         If ValidatePassword(txtPassword) then
> |             cmdSubmit.Enable = True
> |         Else
> |             cmdSubmit.Enable  = False
> |         End IF
> |     Else
> |         cmdSubmit.Enable  = False
> |     End If
> | End Sub



Mon, 08 Dec 2003 20:28:03 GMT  
 Simple Question
Try using the Validate Event of the txtPassword box ...
this will be triggered just before the focus moves from
txtPassword --- for example:
   Private Sub txtPassword_Validate(Cancel As Boolean)
     If Len(txtPassword) = 8 And <<other conditions>> Then
       cmdSubmit.Enabled = True
     Else
       MsgBox "Password must contain 8 characters."
       Cancel = True
     End If
   End Sub
(You could also verify the characters entered if the
password is restricted to alphanumeric characters.)

Quote:
>-----Original Message-----
>Hi,

>I have a form with a two text boxes: txtUserName and
txtPassword, i also
>have a two command buttons: cmdSubmit and cmdCancel.

>The cmdSubmit is disabled by default, how can I enable it
programmatically
>when the two text boxes have been filled with valid data
(say for example 7
>characters in  txtUserName and 8 characters in
txtPassword).

>Thank you,

>Cube

>.



Tue, 16 Dec 2003 01:09:08 GMT  
 
 [ 10 post ] 

 Relevant Pages 

1. Simple Question: Assigning Icon to an App : Simple Question

2. simple question...what was the source code for this simple custom action (rules wizard)

3. SIMPLE QUESTION : SIMPLE ANSWER?

4. SIMPLE QUESTION : SIMPLE ANSWER?

5. SIMPLE QUESTION, please SIMPLE ANSWER

6. Simple controls and a very simple question

7. Simple Question...simple answer???

8. VB5 Pro Masked Edit control - A simple, simple question

9. HELP! simple question need simple answer

10. HELP! simple question need simple answer

11. HELP! simple question need simple answer

12. Simple Question (dumb Question)

 

 
Powered by phpBB® Forum Software