Solved

Key Ascii

Posted on 2002-04-08
4
2,005 Views
Last Modified: 2008-03-10
Hi,

I have a password field where i display the password entered with a * and i append one more * to make it look like ** for every key stroke. I want to disable the space bar key from the password.. The code i have still gives one * for space bar..how do i supress it.


If KeyAscii = 32 Then
MsgBox "Space is not a valid key", vbOKOnly
txtPassword.SetFocus
Exit Sub

Else
txtPassword.Text = txtPassword.Text & "*"
txtPassword.SelStart = Len(txtPassword.Text)
End If

If KeyAscii = 8 Then
txtPassword.Text = Mid(txtPassword.Text, 1, Len(txtPassword.Text) - 2)
txtPassword.SelStart = Len(txtPassword.Text)
End If


Thanks
0
Comment
Question by:sramkris
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 3
4 Comments
 
LVL 17

Expert Comment

by:inthedark
ID: 6927408
If KeyAscii = 32 Then
   MsgBox "Space is not a valid key", vbOKOnly
   txtPassword.SetFocus
    KeyAscii = 0
Exit Sub

0
 
LVL 17

Accepted Solution

by:
inthedark earned 100 total points
ID: 6927420
Also suggest that you set the PasswordChar property of the textbox to "*"

In this way you only need the following code (EXAMPLE FOR TEXT1):

Private Sub Text1_KeyPress(KeyAscii As Integer)

Static ValidKeys As String
Static Done As Boolean

If Not Done Then
    ' ADD YOU VALID KEYS HERE:
    ValidKeys = "0123456789abcdefghijklmnopqrstuvwxyzABCDEGHIJLKMNOPQRSTUVWXYZ`¬!""£$%^&*(){}_+=[]/\?><,.;:'"
End If
If InStr(ValidKeys, Chr(KeyAscii)) = 0 Then
    KeyAscii = 0
    MsgBox "Invalid Password Key", vbExclamation, "Error"
    Text1.SetFocus
End If

End Sub

Hope this helps....inthedark
0
 
LVL 5

Expert Comment

by:KarcOrigin
ID: 6927421
Hi,
Try this -


Private Sub Text1_KeyPress(KeyAscii As Integer)
    If KeyAscii = 32 Then KeyAscii = 0
End Sub
0
 
LVL 17

Expert Comment

by:inthedark
ID: 6927423
Woops

If Not Done Then
   Done = True ' I forgot this
0

Featured Post

Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

If you have ever used Microsoft Word then you know that it has a good spell checker and it may have occurred to you that the ability to check spelling might be a nice piece of functionality to add to certain applications of yours. Well the code that…
You can of course define an array to hold data that is of a particular type like an array of Strings to hold customer names or an array of Doubles to hold customer sales, but what do you do if you want to coordinate that data? This article describes…
As developers, we are not limited to the functions provided by the VBA language. In addition, we can call the functions that are part of the Windows operating system. These functions are part of the Windows API (Application Programming Interface). U…
Show developers how to use a criteria form to limit the data that appears on an Access report. It is a common requirement that users can specify the criteria for a report at runtime. The easiest way to accomplish this is using a criteria form that a…

751 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question