

Title  Draw mathematical equations with super scripts on a form 
Description  This example shows how to draw mathematical equations with super scripts on a form in Visual Basic 6. 
Keywords  equation, superscript, math 
Categories  Strings, 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, subequations such as X^{31}, etc.





