math symbols

Posted on 2009-05-22
Medium Priority
Last Modified: 2013-12-17
How do I add math symbols when i write to a textile from vb.net eg like square root or superscript?
Question by:jagguy
  • 5
  • 2
LVL 32

Expert Comment

by:Daniel Wilson
ID: 24450856
Only ASCII values can be written to a text file.

If you're using Unicode, you can write Unicode characters.

But for math symbols you need a file format other than text.
LVL 39

Expert Comment

ID: 24450900
There are different ways, if you want to go professional, you may want to look up MathML, but expect a learning curve. You say "text file", so I assume you just mean simple math symbols in between the text.

You can use Unicode for that, which is supported by Visual Basic, make sure that you open and write your file using Unicode (Encoding.UTF8 is fine), otherwise you will see a mangled effect or even errors.

Not all fonts support all the unicode characters. Here's a list of all mathematical symbols available: http://unicode.org/charts/PDF/U2200.pdf. In the screenshot you can see that my simple Arial font does not have many of that subset.

LVL 39

Expert Comment

ID: 24450965
Note that when you write these symbols to a text file, someone opening it must understand UTF8. If you use Notepad, or actually Windows application, you should be fine (see attachment), which will automatically recognize it.

Sorry DanielWilson, but it is just not correct that only ASCII can be written to a text file, unless you have a very ancient system (70's, 80's like). In fact, many encodings and character sets exist, but for now, the most used and fully covering, well-supported encoding is Unicode, which is universally recognized.

-- Abel --

Keep up with what's happening at Experts Exchange!

Sign up to receive Decoded, a new monthly digest with product updates, feature release info, continuing education opportunities, and more.

LVL 39

Expert Comment

ID: 24451157
So, back to the "how to". That's a piece of cake. If you use Visual Studio, by default, your files will be (should be!) in UTF8. You can test that by simply writing a line like the following (see screenshot) which I wrote in C# in Visual Studio.

Any character like that can be added. Even if the character cannot be represented because the font does not have that particular character, the character can still be used (you will see a block-like symbol). In that case, it is often better and more understandable, to use the codepoint instead.

LVL 32

Expert Comment

by:Daniel Wilson
ID: 24451172
Sorry, Abel.  I guess working with VB6 so long has me still thinking of Unicode as the exception rather than the rule.
LVL 39

Expert Comment

ID: 24451434
understandable. Though even VB6, with a little work, could deal with Unicode (ChrW, AscW etc). Did you know that Windows used Unicode under the hood since, iirc, NT 3.51? And that the consumer edition has it since Windows 95/98, though partially, and that Win2K and XP have it fully and solely (meaning, it is not possible NOT to use it)?

Still many systems exist with mixed encodings. E-E for one, is completely Unicode, but has a problem in the backend, where it stores the data as ISO-8859-1 (how I know? Try to write some Unicode-aware characters, like the euro-sign. Though the page is served in Unicode, it won't come up as a euro sign).

To the OP, and more on the subject: to go from a codepoint to a character, you can use:

' these numbers can be found at unicode.org or any other online ref '
Dim cSummationSign As Char = Char.ConvertFromUtf32(&h2211)
Dim cSquareRoot As Char = Char.ConvertFromUtf32(&h221A)

Open in new window


Author Comment

ID: 24455869
ok thanks for the replies as I didnt expect so many.
I am using vb.net express 2008. I am writing to a textfile and to write a math symbol like 'Abe'l' did I need , what do you press on the keyboard to make these symbols appear?
LVL 39

Accepted Solution

abel earned 2000 total points
ID: 24455980
ah, that's a whole different ballgame. I hate to remember the keyboard shortcuts (there are shortcuts for many of them, but not all), but the easy way to get this is to go to the Character Map of windows. Just click WinKey-R and then "charmap" + Enter (or any other method you like for starting Character Map) and select the symbols you like.

A hint: inside Character Map, you should select the Group By > Unicode Subrange and then Mathematical Symbols. Is the map empty? Select another font, which may have more glyphs.

A few shortcuts I found through that screen (the zero must be typed):

Superscript one: Alt+0185
Superscript two: Alt+0178
Superscript three: Alt-0179
Three Quarters: Alt+0190
Multiplication sign: Alt+215

Things like "Not equal to", "square root" etc are not giving their respective keyboard input, but you can calculate it yourself: just take the hexadecimal value (U+221A, bottom left in Charmap for square root) and make that decimal: 8730. Type Alt-8730 in any application in windows, and behold, there's the square root (if the selected font supports it).

Hmm, that's what it's supposed to be. But it isn't. It works in charmap and it works in other applications, but the corresponding codes are totally different. So, you're stuck with Charmap for now.


Featured Post

Free Tool: Path Explorer

An intuitive utility to help find the CSS path to UI elements on a webpage. These paths are used frequently in a variety of front-end development and QA automation tasks.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

Join & Write a Comment

In real business world data are crucial and sometimes data are shared among different information systems. Hence, an agreeable file transfer protocol need to be established.
Article by: Shaun
Tiling windows is a great way to see multiple applications at once. Windows Tiler is a tool that automatically tiles open application windows as the open and close.
Show developers how to use a criteria form to limit the data that appears on an Access report. It is a common requirement that users can specify the criteria for a report at runtime. The easiest way to accomplish this is using a criteria form that a…
This lesson covers basic error handling code in Microsoft Excel using VBA. This is the first lesson in a 3-part series that uses code to loop through an Excel spreadsheet in VBA and then fix errors, taking advantage of error handling code. This l…

587 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question