I am trying to output a chemical formula in a label or text field but cannot figure out if I can subscript the calculated number of atoms for each element
Use a Canvas instead with a smaller size and Y-4 (for example).
or use Unicode characters
https://en.wikipedia.org/wiki/Unicode_subscripts_and_superscripts
x¹ x² x³ x? x? x? x? x? x? x?
Me.Text = "x"+&ub9+" x"+&ub2+" x"+&ub3+" x"+&u2074+" x"+&u2075+" x"+&u2076+" x"+&u2077+" x"+&u2078+" x"+&u2079+" x"+&u2070
Thank you. But I will be calculating the numbers that I want subscripted rather than using a known number. The format is C25H34N3O5.
and? that statement is the essence of what programming is all about…
Public Function makeSuperScript(s As String) as String
Dim i As Integer
Dim c As String
For i=0 To 9
Select Case i
Case 0
c=&u2070
Case 1
c=&ub9
Case 2
c=&ub2
Case 3
c=&ub3
Case 4
c=&u2072
Case 5
c=&u2075
Case 6
c=&u2076
Case 7
c=&u2077
Case 8
c=&u2078
Case 9
c=&u2079
End Select
s=ReplaceAll(s,Str(i),c)
Next i
Return s
End Function
s=me.text=makeSuperScript("C25H3N3O5")
C²?H³N³O?
Codepoints for unicode Subscripts are &h2080 through &h2089:
Public Function subscript(i as integer) as String
// return subscripted text for i
Dim r As String
Dim digits As String = Str(i)
Dim d As Integer
While d < LenB(digits)
d = d + 1
r = r + Text.FromUnicodeCodepoint(&h2080 + Val(MidB(digits,d,1)))
Wend
Return r
End Function
opps… I mis-read “SUB” as “SUPER”
Thank you both. I will give these a try.
If you are not taking about editable text, IMO for chemical formulas is is best to draw the text oneself in a canvas as then you can control teh look/spacing however you want and no worry about the specific font used has that glyph.
The way I handled that was NOT using unicode but a both a calculated smaller font size relative to non scripted characters and changing the baseline of the scripted characters (super or subscripts).
For handling formulas I wrote code that can take a string such as C24H34N3O5+1 draw it how I want it,
For one app the input is a formula a string such as C24H34N3O5.The code in calculates the average and monoisotopic molecular weight from that , and puts the data +1, 2 etc ions and all of the common MS adducts for that polarity into listbox with the formulas drawn correctly
-karen