input mask on text field and split function 
Author Message
 input mask on text field and split function

Hi,
on one of my forms, i have a phone number field.  it is bound to the
phone_number field in a table.  I want to do 2 things:
1.  when I save the data to the table, I want to only save numerics,
not "-" or "."
2.  when I display the data to the user on the form, I want to display
it in a mask "xxx-xx-xxxx"

for #1, I am trying to use the split function but I am having
problems.
dim phone1 as string
phone1 = split (txtPhone1.text, "-")
that's not working.

for #2 - not sure what to do.

need help please
rafael



Mon, 10 May 2004 08:39:04 GMT  
 input mask on text field and split function
1. Phone1 = Replace$(txtPhone1.Text, "-", "")

2. Use Format$(Phone1, "000-00-0000")
       or Format$(Phone1, "###-##-####")

Note: I called your variable Phone1 in #2, but it looks more like a Social Security Number
template to me.

Rick


Quote:
> Hi,
> on one of my forms, i have a phone number field.  it is bound to the
> phone_number field in a table.  I want to do 2 things:
> 1.  when I save the data to the table, I want to only save numerics,
> not "-" or "."
> 2.  when I display the data to the user on the form, I want to display
> it in a mask "xxx-xx-xxxx"

> for #1, I am trying to use the split function but I am having
> problems.
> dim phone1 as string
> phone1 = split (txtPhone1.text, "-")
> that's not working.

> for #2 - not sure what to do.

> need help please
> rafael


______________________________________________________________________________
Posted Via Binaries.net = SPEED+RETENTION+COMPLETION = http://www.binaries.net


Mon, 10 May 2004 09:07:33 GMT  
 input mask on text field and split function
The reason the Split approach is failing is because it returns an
array. If the number is 123-45-678, you end up with the following:

 0) 123
 1) 45
 2) 678

Have you tried the Masked Edit control? This is exactly the kind of
thing it's designed for.



Mon, 10 May 2004 20:51:21 GMT  
 input mask on text field and split function

Quote:

> Hi,
> on one of my forms, i have a phone number field.  it is bound to the
> phone_number field in a table.  I want to do 2 things:
> 1.  when I save the data to the table, I want to only save numerics,
> not "-" or "."
> 2.  when I display the data to the user on the form, I want to display
> it in a mask "xxx-xx-xxxx"

> for #1, I am trying to use the split function but I am having
> problems.
> dim phone1 as string
> phone1 = split (txtPhone1.text, "-")
> that's not working.

> for #2 - not sure what to do.

> need help please
> rafael


Here is a different way of solving your problem...
This type of data entry and verification can be simplified by using 10
DropDownList (ComboBox) boxes with the numbers 0-9 placed into each
one.  Now the user can only select a number from each and you don't
have to worry about finding only numbers.  Then to store each field
just concatenate the results...

Dim Phone1 as String
  '// Assumming you use a Control Array
Phone1 = Cmb(1).Text & Cmb(2).Text & Cmb(3).Text
  '// You can also add Static Labels on your form
  '// for the "-" dashes if you want.

To answer you original questions.
Try using a Masked Edit box.
#1 Assuming you have all numbers entered.  To store this as three
strings...
Use Left to grab the first three characters of the Phone number
strings.

Left(string, length)

Then use

Right(string, length)

to remove the 3 leftmost characters by using right with 7.

Hope that helps



Mon, 10 May 2004 22:17:16 GMT  
 
 [ 4 post ] 

 Relevant Pages 

1. input mask on text field and split function

2. ??? Using Split instead of Line Input to read huge text files

3. Add input mask to INPUTBOX function

4. Create Field with Input Mask in DAO

5. Set Format and Input mask of existing field

6. Programmatically alter database field properties / input mask with VB6

7. Input Masking for phone number fields

8. input masking of text boxes

9. Input Mask for HTML Form text Boxes???

10. Formatting Text boxes -- Input Masking

11. Split text field

12. Split() function and text qualifier

 

 
Powered by phpBB® Forum Software