| 网站首页 | 业界新闻 | 小组 | 威客 | 人才 | 下载频道 | 博客 | 代码贴 | 在线编程 | 编程论坛
欢迎加入我们,一同切磋技术
用户名:   
 
密 码:  
共有 1960 人关注过本帖
标题:用vb6制作数学计算器
只看楼主 加入收藏
JaneJackson
Rank: 1
等 级:新手上路
帖 子:8
专家分:0
注 册:2020-5-17
结帖率:66.67%
收藏
 问题点数:0 回复次数:1 
用vb6制作数学计算器
窗体:
图片附件: 游客没有浏览图片的权限,请 登录注册

代码:
Dim s1 As Single, s2 As Single, ysf As String
'定义两个单精度数变量用与存放参与运算的数,一个字符型存放运算符
Private Sub Command1_Click(Index As Integer)
Text1.Text = Text1.Text & Command1(Index).Caption
'将command1的单击事件与文本框显示的内容连接
End Sub

Private Sub Command10_Click()
End
End Sub

Private Sub Command11_Click()
Text1.Text = Sqr(Text1.Text)
If Text1.Text > 0 And Text1.Text < 1 Then
Text1 = IIf(Left(Text1.Text, 1) = ".", 0 & Text1.Text, Text1.Text)
End If
If Text1.Text > -1 And Text1.Text < 0 Then
Text1 = "-0" & (Text1.Text * -1)
End If
End Sub

Private Sub Command12_Click()
Text1.Text = Text1.Text ^ (1 / 3)
If Text1.Text > 0 And Text1.Text < 1 Then
Text1 = IIf(Left(Text1.Text, 1) = ".", 0 & Text1.Text, Text1.Text)
End If
If Text1.Text > -1 And Text1.Text < 0 Then
Text1 = "-0" & (Text1.Text * -1)
End If
End Sub

Private Sub Command2_Click()
Text1.Text = Text1.Text + "."
If (InStr(Text1.Text, ".") = 1) Then
'第一位不能为小数
Text1.Text = ""
End If
If InStr(Text1.Text, ".") < Len(Text1.Text) Then '防止出现两个小数点
Text1.Text = Left(Text1.Text, Len(Text1.Text) - 1)
End If
End Sub
Private Sub Command3_Click()
s2 = Val(Text1.Text) '开始加减乘除运算
Select Case ysf
Case "+"
Text1.Text = s1 + s2
Case "-"
Text1.Text = s1 - s2
Case "×"
Text1.Text = s1 * s2
Case "÷"
Text1.Text = s1 / s2
If s2 = 0 Then
MsgBox "分母不能为0!"
End If
End Select
If Text1.Text > 0 And Text1.Text < 1 Then
Text1 = IIf(Left(Text1.Text, 1) = ".", 0 & Text1.Text, Text1.Text)
End If
If Text1.Text > -1 And Text1.Text < 0 Then
Text1 = "-0" & (Text1.Text * -1)
End If
End Sub
Private Sub Command4_Click()
If Text1.Text = "" Then
Exit Sub
End If
Text1.Text = Left(Text1.Text, Len(Text1.Text) - 1)
End Sub
Private Sub Command5_Click()
Text1.Text = ""
End Sub
Private Sub Command6_Click(Index As Integer)
s1 = Val(Text1.Text)
ysf = Command6(Index).Caption
Text1.Text = ""
End Sub
Private Sub Command7_Click()
If Left(Text1.Text, 1) <> "-" Then
Text1.Text = "-" & Text1.Text
Else
Text1.Text = Right(Text1.Text, Len(Text1.Text) - 1)
End If
End Sub
Private Sub Command8_Click()
Text1.Text = Text1.Text * Text1.Text
If Text1.Text > 0 And Text1.Text < 1 Then
Text1 = IIf(Left(Text1.Text, 1) = ".", 0 & Text1.Text, Text1.Text)
End If
If Text1.Text > -1 And Text1.Text < 0 Then
Text1 = "-0" & (Text1.Text * -1)
End If
End Sub

Private Sub Command9_Click()
Text1.Text = Text1.Text * Text1.Text * Text1.Text
If Text1.Text > 0 And Text1.Text < 1 Then
Text1 = IIf(Left(Text1.Text, 1) = ".", 0 & Text1.Text, Text1.Text)
End If
If Text1.Text > -1 And Text1.Text < 0 Then
Text1 = "-0" & (Text1.Text * -1)
End If
End Sub

搜索更多相关主题的帖子: If Sub End Text Text1 
2020-05-30 15:28
JaneJackson
Rank: 1
等 级:新手上路
帖 子:8
专家分:0
注 册:2020-5-17
收藏
得分:0 
数学计算器.zip (142.61 KB)
2020-05-30 15:31
快速回复:用vb6制作数学计算器
数据加载中...
 
   



关于我们 | 广告合作 | 编程中国 | 清除Cookies | TOP | 手机版

编程中国 版权所有,并保留所有权利。
Powered by Discuz, Processed in 0.015418 second(s), 9 queries.
Copyright©2004-2024, BCCN.NET, All Rights Reserved