Home
Search
 
What's New
Index
Books
Links
Q & A
Newsletter
Banners
 
Feedback
Tip Jar
 
C# Helper...
 
XML RSS Feed
Follow VBHelper on Twitter
 
 
 
MSDN Visual Basic Community
 
 
 
 
 
TitleDraw mathematical equations with super scripts on a form
DescriptionThis example shows how to draw mathematical equations with super scripts on a form in Visual Basic 6.
Keywordsequation, superscript, math
CategoriesStrings, Graphics
 
The program searches the text and decreases the form's Y position slightly when it sees the ^ character.
 
' Display an equation with superscripting. Set
' the form's CurrentX and CurrentY before
' calling this routine.
Private Sub PrintEquation(frm As Form, equation As String)
Const OFFSET = 40
Dim super_scripting As Integer
Dim i As Integer
Dim ch As String

    For i = 1 To Len(equation)
        ch = Mid$(equation, i, 1)
        If ch = "^" Then
            ' Start superscripting.
            super_scripting = True
            frm.CurrentY = frm.CurrentY - OFFSET
        Else
            If super_scripting And (ch < "0" Or ch > "9") _
                Then
                ' Not a numeral. End superscripting.
                super_scripting = False
                frm.CurrentY = frm.CurrentY + OFFSET
            End If
            frm.Print ch;
        End If
    Next i
End Sub
 
You can use similar techniques to provide subscripting and other affects. Note that this simple example doesn't handle cases such as negative superscripts, sub-equations such as X^{3-1}, etc.
 
 
Copyright © 1997-2010 Rocky Mountain Computer Consulting, Inc.   All rights reserved.
  Updated