Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Chris Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Creating text with superscript

Status
Not open for further replies.

fawkes

Technical User
Sep 12, 2003
343
GB
I'm writing a class that contains a collection of strings that hold dimensional symbols. As part of this I need to add indexes (number powers) like superscript to the text, e.g. m4 where 4 is superscript.

How do i do this in Visual basic 6.0?

I can use chr(178) and chr(179) for squares and cubics, but for quartics I struggle.

Any ideas?
 
a. One option is to use the Rich Text Format codes for storing the string. Displaying the strings, if required, would be easy as you can use the RichTextBox control. Morever, this is a good option as RTF codes are pretty standard, and your data can be easily ported between applications if required.

b. Another similar option is HTML code.

c. Yet another is to have your own standard to store the strings and your functions to code/decode the same. It would be a problem however, if you want to enhance (say have provisions for special characters, or underlining, etc.) later on. Morever, for displaying the strings you would again have to use RTF, HTML or similar things.

So, the first 2 and similar options seem the best. You would also have special character support (say characters like 'alpha', 'beta', and many other standard symbols)...

For details about how to implement RTF (and RichTextBox control) or HTML, you would need to have a look at your MSDN collection...

Hope this helped. [pipe]

Ankan.

Please do correct me if I am wrong. s-)
 
Sure. You'll need to use a RichtextBox rather than a normal textbox for this technique to work (and you also need to be aware that the implementation in VB is of an old version of the rich tect control, so you do get some clipping issues. It works best if the font you are using is a TrueType font.

Anyway. You need a form with a rich text box and a command button for this example. The drop in the following code:

Private Sub Command1_Click()
RichTextBox1.SelRTF = SuperScriptRTF(RichTextBox1.SelText, 9)
End Sub

Private Function SuperScriptRTF(strText As String, Optional FontSize As Long = 9) As String
' fs<x> represents font size, where <x> is twice the required point size
Dim fs As String

fs = &quot;fs&quot; & (2 * FontSize)
SuperScriptRTF = &quot;{\rtf1\super\&quot; & fs & &quot; &quot; & strText & &quot;}&quot;
End Function
 
Thanks for the answers.

This class object doesn't have any controls.

It isn't a form, it simply holds a text value (be that a string or whatever) of the dimensional symbol which can be returned using either a property or method.

Would your options work with this, bearing in mind that there is no guarantee that the calling procedure uses a rich text box.
 
Well, if the calling procedure cannot support displaying mixed fonts, then you are more or less out of luck, unless you can find a font that contains all the superscripted numbers...
 
I've got a little further.

If I use ChrW(&HB2) I get the squared symbol to show in a message box. I've found the unicode for the power 4 which is 2074 but when I use ChrW(&H2074) I just get a 4, is this a problem with the fonts on my machine or a problem with the unicodes?

How do I resolve this?
 
It's a combination. Firstly, the standard controls in VB don't know how to display Unicode characters (MS Forms 2.0, which you can load as a component, does). Secondly you need a font that has the characters in it (as I suggested before). Eg, instead of Arial, you need Arial Unicode MS. And this still won't do you any good if the calling procedure does not a) use Unicode and b) doesn't have a Unicode font available. So, sadly, you've still got some hoops to jump through.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top