Plateforme Level Extreme
Abonnement
Profil corporatif
Produits & Services
Support
Légal
English
Formatting for phone numbers
Message
 
 
À
02/04/2008 14:37:49
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:
01308132
Vues:
10
Yes, the whole thing can be done in one INSERT-SQL command.
use epa_facility_info exclusive 
zap in epa_facility 
INSERT INTO epa_facility_info;
                    (npid, fllc, fllm, fllt, flls, ;
flld, facrwat, huc, fstr1, fstr2, fcity, fcnty, ;
fstate, fzip, fphone, latitude, longitude);
select f1, val(f2), etc.,
CHRTRAN(TRANSFORM (f7), "-", ""),, from facgeo where not ALLTRIM(f1) == "NPID" 
put all fields in the INSERT-SQL command.

Who designed the table using such field names?


>Can't resist refactoring your code...
USE epa_facility_info IN 0
>SELECT epa_facility_info
>DELETE ALL &&Deletes all the outdated records.
>*-- Do you really need to do a pack?
>PACK && Removes the deleted records from the table.
>USE surface_water!facgeo IN 0
>SELECT facgeo
>
>SCAN &&Loop through the table record by record.					
>	IF NOT (ALLTRIM(f1) = "NPID")
>                *-- a = ALLTRIM (f1) is shorter to write and more readable IMHO
>                *-- Why using single letter variable and field names? Harder to read
>		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
>
>		INSERT INTO epa_facility_info;
>                    (npid, fllc, fllm, fllt, flls, ;
flld, facrwat, huc, fstr1, fstr2, fcity, ;
fcnty, fstate, fzip, fphone, ;
latitude, longitude);
>                    VALUES ;
(m.a, m.d, m.e, m.f, m.g, m.h, m.i, m.j, ;
m.k, m.l, m.m, m.n, m.o, m.p, ;
CHRTRAN(TRANSFORM (m.q), "-", ""), m.b, m.c)
>	ENDIF
>ENDSCAN
BTW, you weren't assigning the result of CHRTRAN(fphone, "-", "") to anything in your code.
>
>>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.
>>
If it's not broken, fix it until it is.


My Blog
Précédent
Répondre
Fil
Voir

Click here to load this message in the networking platform