home *** CD-ROM | disk | FTP | other *** search
- VERSION 2.00
- Begin Form fRegular
- BackColor = &H00C0C0C0&
- Caption = "Evaluator"
- ClientHeight = 2805
- ClientLeft = 1875
- ClientTop = 1155
- ClientWidth = 4410
- Height = 3210
- Left = 1815
- LinkTopic = "Form3"
- ScaleHeight = 2805
- ScaleWidth = 4410
- Top = 810
- Width = 4530
- Begin TextBox Text2
- FontBold = 0 'False
- FontItalic = 0 'False
- FontName = "MS Sans Serif"
- FontSize = 9.75
- FontStrikethru = 0 'False
- FontUnderline = 0 'False
- Height = 465
- Left = 90
- TabIndex = 0
- Top = 1845
- Width = 3120
- End
- Begin CommandButton Command1
- BackColor = &H00C0C0C0&
- Caption = "Formula"
- FontBold = 0 'False
- FontItalic = 0 'False
- FontName = "MS Sans Serif"
- FontSize = 8.25
- FontStrikethru = 0 'False
- FontUnderline = 0 'False
- Height = 375
- Left = 3285
- TabIndex = 3
- Top = 90
- Width = 825
- End
- Begin TextBox Text1
- FontBold = 0 'False
- FontItalic = 0 'False
- FontName = "MS Sans Serif"
- FontSize = 9.75
- FontStrikethru = 0 'False
- FontUnderline = 0 'False
- Height = 465
- Left = 90
- TabIndex = 2
- Text = "(5+3)*2"
- Top = 1305
- Width = 3120
- End
- Begin vsFlexString fs
- Left = 3600
- Pattern = "[^ , ]*"
- Text = "VideoSoft FlexString"
- Top = 540
- End
- Begin Label Label1
- BackStyle = 0 'Transparent
- Caption = "Type expressions consisting of numbers, parenthesis, and basic operators (+, -, *, /, ^). Then click the button and see the result."
- FontBold = 0 'False
- FontItalic = 0 'False
- FontName = "MS Sans Serif"
- FontSize = 9.75
- FontStrikethru = 0 'False
- FontUnderline = 0 'False
- Height = 1095
- Left = 90
- TabIndex = 1
- Top = 135
- Width = 3075
- End
- Option Explicit
- Sub Command1_Click ()
- caption = "Evaluator"
- Text2 = Format(Evaluate(Text1), "0.00")
- End Sub
- Function Evaluate (ByVal s$)
- Dim s1$, s2$, s3$
- ' get ready to parse
- fs = Trim(s)
- ' parenthesis
- fs.Pattern = "{.*}({.*}){.*}"
- If fs.MatchCount > 0 Then
- fs.TagIndex = 0: s1 = fs.TagString
- fs.TagIndex = 1: s2 = fs.TagString
- fs.TagIndex = 2: s3 = fs.TagString
- Evaluate = Evaluate(s1 + Format(Evaluate(s2)) + s3)
- Exit Function
- End If
- ' add
- fs.Pattern = "{.*}{[+-]}{.*}"
- If fs.MatchCount > 0 Then
- fs.TagIndex = 0: s1 = fs.TagString
- fs.TagIndex = 2: s2 = fs.TagString
- fs.TagIndex = 1
- Select Case fs.TagString
- Case "+": Evaluate = Evaluate(s1) + Evaluate(s2)
- Case "-": Evaluate = Evaluate(s1) - Evaluate(s2)
- End Select
- Exit Function
- End If
- ' multiply
- fs.Pattern = "{.*}{[*/]}{.*}"
- If fs.MatchCount > 0 Then
- fs.TagIndex = 0: s1 = fs.TagString
- fs.TagIndex = 2: s2 = fs.TagString
- fs.TagIndex = 1
- Select Case fs.TagString
- Case "*": Evaluate = Evaluate(s1) * Evaluate(s2)
- Case "/":
- If Evaluate(s2) <> 0 Then
- Evaluate = Evaluate(s1) / Evaluate(s2)
- Else
- caption = "error: Divide by 0"
- Beep
- End If
- End Select
- Exit Function
- End If
- ' power
- fs.Pattern = "{.*}^{.*}"
- If fs.MatchCount > 0 Then
- fs.TagIndex = 0: s1 = fs.TagString
- fs.TagIndex = 1: s2 = fs.TagString
- Evaluate = Evaluate(s1) ^ Evaluate(s2)
- Exit Function
- End If
- ' number
- fs.Pattern = "[0-9]+\.?[0-9]?"
- If fs.MatchLength = Len(fs) Then
- Evaluate = Val(s)
- Else
- caption = "error: Syntax"
- Beep
- End If
- End Function
-