Plateforme Level Extreme
Abonnement
Profil corporatif
Produits & Services
Support
Légal
English
Text conversion to big number
Message
De
29/09/2020 06:42:20
 
 
À
26/09/2020 12:09:31
Information générale
Forum:
Visual FoxPro
Catégorie:
Autre
Divers
Thread ID:
01676260
Message ID:
01676301
Vues:
45
>Hi,
>
>I need to convert a text. e.g 1.2.11.3 to a number like 1021103 for which I constructed a method:
>
>
>*!* PROCEDURE conversion
>LPARAMETERS lcNumberIn
>
>Local ;
>	lcNewpar As String, ;
>	lcNumberIn As String, ;
>	lnI As Number, ;
>	lnParenteel As Number
>
>
>*!*	? lcNumberIn
>m.lcNewpar = ''
>
>For m.lnI = 1 To Len(Alltrim(m.lcNumberIn ))
>	Do Case
>		Case !Isdigit(Substr(m.lcNumberIn ,m.lnI,1))
>			m.lcNewpar = m.lcNewpar +Substr(m.lcNumberIn ,m.lnI,1)
>		Case Isdigit(Substr(m.lcNumberIn ,m.lnI,1))
>			m.lcNewpar = m.lcNewpar + Iif(Isdigit(Substr(m.lcNumberIn ,m.lnI,1)),Padl(Substr(m.lcNumberIn ,m.lnI,1),2,'0'),Substr(lcParenteel  ,m.lnI,1))
>
>	Endcase
>Endfor 
>m.lcNewpar = Strtran(m.lcNewpar ,'010','1')
>m.lcNewpar = Strtran(m.lcNewpar ,'.','')
>m.lcNewpar = ALLTRIM(Substr(m.lcNewpar ,2))
>RETURN val(m.lcNewpar)
>
>
>Now I come to a text 1.4.2.1.9.1.4.4.1.1.1 which would be 104020109010404010101 however this are to much digits vor VFP to handle thus my method gives 1040201090104+E
>

Not the question you asked, but I'd do this with ALINES() rather than SUBSTR(). It would make the code considerably simpler:
LOCAL laParts[1], lnParts, lnPart, lcPart, lcWhole
lnParts = ALINES(laParts, m.lcNumberIn , '.')
lcWhole = ''

FOR lnPart = 1 to m.lnParts
   lcPart = PADL(laParts[m.lnPart, 2, '0')
   lcWhole = m.lcWhole + m.lcPart
ENDFOR

RETURN m.lcWhole
Untested, but should give you the idea.

Tamar
Précédent
Répondre
Fil
Voir

Click here to load this message in the networking platform