Question

Formatting Text

Asked by: demmick

Hi All

I have a query which returns a long text field from a sql database.  When I display the text in VB I have "squares" displayed at the start of the each record as well as in various places in the text.  I think it has something to with carriage return.  I would like my text to be diplayed using the carriage returns but not display the "squares".  How can I do this?

Regards
Sam

This Question has been solved and asker verified All Experts Exchange premium technology solutions are available to subscription members.

Subscribe now for full access to Experts Exchange and get

Instant Access to this Solution

  • Plus...
  • 30 Day FREE access, no risk, no obligation
  • Collaborate with the world's top tech experts
  • Unlimited access to our exclusive solution database
  • Never be left without tech help again

Subscribe Now

Asked On
2003-12-16 at 06:12:33ID20827076
Tags

return

,

squares

Topic

Visual Basic Programming

Participating Experts
5
Points
50
Comments
23

Trusted by hundreds of thousands everyday for fast, accurate and reliable tech support.

  • "The time we save is the biggest benefit of Experts Exchange to Warner Bros. What could take multiple guys 2 hours or more each to find is accessed in around 15 minutes on Experts Exchange." Mike Kapnisakis, Warner Bros.
  • "Our team likes having a resource that is more secure than just using Google and most experts using this service really know their stuff. It's nice to look here first versus using Google." Dayna Sellner, Lockheed Martin
  • "Anytime that I've been stumped with a problem, 9 out of 10 times Experts Exchange has either the accepted solution or an open discussion of the potential solution to the problem." Kenny Red, eBay Inc.

See what Experts Exchange can do for you.

Got a question?

We've got the answer.

Experts Exchange has been collecting answers to technology questions since 1996…3 million and counting! If you have a question, chances are we already have your answer.

Screenshot of Experts Exchange Knowledgebase

Need individual assistance?

Our experts are ready to help.

If you can't find the exact answer you're looking for, ask our exclusive community of 50,000 experts. You’ll get a personalized answer from a trusted professional.

Screenshot of Experts Exchange Knowledgebase

Want to learn from the best?

Read articles from industry experts.

Thousands of free tech tips, tricks, how-to’s and tutorials are available in our peer reviewed articles section. See for yourself how smart our experts are, no login required.

Screenshot of an Article

Working on a long term project?

Store your work and research.

Save solutions to your questions, answers you’ve discovered through searching plus helpful articles in your personal knowledgebase for easy future access.

Screenshot of Experts Exchange Knowledgebase

Access the answers to your technology questions today.

Subscribe Now

30-day free trial. Register in 60 seconds.

What Makes Experts Exchange Unique?

Members of the expert community talk about why the experience at Experts Exchange is different than what you will find anywhere else.

Trusted by the world's most respected brands.

image of each brand's logo

Faithfully serving IT professionals since 1996.

Experts Exchange Logo

Try it out and discover for yourself.

Subscribe Now

30-day free trial. Register in 60 seconds.

Related Solutions

  1. Remove square box (carriage return) in report
    I have a table that has contact data in it. I develop a report to print mailing labels. The problem is that when I create the report the address line has carriage returns in it that when the report is ran the address line shows the address with square boxes in the text wher...
  2. <cffile creating squares instead of carriage returns?
    Hi, I am creating a file dynamically using cffile. When I open the file up, instead of carriage returns, I get squares. What am I doing wrong? Need help! Thanks. Code: <cffile action = "append" charset="utf-8" file = "c:\execute.vbs...

Free Tech Articles

  1. WARNING: 5 Reasons why you should NEVER fix a computer for free.
    It is in our nature to love the puzzle. We are obsessed. The lot of us. We love puzzles. We love the challenge. We thrive on finding the answer. We hate disarray. It bothers us deep in our soul. W...
  2. SCCM OSD Basic troubleshooting
    SCCM 2007 OSD is a fantastic way to deploy operating systems, however, like most things SCCM issues can sometimes be difficult to resolve due to the sheer volume of logs to sift through and the dispe...
  3. Migrate Small Business Server 2003 to Exchange 2010 and Windows 2008 R2
    This guide is intended to provide step by step instructions on how to migrate from Small Business Server 2003 to Windows 2008 R2 with Exchange 2010. For this migration to work you will need the fo...
  4. Create a Win7 Gadget
    This article shows you how to create a simple "Gadget" -- a sort of mini-application supported by Windows 7 and Vista. Gadgets can be dropped anywhere on the desktop to provide instant information, ...
  5. Outlook continually prompting for username and password
    There have been a lot of questions recently regarding Outlook prompting for a username and password whilst using Exchange 2007. There are a few reasons why this would happen and I will try to cover t...
  6. Backup Exchange 2010 Information Store using Windows Backup
    There seems to be quite a lot of confusion around the ability to backup Exchange 2010 using the built in Windows Backup feature. This stems from the omission of this feature prior to Exchange 2007 s...

Cloud Class Webinars

  1. Avoiding Bugs in Microsoft Access
    Alison Balter takes and in-depth look at avoiding bugs in Access. In this webinar you will learn about using the immediate window to debug your applications, invoking the debugger, using breakpoints to troubleshoot, stepping through code, setting the next statement to execute, ...
  2. Top 10 Best New Features in Visio 2010
    Scott Helmers gives live demonstrations of the top 10 new features in Visio 2010. This webinar will teach you how to create compelling diagrams by adding shapes to the page with a single click, linking the shapes in a diagram to data in Excel (or SQL Server, or SharePoint), ...
  3. IT Consultant Business Secrets Revealed
    Michael Munger, Experts Exchange tech pro and IT consultant, pulls back the curtain on his very successful businesses and answers question on every IT consultant and business owner should know about. He shares secrets on what he did to solve the 5 most common problems in IT, ...
  4. Disaster Recovery and Business Continuity
    Quest CTO, Mike Billon, gives an overview of the steps involved in building a dunamic disaster recovery plan. Through case studies and an examination of software/hardware tooles for monitoring and testing, you'll gain a better understandin of where you are, where you want ...
  5. Organize Your Visio Diagrams with Containers and Lists
    Scott Helmers uses cross functional flowcharts, wireframe diagrams, data graphic legends and seating charts to teach you: how to ustilize all three new structured diagram components in Visio 2010, the best practices for organizeing shapes in previous version of Visio, how to organize ...
  6. How to Us Objects, Properties, Events and Methods in Microsoft Access
    Alison Dalter gives an in-depbth look at objects, properties, events and methods in Microsoft Access. In this webinar you will learn about using the object browser, referring to objects, working with properties and methods, working with object variables, understanding the ...

Join the Community

Give a Little. Get a Lot.

Join the community of experts here and help other tech pros by answering question in your area of expertise. You can earn FREE access to all Experts Exchange's premium features and resources.

Join the Community

Answers

 

by: Pi7Posted on 2003-12-16 at 06:49:27ID: 9949490

Hi there,
  whenever you want to display text on 2 different lines use the vb const vbcrlf
e.g. if i want the text "This is an example.Hope it works fine" to appear in a textbox or label control like


This is an example.
Hope it works fine  

This is what I'll do assuming the text will be displayed in a text box
text1.text = "This is an example." & vbCrlf & "Hope it works fine"

 

by: demmickPosted on 2003-12-16 at 06:57:22ID: 9949568

I haven made my self clear wnough.

the database holds text including carriage returns.


E.g  rec1 = "this is good.
                  but not good enough"

when i write this value to the screen in vb i get

"square" this is good. "square"
but not good enough. "square"

 

by: CronanPosted on 2003-12-16 at 07:05:14ID: 9949619

The "squares" are CRs or LFs (ASCII 10 or 13) by themselves
You need to replace them with vbCRLF (which is simply a constant for a CR followed by an LF)

 

by: demmickPosted on 2003-12-16 at 07:10:02ID: 9949644

hOW CAN i DO THAT?

 

by: RanaHossainPosted on 2003-12-16 at 07:10:03ID: 9949645

demmick, how are you writing to screen... if its a textbox, set multiline to true, and put a scrollbar in.,

 

by: CronanPosted on 2003-12-16 at 07:10:57ID: 9949656

Sample code:

Function FixString(Byval inputString as String) as String
  Dim strInput As String
 
  strInput = inputString

  strInput = "Test line 1" & Chr(10) & "Test line 2" & vbCrLf & _
  "Test line 3" & Chr(13) & "Test line 4" & vbCrLf & "Test line 5" & vbCrLf
  'Change real crlf into nulls
  strInput = Replace(strInput, vbCrLf, Chr(0))
  'Change stand-alone line feeds.
  strInput = Replace(strInput, Chr(10), vbCrLf)
  'Change new crlfs into nulls.
  strInput = Replace(strInput, vbCrLf, Chr(0))
  ' Change standalone carriage returns.
  strInput = Replace(strInput, Chr(13), vbCrLf)
  'Replace the nulls w/ vbcrlf
  strInput = Replace(strInput, Chr(0), vbCrLf)

  FixString = strInput
End Sub

 

by: demmickPosted on 2003-12-16 at 07:11:19ID: 9949659

Well I am writing it out as a comment in an excel file.

 

by: CronanPosted on 2003-12-16 at 07:11:35ID: 9949661

Demmick

Don't shout! ;-)
I was writing the code out ...

Ivan

 

by: CronanPosted on 2003-12-16 at 07:12:27ID: 9949673

I do understand your frustration.
I hate it when I ask how to do something and people don't give me code ... ;-)

Ivan

 

by: demmickPosted on 2003-12-16 at 07:36:45ID: 9949861

Ivan

I wasn't shouting, I didn't realise my caps were on.

Sorry.

:-)

 

by: Pi7Posted on 2003-12-16 at 07:38:16ID: 9949875

demmick i think i have an idea how to get round this problem.If you want code then just remind me of the vb function that returns the position of a character within a string

 

by: demmickPosted on 2003-12-16 at 07:46:02ID: 9949942

I am totally confused now.  This is how I am writing out the comment in each box in the following way...

 Range("C" & i & ":C" & i).AddComment
 Range("C" & i & ":C" & i).Comment.Visible = True
 Range("C" & i & ":C" & i).Comment.text text:= rsTest("description")
 Range("C" & i & ":C" & i).Comment.Shape.TextFrame.Characters.Font.Bold = True

My SQL Database is storing "description" as longtext and the vaules in this field has carriage returns as this helps to span out the comments so thay are visible easily.  The problem is when I write the line out I get "squares" written in comments.  

 

by: CronanPosted on 2003-12-16 at 07:53:18ID: 9950002

Did you try my function?

 

by: CronanPosted on 2003-12-16 at 07:54:32ID: 9950013

So your code would be:

Range("C" & i & ":C" & i).Comment.text text:= FixString(rsTest("description"))

 

by: demmickPosted on 2003-12-16 at 08:12:16ID: 9950168

I tried that the squares are still there and it falls over if there is nothing in the field.  I tried testing for null but it's not working

 

by: CronanPosted on 2003-12-16 at 08:27:29ID: 9950279

try using the chr$() function combined with mid$ to work out what ASCII characters these are
e.g.

? chr$(mid$(somestring,11,1))

will print out the ascii code of the 11th item in the string
Do this for one of these "square" characters.

Then look up the code in your online help, or let me know what it is

 

by: CronanPosted on 2003-12-16 at 08:32:20ID: 9950320

So that you understand:

The characters in your string cannot be understood by Excel. That is why they are printing out as "squares"
To resolve this you need to ensure that such characters are either removed or changed before displaying in Excel, or (even better) that they are not added in to the data in the first place.

In one of your postings you wrote:

"the database holds text including carriage returns"

If this is true, then this is your problem. Excel will not understand carriage returns by themselves. Ensure that when the data is placed into the database, new lines are indicated by a carriage return immediately followed by a line feed. As pointed out by Pi7, this is done (in VB or VBA) by using the constant vbCrLf

What application is being used to insert the data (with the carriage returns) into the database?

 

by: demmickPosted on 2003-12-16 at 08:50:56ID: 9950465

Data is entered through a web page.

 

by: daffyduck14milPosted on 2003-12-16 at 09:29:27ID: 9950752

Hi,

Saw this post, and mind me saying, but this is simple to resolve. The problem with the "square's" in your text is as others have said. Excel doesn't understand the combination LineFeed and CariageReturn in comment text.

To resolve this problem, taking you use VB6, is to replace all instances of vbCrLf with CHR$(10) = vbLf. Excel then should have no problem with it.

The following code does this:

Range("C" & i & ":C" & i).Comment.text text:= Replace(rsTest("description").value, vbCrLf, vbLf)

If you still get square's, then there are other character codes you need to strip.

Thus, to recap:
- Excel comments don't understand cariage returns.
- Excel comments do understand line feeds.
- In order to use multiline comments in Excel, use linefeeds in your strings.

Grtz.&copy;

D.

-- Don't shoot, I'm already dead.

 

by: daffyduck14milPosted on 2004-02-09 at 03:01:19ID: 10308906

Hi,

I think we are looking at a hit-and-run. Just accept any answer, solution is valid.

Grtz.&copy;

D.

 

by: planoczPosted on 2004-02-25 at 05:02:12ID: 10449923

No comment has been added lately, so it's time to clean up this TA.
I will leave a recommendation in the Cleanup topic area that this question is:
No response from demmick from 2/8/2004 comment
Award points to daffyduck14mil(50%) and Cronan(50%) is recommend.
Please leave any comments here within the next four days.
Due Date : 3/1/2004
PLEASE DO NOT ACCEPT THIS COMMENT AS AN ANSWER!

planocz
EE Cleanup Volunteer

20120131-EE-VQP-002

3 Ways to Join

30-Day Free Trial

The Experts

98% positive feedback on 31,087 answers since March 2000. angeliii is a Microsoft Most Valuable Professional for his work with MS SQL Server & Develoment.

He has also proven his knowledge of Visual Basic Programming, PHP Scripting and Oracle Databases.

The Experts

97% positive feedback on 10,752 answers since July 2000. lrmoore has more than 18 years experience in the networking industry.

The six-time Mircosoft MVPs specialties include firewalls, virtual private networking, and network management.

Testimonials

"...and excellent source for support... Kind of like having your very own IT dept." Electriciansnet

Testimonials

"I was apprehensive at signing up at first. However... it has already made my life as an IT administrator much easier." JaCrews

Testimonials

"WOW! You guys have great, active, and knowledgeable people on here." moore50

Business Clients

Business Clients

In the Press

"If you’ve got a question... Experts Exchange can supply an answer.”

In the Press

"...an invaluable aid for both IT professionals and those who require tech support."

In the Press

"where IT professionals provide quick answers on just about any topic"

Business Account Plans

Loading Advertisement...