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

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
    Case 1
    Case 2
    Case 3
    Case 4
    Case 5
    Case 6
    Case 7
    Case 8
    Case 9
    End Select
  Next i
  Return s
End Function


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)))
  Return r
End Function

opps… I mis-read “SUB” as “SUPER” :slight_smile:

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