用VB编写简易计算器(带运行图) 下载本文

内容发布更新时间 : 2024/6/16 8:26:18星期一 下面是文章的全部内容请认真阅读。

简易计算器:

Option Explicit

Dim Flg As Boolean, Op As Integer, First As Single

Private Sub Command1_Click(Index As Integer) If Index = 10 Then

Text1.Text = Text1.Text & \ Else

Text1.Text = Text1.Text & CStr(Index) End If

If Len(Text1) = 2 And Left(Text1, 1) = \And Mid(Text1, 2, 1)<> \Then

Text1 = Mid(Text1, 2) End If End Sub

Private Sub Command2_Click(Index As Integer) First = Val(Text1.Text) Op = Index

Text1.Text = \

End Sub

Private Sub Command3_Click() Text1.Text = \ First = 0 End Sub

Private Sub Command4_Click() Dim Sec As Single

Sec = Val(Text1.Text) Select Case Op Case 0

Text1.Text = Str(First + Sec) Case 1

Text1.Text = Str(First - Sec) Case 2

Text1.Text = Str(First * Sec)

Case 3

If Sec <> 0 Then

Text1.Text = Str(First / Sec) Else

Text1.Text = \除数为0\ End If Case 4

If Sec <> 0 Then

Text1.Text = Str(First Mod Sec) Else

Text1.Text = \除数为0\ End If End Select End Sub

Private Sub Command5_Click() End End Sub

运行画面: