VB计算器(界面设计+ 全部代码) 下载本文

内容发布更新时间 : 2024/5/13 13:25:46星期一 下面是文章的全部内容请认真阅读。

VB计算器

此计算器能够实现加减乘除等一系列的功能。还有实现显示系统时间的附加功能。 截图如下:

程序设计:0-9 和点 在command1的组内。其他的按钮式运算符和其他功能。 正切和余切有对特殊值进行警告,除也有对除数为零的情况提示警告,还有阶乘等一系列计算溢出的情况提出警告,还有很多需要完善。。。这仅供参考。 Public sum As Double Public k As String

Public dian As Boolean Public b As Integer

Public pointflag As Boolean Dim clearFlag As Boolean Public F As Long 'Dim start As boolen

Public resl As Boolean '运算结果存储在resl里

Public ff As Double 'resl里是否为空

'////////////////////////////////////////////////////////数字按钮在一个组内,点击按钮输入数字///////////////////////////////////////////

Private Sub command1_click(Index As Integer) Select Case Index Case 1

If Not clearFlag Then '不是等号,那么显示1 Text1.Text = Text1.Text & 1

Else '是等号,那么清空 Text1.Text = 1 clearFlag = False End If

If Len(Text1.Text) = 2 And InStr(1, Text1, \

'如果第一位的数位0,字符串的长度为2.那么取字符串右面的数,即两个数中右面的数 Case 2

If Not clearFlag Then

Text1.Text = Text1.Text & 2 Else

Text1.Text = 2 clearFlag = False End If

If Len(Text1.Text) = 2 And InStr(1, Text1, \ Case 3

If Not clearFlag Then

Text1.Text = Text1.Text & 3 Else

Text1.Text = 3 clearFlag = False End If

If Len(Text1.Text) = 2 And InStr(1, Text1, \ Case 4

If Not clearFlag Then

Text1.Text = Text1.Text & 4 Else

Text1.Text = 4 clearFlag = False End If

If Len(Text1.Text) = 2 And InStr(1, Text1, \ Case 5

If Not clearFlag Then

Text1.Text = Text1.Text & 5 Else

Text1.Text = 5 clearFlag = False End If

If Len(Text1.Text) = 2 And InStr(1, Text1, \

Case 6

If Not clearFlag Then

Text1.Text = Text1.Text & 6 Else

Text1.Text = 6 clearFlag = False End If

If Len(Text1.Text) = 2 And InStr(1, Text1, \ Case 7

If Not clearFlag Then

Text1.Text = Text1.Text & 7 Else

Text1.Text = 7 clearFlag = False End If

If Len(Text1.Text) = 2 And InStr(1, Text1, \ Case 8

If Not clearFlag Then

Text1.Text = Text1.Text & 8 Else

Text1.Text = 8 clearFlag = False End If

If Len(Text1.Text) = 2 And InStr(1, Text1, \ Case 9

If Not clearFlag Then

Text1.Text = Text1.Text & 9 Else

Text1.Text = 9 clearFlag = False End If

If Len(Text1.Text) = 2 And InStr(1, Text1, \