Microsoft.VisualBasic.RTrim Doesn't

  • Thread starter Thread starter Ross Culver
  • Start date Start date
R

Ross Culver

Can anyone explain to me why Microsoft.VisualBasic.RTrim or
Microsoft.VisualBasic.Trim do not remove the trailing blank spaces in a word
such as "PI030010035127SIY "?

I'm pulling data from SQL 2005 using a standard dataset/datatableadapter. I
assign a variable for each field and assign the variable the field value.
Then I trim it so that I can effectively line up the next word in an ongoing
string (creating a string variable to use with a PrintDocument).

Any suggestions?

Thanks.
 
Ross Culver said:
Can anyone explain to me why Microsoft.VisualBasic.RTrim or
Microsoft.VisualBasic.Trim do not remove the trailing blank spaces in a word
such as "PI030010035127SIY "?

I'm pulling data from SQL 2005 using a standard dataset/datatableadapter. I
assign a variable for each field and assign the variable the field value.
Then I trim it so that I can effectively line up the next word in an ongoing
string (creating a string variable to use with a PrintDocument).

Could you post a short but complete program which demonstrates the
problem?

See http://www.pobox.com/~skeet/csharp/complete.html for details of
what I mean by that.
 
Ross Culver said:
Thanks for the response, Jon. As I was posting a snippet of the code,
I noticed a problem with the code. Correcting did prove that the trim
was working.

Let me guess - you were calling RTrim, but assuming it would trim the
string itself rather than returning a trimmed string?
So, let me ask a slightly different questions:

I'm trying to, in essence, create a table of data (6 columns) where
the text in each column starts in the same character position on the
page. Below is part of the code. My problem is that even when I
subtract the desired character position from the accumulated length
of the preceding text, I can't get column 3 (for example) to line up.
Note, the length of ODITNO never exceeds 30.
....
line = line & ODITNO & Microsoft.VisualBasic.Space(50 -
Microsoft.VisualBasic.Len(ODITNO)) & ItemDescription

The ODITNO value is column 2 and it's length varies, so the beginning
of the text for column 3 (ItemDescription) varies as well.

Remember, I doing this for a PrintDocument, used in the following:
document = header & line

ev.Graphics.DrawString(document, printFont, Brushes.Black,
leftMargin, yPos, New StringFormat())

I'm sure there just something wrong with my logic. Any suggestions?

I can't say I'm familiar with all of this - but is it a monospaced
font?

Does the position of column 3 vary in a predictable way? Does column 2
line up?
 
Column 2 lines up, but that's because the value in column 1 can only be
either 1 or 2 characters long, so the 'if' coding is simple. Column 3's
data doesn't vary predictably. It can range from 2 to 30 characters. The
font is defined in the document settings as Arial 9.

Thanks for your time.
 
By the way, I tried using Microsoft.VisualBasic.vbTab, but that didn't seem
to do anything, even when I concatenated 2 or 3 together.

Ross
 
Ross Culver said:
Column 2 lines up, but that's because the value in column 1 can only be
either 1 or 2 characters long, so the 'if' coding is simple. Column 3's
data doesn't vary predictably. It can range from 2 to 30 characters. The
font is defined in the document settings as Arial 9.

Okay, that's the problem then - Arial is a proportional font. For
instance, "iiiii" will take up a lot less space than "MMMMM".

You'll either need to use a non-proportional font, or draw the
different columns using separate DrawString calls.
 
Ok, I can use a different, non-proportional font. But I don't know how to
concatenate the drawstring calls. So, if I understand you, I can call as
many DrawString calls as I want in a single print; the trick is to format
each so they don't overlap. Is that correct?

Ross
 
Ross Culver said:
Ok, I can use a different, non-proportional font.

That would probably be the simplest solution, yes.
But I don't know how to
concatenate the drawstring calls. So, if I understand you, I can call as
many DrawString calls as I want in a single print; the trick is to format
each so they don't overlap. Is that correct?

Sounds about right to me. You can call MeasureString with some
arbitrary "as wide as it will get" string to work out distances - or
hard code them, I guess.

Hopefully someone who's actually *done* some printing in .NET will
chime in at some point...
 
Back
Top