⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 eval.frm

📁 是一个VB类,相当于vbscript中的eval函数,是用堆栈实现
💻 FRM
字号:
VERSION 5.00
Begin VB.Form frmMain 
   BorderStyle     =   3  'Fixed Dialog
   Caption         =   "Expression Evaluator"
   ClientHeight    =   2055
   ClientLeft      =   2445
   ClientTop       =   2805
   ClientWidth     =   3750
   ClipControls    =   0   'False
   LinkTopic       =   "Form1"
   PaletteMode     =   1  'UseZOrder
   ScaleHeight     =   2055
   ScaleWidth      =   3750
   Begin VB.CommandButton cmdExit 
      Cancel          =   -1  'True
      Caption         =   "E&xit"
      Height          =   375
      Left            =   2520
      TabIndex        =   5
      Top             =   1560
      Width           =   1095
   End
   Begin VB.TextBox txtResult 
      BackColor       =   &H8000000F&
      Height          =   285
      Left            =   120
      Locked          =   -1  'True
      TabIndex        =   3
      Top             =   1080
      Width           =   3495
   End
   Begin VB.TextBox txtExpression 
      Height          =   285
      Left            =   120
      TabIndex        =   1
      Text            =   "((45 * 7) + 14) * FIVE"
      Top             =   360
      Width           =   3495
   End
   Begin VB.CommandButton cmdEvaluate 
      Caption         =   "E&valuate"
      Default         =   -1  'True
      Height          =   375
      Left            =   1320
      TabIndex        =   4
      Top             =   1560
      Width           =   1095
   End
   Begin VB.Label Label2 
      Caption         =   "Result:"
      Height          =   255
      Left            =   120
      TabIndex        =   2
      Top             =   840
      Width           =   1935
   End
   Begin VB.Label Label1 
      Caption         =   "&Expression:"
      Height          =   255
      Left            =   120
      TabIndex        =   0
      Top             =   120
      Width           =   1935
   End
End
Attribute VB_Name = "frmMain"
Attribute VB_GlobalNameSpace = False
Attribute VB_Creatable = False
Attribute VB_PredeclaredId = True
Attribute VB_Exposed = False
'CEval - Algebraic expression evaluator class for VB5
'Copyright (c) 1995-97 SoftCircuits Programming (R)
'Redistributed by Permission.
'
'This class implements an Algebraic expression evaluator for Visual
'Basic 5. It support floating point numbers, most standard operators,
'plus or minus unary operators and parantheses to override default
'precedence rules. Rudimentary support for user-defined symbols is also
'included.
'
'To use this class in your own programs, you need to include CEval.cls,
'CStack.cls and CSymbolTable.cls in your project. If you don't need
'support for user symbols, then set the USE_SYMBOLS #Const to False and
'then only include CEval.cls and CStack.cls.
'
'At the time this demo was put together, SoftCircuits was building a
'more sophisticated version of this code that is implemented as a
'control and uses events to implement user symbols and even user
'functions. Although not determined at this time, this example will
'most likely not be for free. But if you need something a little more
'sophisticated, please stop by our web site and see what else we have
'to offer.
'
'This program may be distributed on the condition that it is
'distributed in full and unchanged, and that no fee is charged for
'such distribution with the exception of reasonable shipping and media
'charged. In addition, the code in this program may be incorporated
'into your own programs and the resulting programs may be distributed
'without payment of royalties.
'
'This example program was provided by:
' SoftCircuits Programming
' http://www.softcircuits.com
' P.O. Box 16262
' Irvine, CA 92623
Option Explicit

Private eval As New CEval

'Evaluates the given expression
Private Sub cmdEvaluate_Click()
    'Trap errors
    On Error GoTo EvalError
    'Evaluate expression
    txtResult = eval.Evaluate(CStr(txtExpression))
    Exit Sub
EvalError:
    MsgBox Err.Description  'Display error message
    Exit Sub
End Sub

Private Sub Form_Load()
    Dim symbols As New CSymbolTable

    'Center form
    Move (Screen.Width - Width) / 2, (Screen.Height - Height) / 2
    'Define some sample symbols (not case sensitive)
    symbols.Add "One", 1
    symbols.Add "Five", 5
    symbols.Add "Ten", 10
    symbols.Add "Hundred", 100
    'Assign symbol table to our eval object
    Set eval.m_SymbolTable = symbols
    'In addition to assigning a new symbol table object,
    'we can also access eval's symbol table directly
    eval.m_SymbolTable.Add "Thousand", 1000

End Sub

Private Sub cmdExit_Click()
    Unload Me
End Sub

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -