473,327 Members | 2,012 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,327 software developers and data experts.

Displaying only last 4 numbers of SSN in textbox

Hello,
Could anyone post some simple code or advise me on how I can display the SSN
number like *****7890 in a text box, even thought the user entered
1234567890, and the value of the variable would remain the same.
Only thing I can think of is, accept the user input load it into a varible,
and then just take the last 4 digits of the number and concatenate it to 5
*'s and replace the text box variable with that.... I was hoping there was a
better way to do this though.
Thanks for any help..
Please email me be*******@billsterworld.com
Thanks.
Jan 11 '06 #1
5 10460
This is VB6. Thanks
"Bill" <NO*************@billsterworld.com> wrote in message
news:Es******************************@centurytel.n et...
Hello,
Could anyone post some simple code or advise me on how I can display the
SSN number like *****7890 in a text box, even thought the user entered
1234567890, and the value of the variable would remain the same.
Only thing I can think of is, accept the user input load it into a
varible, and then just take the last 4 digits of the number and
concatenate it to 5 *'s and replace the text box variable with that.... I
was hoping there was a better way to do this though.
Thanks for any help..
Please email me be*******@billsterworld.com
Thanks.

Jan 11 '06 #2
This is for VB6, Thanks.
"Bill" <NO*************@billsterworld.com> wrote in message
news:Es******************************@centurytel.n et...
Hello,
Could anyone post some simple code or advise me on how I can display the
SSN number like *****7890 in a text box, even thought the user entered
1234567890, and the value of the variable would remain the same.
Only thing I can think of is, accept the user input load it into a
varible, and then just take the last 4 digits of the number and
concatenate it to 5 *'s and replace the text box variable with that.... I
was hoping there was a better way to do this though.
Thanks for any help..
Please email me be*******@billsterworld.com
Thanks.

Jan 11 '06 #3
If you're talking about displaying the string after someone has entered it
normally, you can use Mid$ in statement mode to affect the desired change:

Private Sub Command1_Click()

Dim s As String
s = "1234567890"

Mid$(s, 1, 6) = "******"
Text1.Text = s

End Sub
If you're talking about modifying text entry on-the-fly as the user enters
the data, you'll need to manually handle the keypresses in the text box.
Start a new project, add two text boxes to the form, along with this code.
Text2 is where you enter the SSN; the entered value and the protected
strings are shown in Text1 and Text2, respectively:

Option Explicit

Dim realSSN As String
Dim protectedSSN As String

'for our purposes, to test that
'1234567890 converts to ******7890
Private Const maxSSNLength = 10

Private Sub Form_Load()

Text2.MaxLength = maxSSNLength

End Sub
Private Sub Text2_KeyDown(KeyCode As Integer, Shift As Integer)

Select Case KeyCode

Case vbKeyDelete

'we'll cheat and assume a
'delete keypress means nuke everything.
'Good coding practice would only
'delete selected text, and adjust
'the real and protected strings
'accordingly.
Text2.Text = ""
realSSN = ""
protectedSSN = ""

End Select

End Sub

Private Sub Text2_KeyPress(KeyAscii As Integer)

Static bWorking As Boolean
Dim sLen As Long

'safety valve
If bWorking Then Exit Sub

bWorking = True

Select Case KeyAscii

'if key is 0 to 9
Case vbKey0 To vbKey9, vbKeyNumpad0 To vbKeyNumpad9

'if we've not reached the
'max length of the SSN string
If Len(realSSN) <= maxSSNLength Then

'the real SSN is built by adding
'the chr for the key pressed
realSSN = realSSN & Chr$(KeyAscii)

'the length of this string is saved
sLen = Len(realSSN)

'we want the first 6 to have the
'pw char
If sLen <= 6 Then

'first assign the realSSN to
'the protected string
protectedSSN = realSSN

'and in the protected string
'replace up to the first 6 chrs
'with a *
Mid$(protectedSSN, 1, sLen) = String(sLen, "*")
Else
'we're past the 6th chr,
'so show the actual chr
protectedSSN = protectedSSN & Chr$(KeyAscii)
End If

'show the two strings in two text boxes
Text1.Text = realSSN
Text2.Text = protectedSSN

'make sure the cursor is at the end
'of the entry text box
Text2.SelStart = Len(Text2.Text)

End If

'kill the keypress so the text box
'doesn't handle the keypress itself
KeyAscii = 0

Case vbKeyBack

'backspace pressed, so remove 1 from
'each string
If Len(realSSN) > 0 Then

realSSN = Left$(realSSN, Len(realSSN) - 1)
protectedSSN = Left$(protectedSSN, Len(realSSN) - 1)

'reflect the changes
Text1.Text = realSSN
Text2.Text = protectedSSN
Text2.SelStart = Len(Text2.Text)

'and kill the keypress
KeyAscii = 0
End If

Case Else

'anything other than
'backspace or 0 to 9,
'we kill
KeyAscii = 0

End Select

'reset to allow work
bWorking = False

End Sub

--

--

Randy Birch
MS MVP Visual Basic
http://vbnet.mvps.org/

Please reply to the newsgroups so all can participate.


"Bill" <NO*************@billsterworld.com> wrote in message
news:Es******************************@centurytel.n et...
: Hello,
: Could anyone post some simple code or advise me on how I can display the
SSN
: number like *****7890 in a text box, even thought the user entered
: 1234567890, and the value of the variable would remain the same.
: Only thing I can think of is, accept the user input load it into a
varible,
: and then just take the last 4 digits of the number and concatenate it to 5
: *'s and replace the text box variable with that.... I was hoping there was
a
: better way to do this though.
: Thanks for any help..
: Please email me be*******@billsterworld.com
: Thanks.
:
:

Jan 11 '06 #4
Thanks for the help.... Just what I needed. Thanks.
"Randy Birch" <rg************@mvps.org> wrote in message
news:43*********************@news.usenetguide.com. ..
If you're talking about displaying the string after someone has entered it
normally, you can use Mid$ in statement mode to affect the desired change:

Private Sub Command1_Click()

Dim s As String
s = "1234567890"

Mid$(s, 1, 6) = "******"
Text1.Text = s

End Sub
If you're talking about modifying text entry on-the-fly as the user enters
the data, you'll need to manually handle the keypresses in the text box.
Start a new project, add two text boxes to the form, along with this code.
Text2 is where you enter the SSN; the entered value and the protected
strings are shown in Text1 and Text2, respectively:

Option Explicit

Dim realSSN As String
Dim protectedSSN As String

'for our purposes, to test that
'1234567890 converts to ******7890
Private Const maxSSNLength = 10

Private Sub Form_Load()

Text2.MaxLength = maxSSNLength

End Sub
Private Sub Text2_KeyDown(KeyCode As Integer, Shift As Integer)

Select Case KeyCode

Case vbKeyDelete

'we'll cheat and assume a
'delete keypress means nuke everything.
'Good coding practice would only
'delete selected text, and adjust
'the real and protected strings
'accordingly.
Text2.Text = ""
realSSN = ""
protectedSSN = ""

End Select

End Sub

Private Sub Text2_KeyPress(KeyAscii As Integer)

Static bWorking As Boolean
Dim sLen As Long

'safety valve
If bWorking Then Exit Sub

bWorking = True

Select Case KeyAscii

'if key is 0 to 9
Case vbKey0 To vbKey9, vbKeyNumpad0 To vbKeyNumpad9

'if we've not reached the
'max length of the SSN string
If Len(realSSN) <= maxSSNLength Then

'the real SSN is built by adding
'the chr for the key pressed
realSSN = realSSN & Chr$(KeyAscii)

'the length of this string is saved
sLen = Len(realSSN)

'we want the first 6 to have the
'pw char
If sLen <= 6 Then

'first assign the realSSN to
'the protected string
protectedSSN = realSSN

'and in the protected string
'replace up to the first 6 chrs
'with a *
Mid$(protectedSSN, 1, sLen) = String(sLen, "*")
Else
'we're past the 6th chr,
'so show the actual chr
protectedSSN = protectedSSN & Chr$(KeyAscii)
End If

'show the two strings in two text boxes
Text1.Text = realSSN
Text2.Text = protectedSSN

'make sure the cursor is at the end
'of the entry text box
Text2.SelStart = Len(Text2.Text)

End If

'kill the keypress so the text box
'doesn't handle the keypress itself
KeyAscii = 0

Case vbKeyBack

'backspace pressed, so remove 1 from
'each string
If Len(realSSN) > 0 Then

realSSN = Left$(realSSN, Len(realSSN) - 1)
protectedSSN = Left$(protectedSSN, Len(realSSN) - 1)

'reflect the changes
Text1.Text = realSSN
Text2.Text = protectedSSN
Text2.SelStart = Len(Text2.Text)

'and kill the keypress
KeyAscii = 0
End If

Case Else

'anything other than
'backspace or 0 to 9,
'we kill
KeyAscii = 0

End Select

'reset to allow work
bWorking = False

End Sub

--

--

Randy Birch
MS MVP Visual Basic
http://vbnet.mvps.org/

Please reply to the newsgroups so all can participate.


"Bill" <NO*************@billsterworld.com> wrote in message
news:Es******************************@centurytel.n et...
: Hello,
: Could anyone post some simple code or advise me on how I can display the
SSN
: number like *****7890 in a text box, even thought the user entered
: 1234567890, and the value of the variable would remain the same.
: Only thing I can think of is, accept the user input load it into a
varible,
: and then just take the last 4 digits of the number and concatenate it to
5
: *'s and replace the text box variable with that.... I was hoping there
was
a
: better way to do this though.
: Thanks for any help..
: Please email me be*******@billsterworld.com
: Thanks.
:
:

Jan 15 '06 #5
> Mid$(s, 1, 6) = "******"
Text1.Text = s


And for the one-liner version...

Text1.Text = Format$(s, "!\*\*\*\*\*\*@@@@")

<g>

Rick
Jan 15 '06 #6

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

12
by: Don | last post by:
With the following, I'm trying to display numberOne and numberTwo, each as a two digit character group, such as "nn". If numberOne or numberTwo is less than 10, "bn" will be displayed (where "b"...
3
by: B | last post by:
I know there are several ways to speed up combo boxes and form loading. Most of the solutions leave rowsource of the combo box blank and set the rowsource to a saved query or an SQL with a where...
3
by: mark1110 | last post by:
Hi, I am using VB6 and have a masked edit text box. In the mask property I have #.####. I am also using an access database. The textbox works fine if the number is positive (1.2345), however if...
17
by: Ron | last post by:
I want to write a program that will accept a number in a textbox for example 23578 and then in a label will display the sum of the odd and even number like this... the textbox containsthe number...
5
by: Michael R | last post by:
Searching the net I've found a simple technique to add row numbers and alternate colors (for the even and the uneven row) to a continuous form. 1st step: Create a textbox, send it to background...
3
by: RG | last post by:
I am reading in from a serial port a 16 bit number from 0 to 65536. It is being read as a string from my microcontroller into VB using DEC5 or 5 digits are displayed. I need to display this value...
51
by: kjewell23 | last post by:
Hello, I'm new to this asp.net 2.0 I need help?? My database is coming from AS400 which uses odbc Commands. i have data in the dataset but nothing showing in my gridview. However the data does show...
5
by: Gilberto | last post by:
Hello, I have a textbox where the user enters a category for a product selected on a combo box. The user has to select a LOT of products and most of the time he enters them in order of category,...
2
by: mathewgk80 | last post by:
Hi all, I am creating a calculator.. The first problem i am facing is to display and enter the values(Text) at the right side of a textbox where the calculations are carrrying out and displaying...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
1
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: Vimpel783 | last post by:
Hello! Guys, I found this code on the Internet, but I need to modify it a little. It works well, the problem is this: Data is sent from only one cell, in this case B5, but it is necessary that data...
0
by: ArrayDB | last post by:
The error message I've encountered is; ERROR:root:Error generating model response: exception: access violation writing 0x0000000000005140, which seems to be indicative of an access violation...
1
by: PapaRatzi | last post by:
Hello, I am teaching myself MS Access forms design and Visual Basic. I've created a table to capture a list of Top 30 singles and forms to capture new entries. The final step is a form (unbound)...
1
by: Defcon1945 | last post by:
I'm trying to learn Python using Pycharm but import shutil doesn't work
0
by: af34tf | last post by:
Hi Guys, I have a domain whose name is BytesLimited.com, and I want to sell it. Does anyone know about platforms that allow me to list my domain in auction for free. Thank you
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.