Plateforme Level Extreme
Abonnement
Profil corporatif
Produits & Services
Support
Légal
English
Testing a Character field for Numeric Data'
Message
De
29/07/2009 17:46:56
 
 
À
28/07/2009 19:14:38
Information générale
Forum:
Visual FoxPro
Catégorie:
Codage, syntaxe et commandes
Versions des environnements
Visual FoxPro:
VFP 9 SP2
OS:
Windows XP SP2
Divers
Thread ID:
01415119
Message ID:
01415412
Vues:
47
>>Hi All:
>>
>>Do you have an easy way for testing if a character field contains valid numeric data.
>>
>>Someone suggested:
>>
>>
>>IF TRANSFORM(VAL(m.luValue)) == m.luValue
>>
>>
>>but this doesn't work every time. e.g. when luValue = '08'
>>
>>Thanks,
>>
>>Yossi
>
>This may or may not be helpful to you...............
>
>In reading the thread, I'm still not sure if you want a field value which evaluates as numeric to be TRUE or only a field value which contains (this may not be the correct way to put it) a valid numeric constant.
>
>For example, if
>1+1
>5/2
>etc.
>
>should give you true, then TYPE() might be made to work for you. Bear in mind that, however, if you have a value of "XYZ" and a variable/field named XYZ with a numeric value, that will also be true.
>
>If you want to verify that the field value would be a valid numeric constant then I think
>LEN(CHRTRAN(ALLTRIM(myField),"0123456789.","") = 0 AND OCCURS(".",myField) < 2
>might do the trick
>(I use LEN() rather than EMPTY() because EMPTY("123 456") would be true after the CHRTRAN()
Expanding your function, to accomodate -99.3 or +99.5
LEN(CHRTRAN(ALLTRIM(myField),"0123456789.+-","") = 0 ;
AND OCCURS(".",myField) < 2 ;
AND AT("-",myField) < 2 ;
AND AT("+",myField) < 2
Précédent
Répondre
Fil
Voir

Click here to load this message in the networking platform