Plateforme Level Extreme
Abonnement
Profil corporatif
Produits & Services
Support
Légal
English
Formatting for phone numbers
Message
 
 
Information générale
Forum:
Visual FoxPro
Catégorie:
Problèmes
Versions des environnements
Visual FoxPro:
VFP 9 SP2
Divers
Thread ID:
01307488
Message ID:
01307716
Vues:
16
This message has been marked as the solution to the initial question of the thread.
Here're a few (strong) suggestions :)

1. Do not ever refence work areas by there number or one character code. It makes code maintenance a nigthmare. Use workarea aliases instead.
2. Do not use meaningless varable/field names. It makes code unreadable.
3. DO WHILE is poor substitue for SCAN

You don't need to convert phone number to numeric in order to get rid of extra formatring characters.
SELECT 0
USE epa_facility_info Exclusive
ZAP
SELECT 0 
USE surface_water!facgeo
SCAN	
	IF NOT (ALLTRIM(f1) == "NPID")
		STORE ALLTRIM(f1) TO m.a
		STORE VAL(f2) TO m.b
		STORE VAL(f3) TO m.c
		STORE ALLTRIM(f4) TO m.d
		STORE ALLTRIM(f5) TO m.e
		STORE ALLTRIM(f6) TO m.f
		STORE ALLTRIM(f7) TO m.g
		STORE ALLTRIM(f8) TO m.h
		STORE ALLTRIM(f9) TO m.i
		STORE ALLTRIM(f10) TO m.j
		STORE ALLTRIM(f11) TO m.k
		STORE ALLTRIM(f12) TO m.l
		STORE ALLTRIM(f13) TO m.m
		STORE RIGHTC(ALLTRIM(f14),3) TO m.n
		STORE ALLTRIM(f15) TO m.o
		STORE ALLTRIM(f16) TO m.p
		* Remove all formating characters from the phone #
		STORE CHRTRAN(f17, " ()-", "") TO m.phone

		SELECT epa_facility_info
		APPEND BLANK &&Adds a blank record to populate the fields with the variables.
		REPLACE npid WITH m.a, ;
				fllc WITH m.d, ;
				fllm WITH m.e, ;
				fllt WITH m.f, ;
				flls WITH m.g, ;
				flld WITH m.h, ;
				facrwat WITH m.i, ;
				huc WITH m.j, ;
				fstr1 WITH m.k, ;
				fstr2 WITH m.l, ;
				fcity WITH m.m, ;
				fcnty WITH m.n, ;
				fstate WITH m.o, ;
				fzip WITH m.p, ;
				fphone WITH m.phone, ;
				latitude WITH m.b, ;
				longitude WITH m.c
		
	ENDIF
ENDSCAN
>Alright well I just decided to remove all dashes in the data. However, I'm for some reason it is cutting off some of the data. For phone numbers entered as ###-####### it is working as expected. When the number is entered as ###-###-####, it decides to cut off the last four digits. This baffles me. I have the phone number field set as a character of size 15 to account for any dashes and the 10 numbers, plus extra room. Any idea as to why the numbers of one dash turn out to be just the ten digits, and the ones with two dashes cuts it off after the first seven digits? Here is my code.
>
>Most of this isn't necessary in this discussion, but I will post it anyways.
>
SELECT 1 &&Assign the epa_facility_info table to 1.
>USE epa_facility_info
>DELETE ALL &&Deletes all the outdated records.
>PACK && Removes the deleted records from the table.
>SELECT 3 &&Assign the textfile which is now a remote view to 3.
>USE surface_water!facgeo
>GO TOP &&Move to the top of the table.
>DO WHILE NOT EOF() &&Loop through the table record by record.					
>	IF ALLTRIM(f1) = "NPID"
>	ELSE
>		STORE ALLTRIM(f1) TO m.a
>		STORE VAL(f2) TO m.b
>		STORE VAL(f3) TO m.c
>		STORE ALLTRIM(f4) TO m.d
>		STORE ALLTRIM(f5) TO m.e
>		STORE ALLTRIM(f6) TO m.f
>		STORE ALLTRIM(f7) TO m.g
>		STORE ALLTRIM(f8) TO m.h
>		STORE ALLTRIM(f9) TO m.i
>		STORE ALLTRIM(f10) TO m.j
>		STORE ALLTRIM(f11) TO m.k
>		STORE ALLTRIM(f12) TO m.l
>		STORE ALLTRIM(f13) TO m.m
>		STORE RIGHTC(ALLTRIM(f14),3) TO m.n
>		STORE ALLTRIM(f15) TO m.o
>		STORE ALLTRIM(f16) TO m.p
>		STORE VAL(LEFTC(ALLTRIM(f17),3)+SUBSTR(ALLTRIM(f17),5,7)) TO m.q 
&& this is the phone number entry, it is originally numeric
>*		CHRTRAN(m.q, "-", "")
>		SELECT 1 &&Select the epa_facility_info table.
>		APPEND BLANK &&Adds a blank record to populate the fields with the variables.
>		REPLACE npid WITH m.a
>		REPLACE fllc WITH m.d
>		REPLACE fllm WITH m.e
>		REPLACE fllt WITH m.f
>		REPLACE flls WITH m.g
>		REPLACE flld WITH m.h
>		REPLACE facrwat WITH m.i
>		REPLACE huc WITH m.j
>		REPLACE fstr1 WITH m.k
>		REPLACE fstr2 WITH m.l
>		REPLACE fcity WITH m.m
>		REPLACE fcnty WITH m.n
>		REPLACE fstate WITH m.o
>		REPLACE fzip WITH m.p
>		REPLACE fphone WITH STR(m.q) &&replacing the phone number field with m.q as a string
>		CHRTRAN(fphone, "-", "")  && removing dashes
>		REPLACE latitude WITH m.b
>		REPLACE longitude WITH m.c
>		SELECT 3 &&Select the remote view again.
>	ENDIF
>	IF EOF() &&Check for end of file.
>		EXIT
>	ELSE
>		SKIP
>	ENDIF
>ENDDO
>
>
>Any thoughts?
--sb--
Précédent
Suivant
Répondre
Fil
Voir

Click here to load this message in the networking platform