× The internal search function is temporarily non-functional. The current search engine is no longer viable and we are researching alternatives.
As a stop gap measure, we are using Google's custom search engine service.
If you know of an easy to use, open source, search engine ... please contact support@midrange.com.



On Fri, 25 Oct 2002, Dave wrote:
>
> Why doesn't the following code work?
>

Okay, since you asked, I'll explain why it doesn't work.

Look at this code:

     D text            S             80A
     D E$DrLc          S             15A

     c                   eval      text = 'Ck: #2850'
     c                   eval      E$DrLc = 'AAA123'

Since text is a fixed-length 80-character field, it's not just
9 characters long.   It contains the 9-character string 'Ck: $2850',
but then we've added 71 blanks to the end, automagically, to make
text retain it's 80-byte length.

It has to.  By definition, a fixed-length variable must always be that
length.  It can't ever be larger or smaller than 80 chars.

The same is true of E$DrLc.  It's still 15 chars long, and contains
'AAA123         '.  I realize that you know this already, I'm just
establishing a basis for the next code:

     C                   Eval      Text = Text + ', License #: ' + E$DrLc

Now, we're saying, start by including Text (which is 'Ck: #2850' plus
71 blanks) then add the string ', License #: ' after that (so now, the
result is 'Ck: #2850' followed by 71 blanks, followed ', License # ')
and then add the 15-bytes 'AAA123'.   The result is a 108-character
string... the 80 bytes from Text, the string ', License #: ' (which is
13 bytes if I counted correctly) and the 15 bytes from E$DrLc.

Now, it tries to assign that 108 byte string to Text.  Unfortunately,
text is only 80 bytes long, you can't store 108 bytes into it.   So,
what does it do?   It truncates the rightmost 28 bytes (i.e. the
phrase ', License #: ' and the contents of E$DrLC are dropped)

That's why the code doesn't work.

>
>
> Let's not get into any VARYING discussions or anything like that.  I just
> wanna know how to get this to work.
>

Think about it... what can you add to the end of an 80-byte string, and
expect it to still fit in 80 bytes?

Hmmm...  if only there were a way to make a string not be fixed-length...
something where the length could vary, so you could add it to itself,
and the length would increase, instead of simply truncating...  Sigh.
If only I could talk about VARYING.

Oh well.  The other solution is to modify the string before assigning
it by getting rid of unwanted blanks.   It's much slower to add the
blanks and then strip them back off, but since you don't like varying,
we'll do it this way:

     C                   Eval      Text = %trimr(Text) + ', License #: ' +
     C                                E$DrLc

Now, we're stripping those 71 trailing blanks off of Text before adding
the ', License #: ' string.  The result will be 9 bytes for 'Ck: #2850'
plus the 13 bytes of ', License #: ' plus the 15 bytes of E$DrLc.
Those 37 bytes are less than 80, so the compiler will automagically
add 43 more blanks to keep the fixed length...  for a total of
52 trailing blanks.  (The 43 added, plus the 9 from E$DrLc)

Now, of course, if you want to add more, you'll have to do a
%trimr() again...  which again requires the compiler to search the
string for the last non-blank, and strip them off.   Once again,
we find ourselves wishing we didn't use a fixed-length string...






As an Amazon Associate we earn from qualifying purchases.

This thread ...

Follow-Ups:
Replies:

Follow On AppleNews
Return to Archive home page | Return to MIDRANGE.COM home page

This mailing list archive is Copyright 1997-2024 by midrange.com and David Gibbs as a compilation work. Use of the archive is restricted to research of a business or technical nature. Any other uses are prohibited. Full details are available on our policy page. If you have questions about this, please contact [javascript protected email address].

Operating expenses for this site are earned using the Amazon Associate program and Google Adsense.