🚀 go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

Thread View: comp.databases.xbase.misc
4 messages
4 total messages Started by rt Sat, 11 Jun 1994 22:44
Padding with 0s
#12
Author: rt
Date: Sat, 11 Jun 1994 22:44
19 lines
1308 bytes
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. 
Re: Padding with 0s
#13
Author: A. Gonzalez
Date: Sun, 12 Jun 1994 01:24
55 lines
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 
Re: Padding with 0s
#14
Author: A. Gonzalez
Date: Sun, 12 Jun 1994 06:56
8 lines
980 bytes
And here's  the killer shot:

dzeros  = "0000"
dnumber = 100.00
? right(dzeros + ltrim(str(dnumber, 6, 2)), 8)

Armando
-------
Re: Padding with 0s
#15
Author: Scott McIntosh
Date: Wed, 15 Jun 1994 20:14
15 lines
1152 bytes
A. Gonzalez (gonzalez@blue.weeg.uiowa.edu) wrote:
: And here's  the killer shot:

: dzeros  = "0000"
: dnumber = 100.00
: ? right(dzeros + ltrim(str(dnumber, 6, 2)), 8)

In Clipper:
<field> := padl( str( <number> ), len( <field> ), "0" )

Ciao,
Scott

: Armando
: -------
Thread Navigation

This is a paginated view of messages in the thread with full content displayed inline.

Messages are displayed in chronological order, with the original post highlighted in green.

Use pagination controls to navigate through all messages in large threads.

Back to All Threads