Article View: comp.databases.xbase.misc
Article #13Re: Padding with 0s
From: A. Gonzalez
Date: Sun, 12 Jun 1994 01:24
Date: Sun, 12 Jun 1994 01:24
55 lines
2765 bytes
2765 bytes
rt@astro.ocis.temple.edu (rt@astro.ocis.temple.edu) writes:
>Hello,
>
> I am using dBASE III+. I would like to know how I can pad a
>memory variable with 0s.
>
>For example:
>I would like to store the reccount() into a field in the database.
>
>I would start as :
>mcount=reccount()
>REPLACE field1 WITH mcount
>
>I would like for it to show up as :
>00003 instead of 3 in the character field field1.
>
>--
>My opinion does not reflect that of Temple U. This is because it is made
>up of a non-reflective material.
***********************************************************************
Hello,
There are several ways to do this. The fast one I can come up
with in dBase III+ with fuctions like len(), replicate(),
ltrim() and str() is:
*/ If the character field's length where you want to store \*
*/ the 0-padded number is 5, you could do something like this: \*
*/-----------------------------------------------------------------\*
drecn = 100 && Or reccount()
dmaxlen = 5 && Field's length
dzeros = dmaxlen - len(ltrim(str(drecn))) && Get # of zeros
dzeropad = replicate("0", dzeros) && build a "00..."
dval2store = dzeropad+ltrim(str(drecn)) && d padding
? dval2store && Prints 00100
wait
*/-----------------------------------------------------------------\*
Now you can do a "replace dfield with dval2store".
Also take a look at functions like transform(). In dBase III+
? transform( 100, "*#####.##") && Prints ***100.00
You could write some code to change the "*" with "0". Functions
like substr() are also useful for this.
I tested this in CA-dBfast for Windows, it should also work in
good old dBase III+.
"Adios amigo" and good luck,
Armando R. Gonzalez
Technical Details
Message-ID:
<2tdo3i$30q@blue.weeg.uiowa.edu>Path:
arc1-ca.pugleaf.net!nntp.gmd.de!newsserver.jvnc.net!howland.reston.ans.net!math.ohio-state.edu!hobbes.physics.uiowa.edu!news.uiowa.edu!blue.weeg.uiowa.edu!blue.weeg.uiowa.edu!not-for-mailReferences:
<2tdeoi$ktk@cronkite.ocis.temple.edu>Show Full Headers
Complete Article Headers
X-Google-Language: ENGLISH,ASCII-7-bit X-Google-Thread: 116288,e9c7ff92c0154d6d X-Google-Attributes: gid116288,public X-Google-Thread: 100e8a,e9c7ff92c0154d6d X-Google-Attributes: gid100e8a,public X-Google-ArrivalTime: 1994-06-11 18:40:07 PST Path: arc1-ca.pugleaf.net!nntp.gmd.de!newsserver.jvnc.net!howland.reston.ans.net!math.ohio-state.edu!hobbes.physics.uiowa.edu!news.uiowa.edu!blue.weeg.uiowa.edu!blue.weeg.uiowa.edu!not-for-mail From: gonzalez@blue.weeg.uiowa.edu (A. Gonzalez) Newsgroups: comp.databases.xbase.misc,bit.listserv.dbase-l Subject: Re: Padding with 0s Date: 11 Jun 1994 20:24:02 -0500 Organization: University of Iowa, Iowa City, IA, USA Lines: 55 Distribution: world Message-ID: <2tdo3i$30q@blue.weeg.uiowa.edu> References: <2tdeoi$ktk@cronkite.ocis.temple.edu> NNTP-Posting-Host: blue.weeg.uiowa.edu Keywords: padding