By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
437,593 Members | 2,006 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 437,593 IT Pros & Developers. It's quick & easy.

Last four digits need to display in VB 6

P: 2
Hi,
I would like to enter a number whose minimum and maximum length is 6 and 13.The number should be diaplayed as in the form of XXXX1234 i.e only last four digits should be diaplayed and the remaining should be diaplayed as X.
Can you send me the code.

For example if I enter 1234567 it should display as XXX4567
if I enter 89345684 it should display as XXXX5684


Note: The number I enter is having minmum length of 6 and maximum of 13.
Dec 31 '07 #1
Share this Question
Share on Google+
7 Replies


debasisdas
Expert 5K+
P: 8,127
1.find out the length of the string.(ensure that is in the range of 6 and 13)
2.use right(string,4) to findout last 4 characters
3.filll the remaining with "X" from left side.
Dec 31 '07 #2

P: 3
As you have already said you want to check of 6 digit to 13 so this code does not check that but checks to show XXX

Expand|Select|Wrap|Line Numbers
  1. A = Text1.Text
  2. LENA = Len(A)
  3. C = Right(A, 4)
  4. For I = 1 To LENA - 4
  5.   D = D & "x"
  6. Next
  7. E = D & C
  8. Label1.Caption = E
  9.  
Dec 31 '07 #3

Ali Rizwan
100+
P: 927
Hello,

Use this code

Expand|Select|Wrap|Line Numbers
  1. Text2.Text = Right (Text1.Text,4)
Have a nice day.

>> ALI <<
Dec 31 '07 #4

debasisdas
Expert 5K+
P: 8,127
Hello,

Use this code

Expand|Select|Wrap|Line Numbers
  1. Text2.Text = Right (Text1.Text,4)
Have a nice day.

>> ALI <<
then what about the remaining characters ?

Who will convert that ?
Dec 31 '07 #5

Ali Rizwan
100+
P: 927
then what about the remaining characters ?

Who will convert that ?
I am really very sorry about that. I forgot about that.

This is the right code:

Expand|Select|Wrap|Line Numbers
  1. Private Sub Command1_Click()
  2.  
  3. For i = 1 To Len(Text1) - 4
  4.   Text2 = Text2 & "X"
  5. Next
  6.  
  7. Text2 = Text2 & Right(Text1, 4)
  8.  
  9. End Sub
Regards

>> ALI <<
Dec 31 '07 #6

Expert 100+
P: 487
Simplifying alis code.

Expand|Select|Wrap|Line Numbers
  1. 'Will return string length of text1 -4 characters X to Text2
  2. Text2 = String(Len(Text1) - 4, "X")
  3. 'Add last 4 characters with Text2
  4. Text2 = Text2 & Right(Text1, 4)
Note: As site rule should not post code without explanation.
Dec 31 '07 #7

Expert 5K+
P: 8,434
Well, if it's about simplifying (or at least shortening) the code, how about...

Expand|Select|Wrap|Line Numbers
  1. ' Copy string from Text1 to Text2 with all but last 4 characters masked
  2. Text2 = String(Len(Text1) - 4, "X") & Right(Text1, 4)
Jan 1 '08 #8

Post your reply

Sign in to post your reply or Sign up for a free account.