Home
Search
 
What's New
Index
Books
Links
Q & A
Newsletter
Banners
 
Feedback
Tip Jar
 
 
 
 
 
 
 
 
Old Pages
 
Old Index
Site Map
What's New
 
Books
How To
Tips & Tricks
Tutorials
Stories
Performance
Essays
Links
Q & A
New in VB6
Free Stuff
Pictures
 
 
 
TitleDisplay chemical symbols in a RichTextBox or on a form
Keywordssymbol, chemical symbol, superscript, subscript
CategoriesGraphics, Controls
 
Adjust text positioning to subscript numerals. Subroutine RichTextSubscriptNumerals searches a RichTextBox's text for numerals and adjusts them by a subscript offset amount.

Subroutine FormPrintFormula prints a string onto a form, adjusting each numeral down by a subscript offset amount.

 
' Offset numerals by the indicated amount.
Private Sub RichTextSubscriptNumerals(ByVal rch As _
    RichTextBox, Optional ByVal offset As Integer = -50)
Dim i As Integer
Dim txt As String

    txt = rch.Text
    For i = 1 To Len(txt)
        If Mid$(txt, i, 1) >= "0" And Mid$(txt, i, 1) <= _
            "9" Then
            rch.SelStart = i - 1
            rch.SelLength = 1
            rch.SelCharOffset = offset
        End If
    Next i
End Sub

' Draw a formuls offseting numerals by the indicated amount.
Private Sub FormPrintFormula(ByVal frm As Form, ByVal X As _
    Single, ByVal Y As Single, ByVal txt As String, _
    Optional ByVal offset As Single = 60)
Dim i As Integer
Dim ch As String

    frm.CurrentX = X
    For i = 1 To Len(txt)
        ch = Mid$(txt, i, 1)
        If ch >= "0" And ch <= "9" Then
            frm.CurrentY = Y + offset
        Else
            frm.CurrentY = Y
        End If

        frm.Print ch;
    Next i
End Sub
 
 
Copyright © 1997-2003 Rocky Mountain Computer Consulting, Inc.   All rights reserved.
  Updated