Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
HomeAnnouncementsFree MagazinesWhite PapersSubmit Content
Discussion GroupsASP.NETWindows FormsLanguages.NET FrameworkVisual Studio.NET
Articles.NET FrameworkASP.NETToolsWindows Forms
.NET DirectoryOpen Source ProjectsUser GroupsWeb Resources
Related Topics
Visual Basic 6SQL ServerMS AccessOther DB ProductsMS Server ProductsMore Topics ...

.NET Forum / Windows Forms / WinForm General / March 2008

Tip: Looking for answers? Try searching our database.

Microsoft.VisualBasic.RTrim Doesn't

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
Ross Culver - 18 Mar 2008 17:47 GMT
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.
Jon Skeet [C# MVP] - 18 Mar 2008 17:57 GMT
> Can anyone explain to me why Microsoft.VisualBasic.RTrim or
> Microsoft.VisualBasic.Trim do not remove the trailing blank spaces in a word
[quoted text clipped - 4 lines]
> 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.

Signature

Jon Skeet - <skeet@pobox.com>
http://www.pobox.com/~skeet   Blog: http://www.msmvps.com/jon.skeet
World class .NET training in the UK: http://iterativetraining.co.uk

Ross Culver - 18 Mar 2008 19:08 GMT
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.

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?

Thanks.

Ross

>> Can anyone explain to me why Microsoft.VisualBasic.RTrim or
>> Microsoft.VisualBasic.Trim do not remove the trailing blank spaces in a word
[quoted text clipped - 10 lines]
> See http://www.pobox.com/~skeet/csharp/complete.html for details of
> what I mean by that.
Jon Skeet [C# MVP] - 18 Mar 2008 19:19 GMT
> 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:
>
[quoted text clipped - 18 lines]
>
> 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?

Signature

Jon Skeet - <skeet@pobox.com>
http://www.pobox.com/~skeet   Blog: http://www.msmvps.com/jon.skeet
World class .NET training in the UK: http://iterativetraining.co.uk

Ross Culver - 18 Mar 2008 19:27 GMT
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.

>> 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
[quoted text clipped - 31 lines]
> Does the position of column 3 vary in a predictable way? Does column 2
> line up?
Jon Skeet [C# MVP] - 18 Mar 2008 19:36 GMT
> 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.

Signature

Jon Skeet - <skeet@pobox.com>
http://www.pobox.com/~skeet   Blog: http://www.msmvps.com/jon.skeet
World class .NET training in the UK: http://iterativetraining.co.uk

Ross Culver - 18 Mar 2008 19:42 GMT
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

>> 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
[quoted text clipped - 7 lines]
> You'll either need to use a non-proportional font, or draw the
> different columns using separate DrawString calls.
Jon Skeet [C# MVP] - 18 Mar 2008 19:48 GMT
> 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...

Signature

Jon Skeet - <skeet@pobox.com>
http://www.pobox.com/~skeet   Blog: http://www.msmvps.com/jon.skeet
World class .NET training in the UK: http://iterativetraining.co.uk

Ross Culver - 18 Mar 2008 19:33 GMT
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

>> 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
[quoted text clipped - 31 lines]
> Does the position of column 3 vary in a predictable way? Does column 2
> line up?

Rate this thread:







Free Magazines

Get these publications absolutely FREE for up to 12 months. There are no hidden fees and no obligation. Simply choose a title, complete the application form and submit it. Read more ...

Oracle MagazineNetwork ComputingComputer WorldBio-IT WorldeWeekInformation WeekInfosecurity
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.