博山有什么特产送人啊:求vb编的计算器

来源:百度文库 编辑:查人人中国名人网 时间:2024/04/28 01:48:03
一个text框。数字1~9用控键数组。只要加减的。谢拉。。。。。。

我有个复杂点的要不要?

请看抓图:http://photo.ff88.com/upphoto/25020/2005F12F16819858321.jpg

自己做的,网上下载不到
如果需要的话,选我答案留下邮箱

1、建立14个按钮,按钮的名字都要Command1,设置Index属性,0~9分别对应数字0~9,10为小数点,11为等号,12~14分别对应+、-、*和/。
2、输入如下代码:
Dim Num1, Num2 As Single
Dim StrNum1, StrNum2 As String
Dim FirstNum As Boolean
Dim PointFlag As Boolean
Dim Runsign As Integer
Dim SignFlag As Boolean
Private Sub Command1_Click(Index As Integer)
Select Case Index
Case 0 To 9
If FirstNum Then
StrNum1 = Str(Index)
FirstNum = False
Else
StrNum1 = LTrim(StrNum1) + LTrim(Str(Index))
End If
Text1.Text = Val(StrNum1)
Case 10
If Not PointFlag Then
If FirstNum Then
StrNum1 = "0."
FirstNum = False
Else
StrNum1 = LTrim(StrNum1) + LTrim(".")
End If
Else
Exit Sub
End If
PointFlag = True
Text1.Text = Val(StrNum1)
Case 12 To 15
FirstNum = True
PointFlag = False
If SignFlag Then
Call Run
Else
SignFlag = True
StrNum2 = StrNum1
StrNum1 = ""
End If
Runsign = Index - 11
Case 11
On Error Resume Next
If Not SignFlag Then
Text1.Text = StrNum1
equal = Val(StrNum1)
FirstNum = True
PointFlag = False
Else
Call Run
SignFlag = False
End If
Case Else
Call ClearData
End Select
End Sub
Private Sub Form_Load()
If App.PrevInstance Then MsgBox "请不要多次运行此程序,谢谢!", vbAbortRetryIgnore: Unload Me
Num1 = 0
Num2 = 0
StrNum1 = ""
StrNum2 = ""
FirstNum = True
PointFlag = False
Runsign = 0
SignFlag = False
End Sub
Sub Run()
On Error Resume Next
Dim equal As Single
Dim equal2 As Double
Num1 = Val(StrNum2)
Num2 = Val(StrNum1)
Select Case Runsign
Case 1
equal = Num1 + Num2
If Num1 >= 65536 Or Num2 >= 65536 Or equal >= 65536 Then
equal = 0
equal2 = Num1 + Num2
End If
Case 2
equal = Num1 - Num2
If Num1 >= 65536 Or Num2 >= 65536 Or equal >= 65536 Then
equal = 0
equal2 = Num1 - Num2
End If
Case 3
equal = Num1 * Num2
If Num1 >= 65536 Or Num2 >= 65536 Or equal >= 65536 Then
equal = 0
equal2 = Num1 * Num2
End If
Case 4
equal = Num1 / Num2
If Num1 >= 65536 Or Num2 >= 65536 Or equal >= 65536 Then
equal = 0
equal2 = Num1 / Num2
End If
End Select
If equal = 0 Then a = equal2 Else a = equal
StrNum2 = Str(a)
StrNum1 = StrNum2
Text1.Text = Val(StrNum2)
End Sub
Sub ClearData()
Num1 = 0
Num2 = 0
StrNum1 = ""
StrNum2 = ""
FirstNum = True
PointFlag = False
Runsign = 0
SignFlag = False
Text1.Text = 0
End Sub

程序运行效果如下图所示,完整程序下载:Calc.zip。

一个所有的计算都有的行不行?Dim pi As Double '用于传递pi
Dim X As Integer '用于记忆小数点有多少个
Dim Y As Single '定义一个数用于进行运算
Dim c As Integer '判断是+-*/等中的哪一个
Dim z As Single '用于三角函数及四则运算或两元运算
Private Sub Cmd1_Click(Index As Integer) '数字键盘,设的X是判断小数点的变量
Select Case Index
Case 1
If InStr(Text1.Text, ".") = 0 Then
Text1.Text = Text1.Text + "."
End If
Case Is <> 1
Text1.Text = Text1.Text & Cmd1(Index).Caption
End Select
End Sub

Private Sub Cmd2_Click(Index As Integer) '清除上次输入的数字,显示pi,相反数
Select Case Index
Case 0
Text1.Text = 4 * Atn(1)
Case 1
Text1.Text = -Val(Text1.Text)
Case 2
If Right(Text1.Text, 1) = "." Then
X = 1
End If
Text1.Text = Left(Text1.Text, Len(Text1.Text) - 1)

End Select

End Sub

Private Sub Cmd3_Click(Index As Integer) '计算三角函数
u = Val(Text1.Text)
xp = u * pi / 180
Select Case Index
Case 0
u = Sin(xp)
Case 1
u = Cos(xp)
Case 2
If u Mod 180 <> 90 Then 'u Mod 90 = 0 And u Mod 180 <> 0
u = "ERROR!"
Else
u = Tan(xp)
End If
Case 3
u = Atn(u) * 180 / pi
End Select
Text1.Text = Format(u, "0.0000000000")
End Sub

Private Sub Cmd4_Click(Index As Integer) '进行四则运算
Y = Text1.Text
X = 1
Text1.Text = ""
Select Case Index
Case 0
c = 1
Case 1
c = 2
Case 2
c = 3
Case 3
c = 4
End Select
End Sub

Private Sub Cmd5_Click(Index As Integer) '关闭或清零或时间及日期
Select Case Index
Case 0
z = Text1.Text
Select Case c
Case 1
Y = Y + z
If Y > Int(Y) Then
Text1.Text = Format(Y, "0.0000000")
Else
Text1.Text = Y
End If
Case 2
Y = Y - z
If Y > Int(Y) Then
Text1.Text = Format(Y, "0.0000000")
Else
Text1.Text = Y
End If
Case 3
If z = 0 Then
MsgBox "除数不能为零,请输入一个大于零的数!"
Text1.Text = ""
Else
Text1.Text = Format(Y / z, "#0.000000")
End If
Case 4
Y = Y * z
If Y > Int(Y) Then
Text1.Text = Format(Y, "0.0000000")
Else
Text1.Text = Y
End If
Case 5
Y = Y ^ z
Text1.Text = Y
Case 6
Y = Log(Y) / Log(z)
Text1.Text = Y
Case 7 '显示随机数
If Y > z Then
Y = Rnd * (Y - z + 1) + z
Else
Y = Rnd * (z - Y + 1) + Y
End If
Text1.Text = Y
End Select
Case 1
Text1.Text = ""
X = 1
Case 2
Unload Me
Case 3
'Text2.Text = Time
If Cmd5(3).Caption = "TIME" Then
Timer1.Enabled = False
Cmd5(3).Caption = "DATE"
Text2.Text = Date
Else
Timer1.Enabled = True
Cmd5(3).Caption = "TIME"

End If
End Select
End Sub

Private Sub Cmd6_Click(Index As Integer)
z = Text1.Text
Select Case Index
Case 0
Text1.Text = Format(z ^ 2, "0.0000000")
Case 1
Text1.Text = Format(z ^ 3, "0.0000000")
Case 2
If z < 0 Then
MsgBox "请输入一个大于或等于零的数!"
Else
Text1.Text = Format(Sqr(z), "0.0000000")
End If
Case 3
Text1.Text = Format(1 / z, "0.0000000")
End Select
End Sub

Private Sub Cmd7_Click(Index As Integer)
Y = Text1.Text
X = 1
Text1.Text = ""
Select Case Index
Case 0
c = 5
Case 1
c = 6
Case 2
c = 7
Case 3
a = 1
For i = 1 To Y
a = a * i
Next
Text1.Text = a
End Select
End Sub

Private Sub Form_Load() '装载控件及数组
X = 1
pi = 4 * Atn(1)
Text1.Text = ""
j = 0
For i = 1 To 10 '显示数字键盘
Load Cmd1(i)
If i = 1 Then
Cmd1(1).Top = Cmd1(0).Top
Cmd1(1).Left = Cmd1(0).Left + Cmd1(0).Width * 2
Else
If (i - 2) Mod 3 = 0 Then
Cmd1(i).Left = Cmd1(0).Left
Cmd1(i).Top = Cmd1(i - 1).Top - Cmd1(i - 1).Width
Else
Cmd1(i).Left = Cmd1(i - 1).Left + Cmd1(i - 1).Width
Cmd1(i).Top = Cmd1(i - 1).Top
End If

End If
Cmd1(i).Visible = True
Next
For i = 0 To 10
If i = 0 Then
Cmd1(0).Width = 2 * Cmd1(0).Width
End If
If i <> 1 Then
Cmd1(i).Caption = j
j = j + 1
Else
Cmd1(i).Caption = "."
End If
Next
For i = 1 To 2 '显示pi,相反数,清除上次输入的数
Load Cmd2(i)
Cmd2(i).Top = Cmd2(0).Top
Cmd2(i).Left = Cmd2(i - 1).Left + Cmd2(0).Width + 80
Cmd2(i).Visible = True
Next
For i = 0 To 2
Cmd2(0).Caption = "π"
Cmd2(1).Caption = "+/-"
Cmd2(2).Caption = "<--"
Next
For i = 1 To 3 '显示三角函数
Load Cmd3(i)
Cmd3(i).Left = Cmd3(0).Left
Cmd3(i).Top = Cmd3(i - 1).Top + Cmd3(i - 1).Height + 80
Cmd3(i).Visible = True
Next
For i = 0 To 3
Cmd3(i).Caption = Mid("SinCosTanAtn", (i * 3) + 1, 3)
Next
For i = 1 To 3 '显示四则运算符
Load Cmd4(i)
Cmd4(i).Left = Cmd4(0).Left
Cmd4(i).Top = Cmd4(i - 1).Top + Cmd4(i - 1).Height + 80
Cmd4(i).Visible = True
Next
For i = 0 To 3
Cmd4(i).Caption = Mid("+-÷×", i + 1, 1)
Next
For i = 1 To 3 '显示清除等
Load Cmd5(i)
Cmd5(i).Left = Cmd5(i - 1).Left + Cmd5(0).Width + 80
Cmd5(i).Top = Cmd5(0).Top
Cmd5(i).Visible = True
Next
Cmd5(0).Caption = "="
Cmd5(1).Caption = "ON"
Cmd5(2).Caption = "OFF"
Cmd5(3).Caption = "TIME"
For i = 1 To 3 '显示幂函数
Load Cmd6(i)
Cmd6(i).Left = Cmd6(0).Left
Cmd6(i).Top = Cmd6(i - 1).Top + Cmd6(i - 1).Height + 80
Cmd6(i).Visible = True
Next
For i = 0 To 3
Cmd6(i).Caption = Mid("x^2x^3sqr1/x", (i * 3) + 1, 3)
Next
For i = 1 To 3 '显示指数函数
Load Cmd7(i)
Cmd7(i).Left = Cmd7(0).Left
Cmd7(i).Top = Cmd7(i - 1).Top + Cmd7(i - 1).Height + 80
Cmd7(i).Visible = True
Next
For i = 0 To 3
If i <> 3 Then
Cmd7(i).Caption = Mid("X^YLOGRND", (i * 3) + 1, 3)
Else
Cmd7(i).Caption = "N!"
End If
Next
End Sub

Private Sub Timer1_Timer()
Text2.Text = "现在是" & Time
End Sub

临时编的

Dim strA As String
Dim strB As String
Dim dec1stNumber As Decimal
Dim dec2ndNumber As Decimal
Dim decResult As Decimal
Dim strOpration As String

Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
strB = "0"
lbl1.Text = strB
strA = lbl1.Text
End Sub

Private Sub btn1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btn1.Click
If strB = "0" Then
strB = btn1.Text
Else
Try
strB = strA & btn1.Text
Catch
End Try
End If
lbl1.Text = strB
strA = lbl1.Text
End Sub

Private Sub btn2_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles btn2.Click
If strB = "0" Then
strB = btn2.Text
Else
Try
strB = strA & btn2.Text
Catch
End Try
End If
lbl1.Text = strB
strA = lbl1.Text
End Sub

Private Sub btnPoint_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles btnPoint.Click
Try
strB = strA & btnPoint.Text
Catch
End Try
lbl1.Text = strB
strA = lbl1.Text
btnPoint.Enabled = False
End Sub

Private Sub btnAdd_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles btnAdd.Click
dec1stNumber = CType(strA, Decimal)
strB = "0"
strOpration = "+"
btnPoint.Enabled = True
End Sub

Private Sub btnDivide_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles btnDevide.Click
dec1stNumber = CType(strA, Decimal)
strB = "0"
strOpration = "/"
btnPoint.Enabled = True
End Sub

Private Sub btnMinus_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles btnMinus.Click
dec1stNumber = CType(strA, Decimal)
strB = "0"
strOpration = "-"
btnPoint.Enabled = True
End Sub

Private Sub btnTime_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles btnTime.Click
dec1stNumber = CType(strA, Decimal)
strB = "0"
strOpration = "*"
btnPoint.Enabled = True
End Sub

Private Sub btnEqual_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles btnEque.Click
dec2ndNumber = CType(strA, Decimal)
Select Case strOpration
Case Is = "+"
decResult = dec1stNumber + dec2ndNumber
Case Is = "-"
decResult = dec1stNumber - dec2ndNumber
Case Is = "/"
decResult = dec1stNumber / dec2ndNumber
Case Is = "*"
decResult = dec1stNumber * dec2ndNumber
End Select
lbl1.Text = decResult
strA = lbl1.Text
If decResult < 0 Then
btnPoint.Enabled = False
End If
End Sub

这是我上学期的作业,我发你邮箱里吧.你再加点分好么~