使用VB编写一个简单的计算器,在线等
界面如下第一步:输入89第二步:输入-第三步:输入43第四步:输入=,显示结果希望可以详细说一下那个界面按钮的设计...
界面如下
第一步:输入89
第二步:输入-
第三步:输入43
第四步:输入=,显示结果
希望可以详细说一下那个界面按钮的设计 展开
第一步:输入89
第二步:输入-
第三步:输入43
第四步:输入=,显示结果
希望可以详细说一下那个界面按钮的设计 展开
2个回答
展开全部
VERSION 5.00
Begin VB.Form Form1
BorderStyle = 1 'Fixed Single
Caption = "简易计算器 V1.0"
ClientHeight = 3825
ClientLeft = 45
ClientTop = 375
ClientWidth = 4440
LinkTopic = "Form1"
MaxButton = 0 'False
MinButton = 0 'False
ScaleHeight = 3825
ScaleWidth = 4440
StartUpPosition = 3 '窗口缺省
Begin VB.Frame Frame1
Height = 3735
Left = 120
TabIndex = 0
Top = 0
Width = 4215
Begin VB.CommandButton cmdOperator
Caption = "X"
Height = 495
Index = 3
Left = 1680
TabIndex = 16
Top = 2880
Width = 615
End
Begin VB.CommandButton cmdClearEntry
Caption = "C"
Height = 495
Left = 3120
TabIndex = 15
Top = 2880
Width = 615
End
Begin VB.CommandButton cmdNumber
Caption = "4"
Height = 495
Index = 4
Left = 2400
TabIndex = 14
Top = 1200
Width = 615
End
Begin VB.CommandButton cmdNumber
Caption = "5"
Height = 495
Index = 5
Left = 3120
TabIndex = 13
Top = 1200
Width = 615
End
Begin VB.CommandButton cmdNumber
Caption = "6"
Height = 495
Index = 6
Left = 240
TabIndex = 12
Top = 2040
Width = 615
End
Begin VB.CommandButton cmdNumber
Caption = "7"
Height = 495
Index = 7
Left = 960
TabIndex = 11
Top = 2040
Width = 615
End
Begin VB.CommandButton cmdNumber
Caption = "8"
Height = 495
Index = 8
Left = 1680
TabIndex = 10
Top = 2040
Width = 615
End
Begin VB.CommandButton cmdNumber
Caption = "9"
Height = 495
Index = 9
Left = 2400
TabIndex = 9
Top = 2040
Width = 615
End
Begin VB.CommandButton cmdNumber
Caption = "0"
Height = 495
Index = 0
Left = 3120
TabIndex = 8
Top = 2040
Width = 615
End
Begin VB.CommandButton cmdOperator
Caption = "-"
Height = 495
Index = 2
Left = 960
TabIndex = 7
Top = 2880
Width = 615
End
Begin VB.CommandButton cmdEquals
Caption = "="
Height = 495
Left = 2400
TabIndex = 6
Top = 2880
Width = 615
End
Begin VB.CommandButton cmdNumber
Caption = "1"
Height = 495
Index = 1
Left = 240
TabIndex = 5
Top = 1200
Width = 615
End
Begin VB.CommandButton cmdNumber
Caption = "2"
Height = 495
Index = 2
Left = 960
TabIndex = 4
Top = 1200
Width = 615
End
Begin VB.CommandButton cmdNumber
Caption = "3"
Height = 495
Index = 3
Left = 1680
TabIndex = 3
Top = 1200
Width = 615
End
Begin VB.CommandButton cmdOperator
Caption = "+"
Height = 495
Index = 1
Left = 240
TabIndex = 2
Top = 2880
Width = 615
End
Begin VB.TextBox txtDisplay
Alignment = 1 'Right Justify
BackColor = &H00C0E0FF&
BeginProperty Font
Name = "宋体"
Size = 14.25
Charset = 0
Weight = 700
Underline = 0 'False
Italic = 0 'False
Strikethrough = 0 'False
EndProperty
Height = 495
Left = 360
TabIndex = 1
Top = 480
Width = 3375
End
End
End
Attribute VB_Name = "Form1"
Attribute VB_GlobalNameSpace = False
Attribute VB_Creatable = False
Attribute VB_PredeclaredId = True
Attribute VB_Exposed = False
Option Explicit
Private StoredValue As Double
Private Const opNone = 0
Private Const opAdd = 1
Private Const opSubtract = 2
Private Const opMultiply = 3
Private Const opDivide = 4
Private Operator As Integer
Private NewEntry As Boolean
'清除显示内容,保存运算符
Private Sub cmdClearEntry_Click()
txtDisplay.Text = ""
StoredValue = 0
Operator = opNone
txtDisplay.SetFocus
End Sub
'计算上一操作符的运算结果
Private Sub cmdEquals_Click()
Dim new_value As Double
If txtDisplay.Text = "" Then
new_value = 0
Else
new_value = CDbl(txtDisplay.Text)
End If
Select Case Operator
Case opNone
StoredValue = new_value
Case opAdd
StoredValue = StoredValue + new_value
Case opSubtract
StoredValue = StoredValue - new_value
Case opMultiply
StoredValue = StoredValue * new_value
Case opDivide
StoredValue = StoredValue / new_value
End Select
Operator = opNone
NewEntry = True
txtDisplay.Text = Format$(StoredValue)
txtDisplay.SetFocus
End Sub
' 显示数字
Private Sub cmdNumber_Click(Index As Integer)
If NewEntry Then
txtDisplay.Text = Format$(Index)
NewEntry = False
Else
txtDisplay.Text = txtDisplay.Text & Format$(Index)
End If
txtDisplay.SetFocus
End Sub
Private Sub cmdOperator_Click(Index As Integer)
cmdEquals_Click
Operator = Index
NewEntry = True
txtDisplay.SetFocus
End Sub
Private Sub txtDisplay_Change()
txtDisplay.SelStart = Len(txtDisplay.Text)
End Sub
Private Sub txtDisplay_GotFocus()
txtDisplay_Change
End Sub
Begin VB.Form Form1
BorderStyle = 1 'Fixed Single
Caption = "简易计算器 V1.0"
ClientHeight = 3825
ClientLeft = 45
ClientTop = 375
ClientWidth = 4440
LinkTopic = "Form1"
MaxButton = 0 'False
MinButton = 0 'False
ScaleHeight = 3825
ScaleWidth = 4440
StartUpPosition = 3 '窗口缺省
Begin VB.Frame Frame1
Height = 3735
Left = 120
TabIndex = 0
Top = 0
Width = 4215
Begin VB.CommandButton cmdOperator
Caption = "X"
Height = 495
Index = 3
Left = 1680
TabIndex = 16
Top = 2880
Width = 615
End
Begin VB.CommandButton cmdClearEntry
Caption = "C"
Height = 495
Left = 3120
TabIndex = 15
Top = 2880
Width = 615
End
Begin VB.CommandButton cmdNumber
Caption = "4"
Height = 495
Index = 4
Left = 2400
TabIndex = 14
Top = 1200
Width = 615
End
Begin VB.CommandButton cmdNumber
Caption = "5"
Height = 495
Index = 5
Left = 3120
TabIndex = 13
Top = 1200
Width = 615
End
Begin VB.CommandButton cmdNumber
Caption = "6"
Height = 495
Index = 6
Left = 240
TabIndex = 12
Top = 2040
Width = 615
End
Begin VB.CommandButton cmdNumber
Caption = "7"
Height = 495
Index = 7
Left = 960
TabIndex = 11
Top = 2040
Width = 615
End
Begin VB.CommandButton cmdNumber
Caption = "8"
Height = 495
Index = 8
Left = 1680
TabIndex = 10
Top = 2040
Width = 615
End
Begin VB.CommandButton cmdNumber
Caption = "9"
Height = 495
Index = 9
Left = 2400
TabIndex = 9
Top = 2040
Width = 615
End
Begin VB.CommandButton cmdNumber
Caption = "0"
Height = 495
Index = 0
Left = 3120
TabIndex = 8
Top = 2040
Width = 615
End
Begin VB.CommandButton cmdOperator
Caption = "-"
Height = 495
Index = 2
Left = 960
TabIndex = 7
Top = 2880
Width = 615
End
Begin VB.CommandButton cmdEquals
Caption = "="
Height = 495
Left = 2400
TabIndex = 6
Top = 2880
Width = 615
End
Begin VB.CommandButton cmdNumber
Caption = "1"
Height = 495
Index = 1
Left = 240
TabIndex = 5
Top = 1200
Width = 615
End
Begin VB.CommandButton cmdNumber
Caption = "2"
Height = 495
Index = 2
Left = 960
TabIndex = 4
Top = 1200
Width = 615
End
Begin VB.CommandButton cmdNumber
Caption = "3"
Height = 495
Index = 3
Left = 1680
TabIndex = 3
Top = 1200
Width = 615
End
Begin VB.CommandButton cmdOperator
Caption = "+"
Height = 495
Index = 1
Left = 240
TabIndex = 2
Top = 2880
Width = 615
End
Begin VB.TextBox txtDisplay
Alignment = 1 'Right Justify
BackColor = &H00C0E0FF&
BeginProperty Font
Name = "宋体"
Size = 14.25
Charset = 0
Weight = 700
Underline = 0 'False
Italic = 0 'False
Strikethrough = 0 'False
EndProperty
Height = 495
Left = 360
TabIndex = 1
Top = 480
Width = 3375
End
End
End
Attribute VB_Name = "Form1"
Attribute VB_GlobalNameSpace = False
Attribute VB_Creatable = False
Attribute VB_PredeclaredId = True
Attribute VB_Exposed = False
Option Explicit
Private StoredValue As Double
Private Const opNone = 0
Private Const opAdd = 1
Private Const opSubtract = 2
Private Const opMultiply = 3
Private Const opDivide = 4
Private Operator As Integer
Private NewEntry As Boolean
'清除显示内容,保存运算符
Private Sub cmdClearEntry_Click()
txtDisplay.Text = ""
StoredValue = 0
Operator = opNone
txtDisplay.SetFocus
End Sub
'计算上一操作符的运算结果
Private Sub cmdEquals_Click()
Dim new_value As Double
If txtDisplay.Text = "" Then
new_value = 0
Else
new_value = CDbl(txtDisplay.Text)
End If
Select Case Operator
Case opNone
StoredValue = new_value
Case opAdd
StoredValue = StoredValue + new_value
Case opSubtract
StoredValue = StoredValue - new_value
Case opMultiply
StoredValue = StoredValue * new_value
Case opDivide
StoredValue = StoredValue / new_value
End Select
Operator = opNone
NewEntry = True
txtDisplay.Text = Format$(StoredValue)
txtDisplay.SetFocus
End Sub
' 显示数字
Private Sub cmdNumber_Click(Index As Integer)
If NewEntry Then
txtDisplay.Text = Format$(Index)
NewEntry = False
Else
txtDisplay.Text = txtDisplay.Text & Format$(Index)
End If
txtDisplay.SetFocus
End Sub
Private Sub cmdOperator_Click(Index As Integer)
cmdEquals_Click
Operator = Index
NewEntry = True
txtDisplay.SetFocus
End Sub
Private Sub txtDisplay_Change()
txtDisplay.SelStart = Len(txtDisplay.Text)
End Sub
Private Sub txtDisplay_GotFocus()
txtDisplay_Change
End Sub
来自:求助得到的回答
本回答被提问者和网友采纳
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
展开全部
留下邮箱,我传你一段完整的程序
追问
974620344@qq.com
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询