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

📄 form1.frm

📁 计算控件。以CSTING形式输入的表达试
💻 FRM
📖 第 1 页 / 共 2 页
字号:
   End
   Begin VB.Line Line1 
      BorderColor     =   &H00404040&
      X1              =   120
      X2              =   7800
      Y1              =   3000
      Y2              =   3000
   End
   Begin VB.Label Label8 
      Alignment       =   1  'Right Justify
      Caption         =   "结果"
      BeginProperty Font 
         Name            =   "MS Sans Serif"
         Size            =   9.75
         Charset         =   0
         Weight          =   400
         Underline       =   0   'False
         Italic          =   0   'False
         Strikethrough   =   0   'False
      EndProperty
      Height          =   255
      Left            =   3240
      TabIndex        =   17
      Top             =   4440
      Width           =   495
   End
   Begin VB.Label Label7 
      Alignment       =   1  'Right Justify
      Caption         =   "重复计数"
      BeginProperty Font 
         Name            =   "MS Sans Serif"
         Size            =   9.75
         Charset         =   0
         Weight          =   400
         Underline       =   0   'False
         Italic          =   0   'False
         Strikethrough   =   0   'False
      EndProperty
      Height          =   255
      Left            =   3240
      TabIndex        =   15
      Top             =   3840
      Width           =   855
   End
   Begin VB.Label Label6 
      Alignment       =   1  'Right Justify
      Caption         =   "测试表达式 y=f(x)="
      BeginProperty Font 
         Name            =   "MS Sans Serif"
         Size            =   9.75
         Charset         =   0
         Weight          =   400
         Underline       =   0   'False
         Italic          =   0   'False
         Strikethrough   =   0   'False
      EndProperty
      Height          =   255
      Left            =   1440
      TabIndex        =   13
      Top             =   3240
      Width           =   1695
   End
   Begin VB.Label Label5 
      Caption         =   "速度测试"
      BeginProperty Font 
         Name            =   "MS Sans Serif"
         Size            =   9.75
         Charset         =   0
         Weight          =   400
         Underline       =   0   'False
         Italic          =   0   'False
         Strikethrough   =   0   'False
      EndProperty
      Height          =   255
      Left            =   240
      TabIndex        =   12
      Top             =   3240
      Width           =   855
   End
   Begin VB.Label Label4 
      Alignment       =   1  'Right Justify
      Caption         =   "错误信息"
      BeginProperty Font 
         Name            =   "MS Sans Serif"
         Size            =   9.75
         Charset         =   0
         Weight          =   400
         Underline       =   0   'False
         Italic          =   0   'False
         Strikethrough   =   0   'False
      EndProperty
      Height          =   255
      Left            =   0
      TabIndex        =   10
      Top             =   2520
      Width           =   975
   End
   Begin VB.Label Label3 
      Alignment       =   1  'Right Justify
      Caption         =   "y="
      BeginProperty Font 
         Name            =   "MS Sans Serif"
         Size            =   9.75
         Charset         =   0
         Weight          =   400
         Underline       =   0   'False
         Italic          =   0   'False
         Strikethrough   =   0   'False
      EndProperty
      Height          =   255
      Left            =   120
      TabIndex        =   5
      Top             =   1440
      Width           =   255
   End
   Begin VB.Label Label2 
      Alignment       =   1  'Right Justify
      Caption         =   "x="
      BeginProperty Font 
         Name            =   "MS Sans Serif"
         Size            =   9.75
         Charset         =   0
         Weight          =   400
         Underline       =   0   'False
         Italic          =   0   'False
         Strikethrough   =   0   'False
      EndProperty
      Height          =   255
      Left            =   120
      TabIndex        =   4
      Top             =   1080
      Width           =   255
   End
   Begin VB.Label Label1 
      Alignment       =   1  'Right Justify
      Caption         =   "输入表达式 y=f(x)="
      BeginProperty Font 
         Name            =   "MS Sans Serif"
         Size            =   9.75
         Charset         =   0
         Weight          =   400
         Underline       =   0   'False
         Italic          =   0   'False
         Strikethrough   =   0   'False
      EndProperty
      Height          =   255
      Left            =   0
      TabIndex        =   1
      Top             =   120
      Width           =   1695
   End
End
Attribute VB_Name = "Form1"
Attribute VB_GlobalNameSpace = False
Attribute VB_Creatable = False
Attribute VB_PredeclaredId = True
Attribute VB_Exposed = False
'              &&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&
'                        NBLMaths Control
'                        NBL 数学计算控件
'                           使用范例
'                         作者 rickone
'              &&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&


'几个常用属性和方法
'1,MathsExpression 属性,类型:字符串
'设置原数学表达式,[格式]见帮助文件
'返回成功输入的数学表达式
'
'2,ErrorMessage 属性,类型:字符串
'返回表达式输入时或运算时的错误信息
'
'3,GetResult(X) 方法,类型:双精实型
'返回当自变量为X时的表达式值

Private Sub Command1_Click()
NBLMaths1.MathsExpression = Text1.Text  '输入数学表达式
If NBLMaths1.ErrorMessage = "" Then  '为""表示输入没有错误
    Text2.Text = NBLMaths1.MathsExpression   '输入后再输出的不同,运行后注意观察
    Text5.Text = ""
    'Text3.Text = ""
    'Text3.SetFocus
Else
    Text2.Text = ""
    Text5.Text = NBLMaths1.ErrorMessage '错误信息
End If
End Sub

Private Sub Command2_Click()
Dim X As Double
X = CDbl(Val(Text3.Text)) '强制转化成双精实型
Text4.Text = CStr(NBLMaths1.GetResult(X)) '得到运算结果
Text5.Text = NBLMaths1.ErrorMessage '看是否有运行时错误
End Sub

Private Sub Command3_Click()
Dim I As Long, t1, t2
NBLMaths1.MathsExpression = Text6.Text
If NBLMaths1.ErrorMessage = "" Then
    Text5.Text = ""
    t1 = Now
    For I = 1 To Val(Text7.Text)
        Call NBLMaths1.GetResult(CDbl(I)) '此时不改变原来表达式只改变X
    Next
    t2 = Now
    If t1 = t2 Then
        Text8.Text = "速度大于" & Val(Text7.Text) & "个/秒 为测试准确,请将[重复计数]增大"
    Else
        Text8.Text = "速度 " & Text7.Text / Second(t2 - t1) & "个/秒"
    End If
    Text6.SelStart = Len(Text6.Text)
    Text6.SelText = " = " & NBLMaths1.GetResult(0) & " While x=0"
Else
    Text5.Text = NBLMaths1.ErrorMessage
End If
End Sub

Private Sub Command4_Click()
Dim I As Long, t1, t2
NBLMaths1.MathsExpression = Text6.Text
If NBLMaths1.ErrorMessage = "" Then
    Text5.Text = ""
    t1 = Now
    For I = 1 To Val(Text7.Text)
        NBLMaths1.MathsExpression = Text6.Text '重新再输入表达式
        Call NBLMaths1.GetResult(0)
    Next
    t2 = Now
    If t1 = t2 Then
        Text8.Text = "速度大于" & Val(Text7.Text) & "个/秒 为测试准确,请将[重复计数]增大"
    Else
        Text8.Text = "速度 " & Text7.Text / Second(t2 - t1) & "个/秒"
    End If
    Text6.SelStart = Len(Text6.Text)
    Text6.SelText = " = " & NBLMaths1.GetResult(0) & " While x=0"
Else
    Text5.Text = NBLMaths1.ErrorMessage
End If
End Sub


Private Sub Text1_KeyPress(KeyAscii As Integer)
 If KeyAscii = 13 Then
  KeyAscii = 0
  Command1_Click
 End If
End Sub

⌨️ 快捷键说明

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