473,546 Members | 2,205 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

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*******@bills terworld.com
Thanks.
Jan 11 '06 #1
5 10502
This is VB6. Thanks
"Bill" <NO************ *@billsterworld .com> wrote in message
news:Es******** *************** *******@century tel.net...
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*******@bills terworld.com
Thanks.

Jan 11 '06 #2
This is for VB6, Thanks.
"Bill" <NO************ *@billsterworld .com> wrote in message
news:Es******** *************** *******@century tel.net...
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*******@bills terworld.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(K eyCode 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$(protectedS SN, 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$(protected SSN, 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******** *************** *******@century tel.net...
: 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*******@bills terworld.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******** *************@n ews.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(K eyCode 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$(protectedS SN, 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$(protected SSN, 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******** *************** *******@century tel.net...
: 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*******@bills terworld.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
1332
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" is a space character). In other words, I always want the second digit of each number to be in the same column, so that the beginning of "restOfText"...
3
9353
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 clause after users typed in one or several letters/digits. My problem is as follows Most of the time I need to display form in continuous format,...
3
4498
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 the number is negative I get an "Invalid Property" error message when I try to display it. Is there a way to fix this without using ##.####. Thanks,...
17
4608
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 23578 the label would say: Sumof odd number is: 15 Sum of even number is: 10 any ideas?
5
27541
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 and select the first color. .ControlSouce =fRowNum(False) .Name = RowNum 2nd step: Add the following function to the form module: (for row...
3
4006
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 live as a decimal number so I can manipulate the value. For instance I have the following line: TextBox2.Text = buffer1 - 32768 but this...
51
7867
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 on the page. Could you please see what I'm doing wrong. My code is down below Protected Sub btnSubmit_Click(ByVal sender As Object, ByVal e As...
5
2832
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, so for every product (new record) he has to type AGAIN the "category" in the category textbox. Is there a way that this textbox "remembers" the last...
2
1251
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 the numbers and result. Please help me..... Regards, Mathew
0
7435
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language...
0
7698
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. ...
0
7947
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that...
1
7461
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For...
0
6030
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then...
0
3492
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in...
1
1922
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
1
1046
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
0
747
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating...

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.