阴阳师晴明式神是谁:用vb怎么做一个计算器?

来源:百度文库 编辑:高考问答 时间:2024/05/03 07:36:29
代码怎么写啊?

Option Explicit
Dim str1 As String, str2 As String
Dim strtemp As String
Dim sum As Double
Dim d1 As Double, d2 As Double
Dim b As Boolean
Dim i As Integer

Private Sub cmdback_Click()
Command4.SetFocus
If b = False Then strtemp = str1 Else strtemp = str2
If Len(strtemp) > 0 Then
strtemp = Left(strtemp, Len(strtemp) - 1)
If strtemp = "" Then Text1.Text = "0" Else Text1.Text = strtemp
ElseIf strtemp = "" Then
Text1.Text = "0"
End If
If b = False Then str1 = strtemp Else str2 = strtemp
End Sub

Private Sub cmdpn_Click()
Command4.SetFocus
If b = False Then strtemp = str1 Else strtemp = str2
If Len(strtemp) > 0 And Left(strtemp, 1) = "-" Then
strtemp = Right(strtemp, Len(strtemp) - 1)
Else
strtemp = "-" & strtemp
End If
Text1.Text = strtemp
If b = False Then str1 = strtemp Else str2 = strtemp
End Sub

Private Sub Command1_Click(Index As Integer)
Command4.SetFocus
If b = False Then strtemp = str1 Else strtemp = str2
If Index < 10 Then
strtemp = strtemp + CStr(Index)
Else
If InStr(strtemp, ".") = 0 Then strtemp = strtemp + "."
End If
If Len(strtemp) > 1 And Left(strtemp, 1) = "0" And Mid(strtemp, 2, 1) <> "." Then
strtemp = Right(strtemp, Len(strtemp) - 1)
End If
Text1.Text = strtemp
If b = False Then str1 = strtemp Else str2 = strtemp
End Sub

Private Sub Command2_Click(Index As Integer)
Command4.SetFocus
If Len(Trim(str1)) <> 0 And Len(Trim(str2)) <> 0 Then
d1 = Val(str1)
d2 = Val(str2)
Select Case i
Case 0
d1 = d1 + d2
Case 1
d1 = d1 - d2
Case 2
d1 = d1 * d2
Case 3
If d2 = 0 Then
MsgBox "除数不能为0!", 16, "错误"
Exit Sub
End If
d1 = d1 / d2
End Select
str1 = CStr(d1)
str2 = ""
Text1.Text = str1
b = True
i = Index
Exit Sub
End If
str2 = ""
If str1 = "" Then str1 = Str(d1)
Text1.Text = str1
b = True
i = Index
End Sub

Private Sub Command3_Click()
Command4.SetFocus
str1 = ""
str2 = ""
Text1.Text = "0"
b = False
d1 = 0
End Sub

Private Sub Command4_Click()
If Len(Trim(str1)) = 0 Or Len(Trim(str2)) = 0 Then
b = False
Exit Sub
End If

d1 = Val(str1)
d2 = Val(str2)
Select Case i
Case 0
d1 = d1 + d2
Case 1
d1 = d1 - d2
Case 2
d1 = d1 * d2
Case 3
If d2 = 0 Then
MsgBox "除数不能为0!", 16, "错误"
Exit Sub
End If
d1 = d1 / d2
End Select
str1 = CStr(d1)
Text1.Text = str1
b = False
str2 = ""
End Sub

Private Sub Form_KeyPress(KeyAscii As Integer)
Command4.SetFocus
Dim s As Integer, f As Integer
If (KeyAscii >= 48 And KeyAscii <= 57) Or KeyAscii = 46 Then

Select Case KeyAscii
Case 48
s = 0
Case 49
s = 1
Case 50
s = 2
Case 51
s = 3
Case 52
s = 4
Case 53
s = 5
Case 54
s = 6
Case 55
s = 7
Case 56
s = 8
Case 57
s = 9
Case 46
s = 10
End Select
Call Command1_Click(s)
ElseIf KeyAscii = 42 Or KeyAscii = 43 Or KeyAscii = 45 Or KeyAscii = 47 Then
Select Case KeyAscii
Case 42
f = 2
Case 43
f = 0
Case 45
f = 1
Case 47
f = 3
End Select
Call Command2_Click(f)
ElseIf KeyAscii = 13 Or KeyAscii = 61 Then
Call Command4_Click
ElseIf KeyAscii = 32 Or KeyAscii = 82 Or KeyAscii = 114 Then
Call Command3_Click
ElseIf KeyAscii = 67 Or KeyAscii = 99 Then
Call cmdback_Click
Else
KeyAscii = 0
End If
End Sub

Private Sub Label1_Click()
frmAbout.Show
End Sub

这个东西不是一句两句话说的清楚的

这个简单了
画几个控件
写几个语句就行

用一个累加器