473,405 Members | 2,287 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,405 software developers and data experts.

Problem outputting to text box using VBA

119 100+
This is probably a very easy question to answer:

I have been outputting some text to a message box, similar to the following:

Expand|Select|Wrap|Line Numbers
  1. strOutput = "---" & Chr(10) & Chr(10)
  2. strOutput = strOutput & "VAR:" & AddTabs(1) & Format(rsVar![VAR], "currency")
  3. strOutput = strOutput & Chr(10) & Chr(10)
  4. strOutput = strOutput & "Position Value:" & AddTabs(1) & Format(rsVar![ValuePosition], "currency") & Chr(10)
  5. strOutput = strOutput & "Position Risk:" & AddTabs(1) & Format(rsVar![valueRisk], "currency") & Chr(10)
  6. msgbox(strOutput)
Which works fine. I tried outputting the same string (strOutput) in a text box on a form, i.e.:
Expand|Select|Wrap|Line Numbers
  1. txtBox.caption  = strOutput
The problem is that rather than creating new lines using chr(10), small boxes appear.

Does anyone know an equivalent to chr(10) that will work when sending a string to a text box?
Jun 2 '08 #1
12 13330
Stewart Ross
2,545 Expert Mod 2GB
Hi. You are not actually outputting the string to the textbox, but to its associated label (by use of the caption property). As far as I know labels are not intended to display multi-line strings, hence your problem with the line feed.

You should find that the actual text box displays multi-line strings correctly. To set the textbox itself to the string, simply use

txtBox = strOutput

You will need to resize the textbox vertically to see the second and subsequent lines correctly.

-Stewart

ps there is a vb constant vbCrLf which you can use in place of your Chr(10) to insert a complete carriage-return and line-feed combination into the string. You may find that this works reliably if the Chr(10) does not.
Jun 2 '08 #2
NeoPa
32,556 Expert Mod 16PB
** NEWS **

Stewart leaves me nothing to say - AGAIN!

/** NEWS **

I would only stress further that using vbCRLF (and/or associated vbCR and vbLF constants) is a recommended way to refer to these characters. It makes the code more easily readable if nothing else.
Jun 3 '08 #3
mshmyob
904 Expert 512MB
Actually Captions on labels CAN be multi lined.

As the previous posts say use the vbCrLF instead of chr(10) and then you MUST set the height of your label to accomodate all the lines. If your height is not set to accomodate all the lines it will just show 1 line or as many as it can show in the label.

I create multi line labels all the time. I also ran your code and substituted vbCRLF and it works for me.

cheers,

This is probably a very easy question to answer:

I have been outputting some text to a message box, similar to the following:

Expand|Select|Wrap|Line Numbers
  1. strOutput = "---" & Chr(10) & Chr(10)
  2. strOutput = strOutput & "VAR:" & AddTabs(1) & Format(rsVar![VAR], "currency")
  3. strOutput = strOutput & Chr(10) & Chr(10)
  4. strOutput = strOutput & "Position Value:" & AddTabs(1) & Format(rsVar![ValuePosition], "currency") & Chr(10)
  5. strOutput = strOutput & "Position Risk:" & AddTabs(1) & Format(rsVar![valueRisk], "currency") & Chr(10)
  6. msgbox(strOutput)
Which works fine. I tried outputting the same string (strOutput) in a text box on a form, i.e.:
Expand|Select|Wrap|Line Numbers
  1. txtBox.caption  = strOutput
The problem is that rather than creating new lines using chr(10), small boxes appear.

Does anyone know an equivalent to chr(10) that will work when sending a string to a text box?
Jun 3 '08 #4
billelev
119 100+
Thanks for all your comments.

I have replaced Chr(10) with vbCrLf with the desired results.

However...vbTab is not producing tabs, but those small boxes again...?
Jun 3 '08 #5
mshmyob
904 Expert 512MB
I don't think tabbing is supported in a label caption. You would just need to add spaces.

cheers,

Thanks for all your comments.

I have replaced Chr(10) with vbCrLf with the desired results.

However...vbTab is not producing tabs, but those small boxes again...?
Jun 3 '08 #6
NeoPa
32,556 Expert Mod 16PB
Tabs in general (and therefore vbTab in this situation) only has meaning within a defined context. What would you be expecting of a tab within a label?

The difference between Chr(10) and vbCRLF is not simply that one is a constant. Chr(10) is actually equivalent to vbLF rather than vbCRLF (It is a Line-Feed rather than a Character Return / Line Feed combination).

I suspect that whichever control you're using this in (TextBox or Label) has no context defined for Tab characters therefore it won't match what you expect.
Jun 3 '08 #7
billelev
119 100+
Tabs in general (and therefore vbTab in this situation) only has meaning within a defined context. What would you be expecting of a tab within a label?

The difference between Chr(10) and vbCRLF is not simply that one is a constant. Chr(10) is actually equivalent to vbLF rather than vbCRLF (It is a Line-Feed rather than a Character Return / Line Feed combination).

I suspect that whichever control you're using this in (TextBox or Label) has no context defined for Tab characters therefore it won't match what you expect.
I'm trying to display a table of data, aligning the columns using tabs. I'm also outputting the same text to an email, which accepts the tab character. The table is roughly 6 columns by 20 rows.
Jun 3 '08 #8
Stewart Ross
2,545 Expert Mod 2GB
As NeoPa says, a tab has no meaning without a context. Thirty years ago typewriter teachers used to teach typing students about the use of tabs, and how important they were in lining up numbers within the manually-spaced lines of (monospaced) Courier or similar text.

Tabs are more or less obsolete in powerful word processors such as Word, where the line-oriented left, right, centre and decimal tabs have generally been replaced by the use of tables, where the columns themselves can align text left, centre and right. Even so, Word still has default tabs set every 1/2 in as standard. Whay am I mentioning this? Because if you set up a document with 1/2" tabs, use these to space the text, then someone changes it to 1", say, the document suddenly becomes unreadable.

It is because a tab is effectively an instruction to move the current text location to a defined point that it has no meaning unless the context is defined.

...And all of this is a long-winded way of asking you, as NeoPa has also done - in what context is it meaningful to include tabs in a text control which has no default means of handling the spacing instruction you have included?

-Stewart (the verbose...)
Jun 3 '08 #9
LBryant
18
You can use a List Box control for displaying information in columns, yes?
Jun 3 '08 #10
Stewart Ross
2,545 Expert Mod 2GB
(Sigh) It takes longer to write a reply than it does for the thread context to change, hence I sent then deleted a message which was out of context of the changed thread.

The last poster makes the point that a listbox control can be used to output columns. It can, but with limitations - there is not much in the way of alignment that can be done, for instance. And it does not answer what you need for output via e-mail. I would suggest using a text export which is tab-delimited or using CSV format to output your columns, rather than trying to do this in the message itself. This would be an attachment task, but at least has the advantage that tabs delineate columns, whereas otherwise the interpretation of tabs depends entirely on the application.

In my experience e-mail applications do not do a good job of tabbing, as they impose defaults in the same way as word processors do - arbitrarily. Some columns line up, some don't as they miss the tab point concerned. Some spill into the next column, and so on.

-Stewart
Jun 3 '08 #11
NeoPa
32,556 Expert Mod 16PB
You could try using spaces to format your output. Many text processors use this method even now, especially when no default context is defined. Alternatively, using the same approach, you could use a character other than the space for tabulation formatting (characters frequently used for this include . - _ = * + etc).

PS. Thanks Stewart for that clarification. You translated my message perfectly :)
Jun 4 '08 #12
billelev
119 100+
Thanks for the clarification.

The original context was within an email, wherein a tab character moved in multiples of six character spaces, to the nearest multiple. This made the formatting of the table using tabs a reasonably trivial task. I'll probably try using spaces to format the text within the text box.
Jun 4 '08 #13

Sign in to post your reply or Sign up for a free account.

Similar topics

7
by: Cezary | last post by:
Hi. I want to change language on my site online. So, I wrote this: <form action="<?= preg_replace("/&/", "&amp;", $_SERVER) ?>" method="post" name="change_lang_form"> <p...
5
by: Andrei Pociu | last post by:
I have a major doubt about outputting text in ASP .NET when using code behind. I know most of the output you gain from a code behind file (.aspx.cs) is outputted to the Webform (.aspx) using...
5
by: Lyle A. Sieren | last post by:
Hello! Is there a way to output text in a unix format from vb.net? I am trying to complete a CIM load in Progress and I need the data to be in unix format. I tried using the following code...
1
by: Bishman | last post by:
Hi, I have been trying to get text to scroll smoothly accross a windows form using GDI+ and a timer. Changing the position of the text by a configurable amount and calling invalidate to force a...
3
by: xiaawan | last post by:
Hi Everyone . I am having problem with text align in CSS. I am using <li> element. I want to display text centered vertically i.e. it should be at equal distance from top and bottom. sorry for my bad...
3
by: nskclr | last post by:
Hi I add a text using document.selection.createRange(). I want to add a text to the bottom of another text - similar to what we do in HTML. <p> xyz </p> <p><div...
1
by: NosherRees | last post by:
I'm using GraphicsPath to draw text onto a graphics object (PictureBox). My graphics object has been scaled so that the top left corner is 400000, 6000000 and the bottom right corner is 400100,...
5
by: padmaneha | last post by:
How to omit replacement in somepart of text using regular expression? For ex: If i want to replace mumbai with mumbai/aaa.com but if i have an anchor tag <a...
1
by: u8dmtm | last post by:
I want to output XML from an ASP.Net page and have created the code below: using System; using System.Data; using System.Configuration; using System.Collections.Generic; using System.Linq;...
0
by: Sirus86 | last post by:
problem with text and image.Text is overlaying or moving to below image. i design is very complex and i need to include a scroll within the design. this is what i have so far div id="content" ...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.