|
-
Feb 27th, 2013, 12:25 AM
#1
Thread Starter
New Member
Subscripts
How do I format the numbers so that they are subscripts? I get an output of X1Y1 + X2Y2 +…, but ideally I would like it to be X1Y1 + X2Y2 +… so that it is easier to read.
Code:
Public Class Form1
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
Dim n, i, count As Integer
Dim string2 As String = ""
Dim string3 As String = ""
i = 1
n = 10
For count = i To n - 1
string2 &= "X" & count.ToString & "Y" & count.ToString & " + "
Next
string3 &= "X" & n.ToString & "Y" & n.ToString
lbl_ans.Text &= string2 & string3
End Sub
End Class
-
Feb 27th, 2013, 05:31 AM
#2
Re: Subscripts
Without resorting to a RichTextBox and applying formatting, you'll need to use the Subscript Digit characters (unicode characters U+2080 -> U+2089). Since you only have ten characters to display, I would simply set up a mapping from the integer to the string - if it was a variable number you might want to set up some kind of generalised function.
vbnet Code:
Public Class Form1
Private _subscripts As New Dictionary(Of Integer, String) From {
{1, ChrW(2081)},
{2, ChrW(2082)},
{3, ChrW(2083)},
{4, ChrW(2084)},
{5, ChrW(2085)},
{6, ChrW(2086)},
{7, ChrW(2087)},
{8, ChrW(2088)},
{9, ChrW(2089)},
{10, ChrW(2081) & ChrW(2080)}}
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
Dim n, i, count As Integer
Dim string2 As String = ""
Dim string3 As String = ""
i = 1
n = 10
For count = i To n - 1
string2 &= "X" & _subscripts(count) & "Y" & _subscripts(count) & " + "
Next
string3 &= "X" & _subscripts(n) & "Y" & _subscripts(n)
lbl_ans.Text &= string2 & string3
End Sub
End Class
Your only problem then is to find a font that supports those characters, or you get little boxes instead of your subscripts.
-
Feb 27th, 2013, 06:08 AM
#3
Re: Subscripts
Don't forget those numbers are hexadecimal, so you'll need to include the hexadecimal literal prefix
Code:
Private _subscripts As New Dictionary(Of Integer, String) From {
{1, ChrW(&H2081)},
{2, ChrW(&H2082)},
{3, ChrW(&H2083)},
{4, ChrW(&H2084)},
{5, ChrW(&H2085)},
{6, ChrW(&H2086)},
{7, ChrW(&H2087)},
{8, ChrW(&H2088)},
{9, ChrW(&H2089)},
{10, ChrW(&H2081) & ChrW(&H2080)}}
As for fonts, Google says try Palatino Linotype, or Calibri which I think is only supplied with Windows 7.
-
Feb 27th, 2013, 06:24 AM
#4
Thread Starter
New Member
Re: Subscripts
Without resorting to a RichTextBox and applying formatting
How would I do this with the richtextbox?
if it was a variable number you might want to set up some kind of generalised function.
I would like this to be for any number not just one through ten.
Your only problem then is to find a font that supports those characters, or you get little boxes instead of your subscripts.
Yes I am getting little boxes. Even with arial unicode ms font which supposedly supports it.
http://www.fileformat.info/info/unic...and_subscripts
-
Feb 27th, 2013, 06:32 AM
#5
Thread Starter
New Member
Re: Subscripts
 Originally Posted by Inferrd
Don't forget those numbers are hexadecimal, so you'll need to include the hexadecimal literal prefix
Code:
Private _subscripts As New Dictionary(Of Integer, String) From {
{1, ChrW(&H2081)},
{2, ChrW(&H2082)},
{3, ChrW(&H2083)},
{4, ChrW(&H2084)},
{5, ChrW(&H2085)},
{6, ChrW(&H2086)},
{7, ChrW(&H2087)},
{8, ChrW(&H2088)},
{9, ChrW(&H2089)},
{10, ChrW(&H2081) & ChrW(&H2080)}}
As for fonts, Google says try Palatino Linotype, or Calibri which I think is only supplied with Windows 7.
Thank you. Those changes did the trick. Palatino Linotype and Calibri also works with windows 8. I guess now I would have to create a function so that it works for any number.
-
Feb 27th, 2013, 07:12 AM
#6
Re: Subscripts
In making the function, I would first convert the integer to a string with the "D" format string. This will ensure you get just integral digits. Then spin through each of the characters in the string which you know are simply the digits 0->9 (assuming you ignore negative numbers!). You can change the lookup dictionary to be (Of Char,String) and map "0"c to ChrW(&H2080) (thanks for the correction, Inferred!) and so on. For each character, lookup the string and append that string to your value that will be returned (you may want to investigate the StringBuilder class in System.Text namespace)
Tags for this Thread
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|