COMPGROUPS.NET | Search | Post Question | Groups | Stream | About | Register

### How to insert blank spaces

• Email
• Follow

```How can I insert a calculated number of blank spaces into a
calculation?

I am trying to generate an electronic record that needs to be in a
certain from.

For example, the patient's name needs to start on column 1, and the
date of birth needs to start on column 30.  In other words, the name is
at the beginning of the line, and the DOB starts at the 30th character
in the line.

So I'm trying to use the Length command to determine how much space the
name takes up, and then subtract it from 30 to get how many spaces I
need to add before the DOB field.  How can I do this?

Thank you!

David Averbach

```
 0
Reply averbach (17) 4/6/2006 6:34:06 AM

See related articles to this posting

```In article <1144305246.367054.32800@i39g2000cwa.googlegroups.com>,
"davey" <averbach@mac.com> wrote:

> How can I insert a calculated number of blank spaces into a
> calculation?
>
> I am trying to generate an electronic record that needs to be in a
> certain from.
>
> For example, the patient's name needs to start on column 1, and the
> date of birth needs to start on column 30.  In other words, the name is
> at the beginning of the line, and the DOB starts at the 30th character
> in the line.
>
> So I'm trying to use the Length command to determine how much space the
> name takes up, and then subtract it from 30 to get how many spaces I
> need to add before the DOB field.  How can I do this?

Firstly, spaces are NOT a good way to line things up unless you're
using a mono-spaced / non-proportional font like Courier. If you're
using a proportional font, then the i character is a skinny letter that
takes up less room than the wide w character, this means that for two
lines like:

igloo     1
windy     2

the 1 and two will not line up, even though each word has five letters
followed by five spaces.

Instead you should use Tabs and set the tab stops at the appropriate
place.

If you are using a non-proportional font or still do want spaces, then
the easiest way is to do something like this:

Line = Left(Name & "{30spaces}", 30) & DOB

This way whatever is in name has 30 spaces appended to the end (in case
the name is empty), and then the Left function takes just the first 30
characters. It then appends the DOB data to that result.

Note: If the Name is longer than 30 characters then only the first 30
will be used.

You could use the Length function if you want to and would have
something like:

Line = Name & Left("{30 spaces}", 30 - Length(Name)) & DOB

Hopefully helping harassed humans happily handle handiwork hardships  ;o)
```
 0

```In article <1144305246.367054.32800@i39g2000cwa.googlegroups.com>,
averbach@mac.com says...
> How can I insert a calculated number of blank spaces into a
> calculation?
>
> I am trying to generate an electronic record that needs to be in a
> certain from.
>
> For example, the patient's name needs to start on column 1, and the
> date of birth needs to start on column 30.  In other words, the name is
> at the beginning of the line, and the DOB starts at the 30th character
> in the line.
>
> So I'm trying to use the Length command to determine how much space the
> name takes up, and then subtract it from 30 to get how many spaces I
> need to add before the DOB field.  How can I do this?

30 - Length(name) = number of spaces you need

to actually generate a string of spaces of this length -- there are a
few approaches... the simplest is just:

Left("...",30-Length(name))

where "..." is a string of 30 spaces... e.g. something like:
"                                                      "

So the line looks like

name & Left("...",30-Length(name)) & birthdate

There are fancier ways of generating the space string using recursive
custom functions, but if you know upfront that the maximum (be it 30,
80, or 200), then just using a literal of suitable length is the most
efficient.

If you were using 7Dev/8Adv I'd make use of custom functions to make
this more modular.

```
 0

```Quick note, according to the original post I would guess the data was
going into a "fixed length" format and DOB starts at 30.  So you
actually are dealing with 29 characters not 30. If simplicity is the
pure goal then, where "..." is a string of 29 spaces,
in FM8 Line = left(Name&"...";29)&DOB and in FM6 Line =
left(Name&"...";29)& datetotext(DOB).

Would it be safe to assume that your date needs formatting to 6 or 8
characters and numbers only so that 06/04/2006 becomes 20060406?  If
so, try returning that BOD into a text string as TextBOD =
Year(DOB)*10^4+Month(DOB)*10^2 + Day(DOB)*10^0.  That's modified from a
Ray Cologon original - the 10^0 was tagged on as it seemed kind of cool
as I recalled that from some distant math class that 10^0 = 1.  And if
you want 6 chars only then grab Right(TextBOD,6)

Stephen

```
 0

```A Custom Function was just posted to Brian Dunning's web site that

FixedLength ( text ; char ; charNumber ; align )

Returns a fixed length string.

http://www.briandunning.com/cf/464

```
 0