用VB程序设计一个简单计算器
2013-06-06
展开全部
首先建立一个command1 然后剪切复制 系统提示说已经有一个COMMAND1 是否要建立控件数组?
你点击是 这样重复9次 分别把caption该成0到9 然后建立command2 方法同上,caption为 +-*/ 然后是 command3 caption是=
然后输入代码,首先在通用里生命dim shu1,shu2
dim suanfu as string
private sub command1(index)_click
text1.text=text1.text & commmand1(index).capton
end sub
command2里 输入
shu1=text1.text
suanfu=text1.text & command(index).capiton
text1.text=""
end sub
command3里输入
shu2=text1.text
selece case suanfu
case "+"
text1.text=shu1+shu2
case "-"
text1.text=shu1-shu2
case "*"
text1.text=shu*shu2
case "/"
if shu2=0 then
msgbox "分母不能为0"
else text1.text=shu1/shu2
end if
end select
end sub
你点击是 这样重复9次 分别把caption该成0到9 然后建立command2 方法同上,caption为 +-*/ 然后是 command3 caption是=
然后输入代码,首先在通用里生命dim shu1,shu2
dim suanfu as string
private sub command1(index)_click
text1.text=text1.text & commmand1(index).capton
end sub
command2里 输入
shu1=text1.text
suanfu=text1.text & command(index).capiton
text1.text=""
end sub
command3里输入
shu2=text1.text
selece case suanfu
case "+"
text1.text=shu1+shu2
case "-"
text1.text=shu1-shu2
case "*"
text1.text=shu*shu2
case "/"
if shu2=0 then
msgbox "分母不能为0"
else text1.text=shu1/shu2
end if
end select
end sub
AiPPT
2024-09-19 广告
2024-09-19 广告
随着AI技术的飞速发展,如今市面上涌现了许多实用易操作的AI生成工具1、简介:AiPPT: 这款AI工具智能理解用户输入的主题,提供“AI智能生成”和“导入本地大纲”的选项,生成的PPT内容丰富多样,可自由编辑和添加元素,图表类型包括柱状图...
点击进入详情页
本回答由AiPPT提供
2013-06-06
展开全部
界面:
text1
1 2 3 +
4 5 6 -
7 8 9 *
0 = AC /
代码:
dim newnum as boolean
dim n1,n2 op as integer
private sub ac_click()
text1.text=""
end sub
private sub command1_click(index as integer)
if newnum=true then text1=""
text1=text1&index
newnum=false
end sub
private sub command1_click(index as integer)
if op=0 then
n1=val(text1)
else
n2=val(text1)
select case op
case 1
text1=n1+n2
case 2
text1=n1-n2
case 3
text1=n1*n2
case 4
if n2<>0 then text1=n1/n2
end select
op=0
end if
if index>0 then op=index
n1=val(text1)
newnum=true
end sub
text1
1 2 3 +
4 5 6 -
7 8 9 *
0 = AC /
代码:
dim newnum as boolean
dim n1,n2 op as integer
private sub ac_click()
text1.text=""
end sub
private sub command1_click(index as integer)
if newnum=true then text1=""
text1=text1&index
newnum=false
end sub
private sub command1_click(index as integer)
if op=0 then
n1=val(text1)
else
n2=val(text1)
select case op
case 1
text1=n1+n2
case 2
text1=n1-n2
case 3
text1=n1*n2
case 4
if n2<>0 then text1=n1/n2
end select
op=0
end if
if index>0 then op=index
n1=val(text1)
newnum=true
end sub
本回答被网友采纳
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
2013-06-06
展开全部
布局如下Option Explicit
Dim sum1, sum2, f, n, dianPrivate Sub Command1_Click(Index As Integer)
Label1.Caption = Label1.Caption & Index
Picture1.SetFocus
End SubPrivate Sub Command11_Click(Index As Integer)
sum1 = Val(Label1.Caption)
Label1.Caption = ""
dian = 0
f = Index
Picture1.SetFocus
End SubPrivate Sub Command15_Click()
sum2 = Val(Label1.Caption)
Select Case f
Case 0
Label1.Caption = sum1 + sum2
Case 1
Label1.Caption = sum1 - sum2
Case 2
Label1.Caption = sum1 * sum2
Case Else
Label1.Caption = sum1 / sum2
End Select
Picture1.SetFocus
End SubPrivate Sub Command16_Click()
Label1.Caption = ""
Picture1.SetFocus
End SubPrivate Sub Command17_Click()
sum1 = 0
sum2 = 0
Label1.Caption = ""
Picture1.SetFocus
End SubPrivate Sub Command2_Click()
If Label1.Caption <> "" Then
Label1.Caption = Left(Label1.Caption, Len(Label1.Caption) - 1)
End If
Picture1.SetFocus
End SubPrivate Sub Command3_Click(Index As Integer)
Dim a, b
n = Index
Select Case n
Case 0
a = ""
Text1.Visible = False
Case 1
Label1.Caption = a
Case 2
a = Val(Label1.Caption)
Text1.Visible = True
Case 3
a = a + Val(Label1.Caption)
Text1.Visible = True
End Select
Picture1.SetFocus
End SubPrivate Sub Command4_Click()
Label1.Caption = Not Label1.Caption - 1
Picture1.SetFocus
End SubPrivate Sub Command6_Click()
Label1.Caption = spr(Label1.Caption)
Picture1.SetFocus
End SubPrivate Sub Command7_Click()
Label1.Caption = Val(Label1.Caption) / 100
Picture1.SetFocus
End SubPrivate Sub Command8_Click()
Label1.Caption = 1 / Val(Label1.Caption)
Picture1.SetFocus
End SubPrivate Sub Command9_Click()
If dian < 1 Then
Label1.Caption = Label1.Caption & "."
dian = dian + 1
End If
Picture1.SetFocus
End SubPrivate Sub Form_Activate()
Picture1.SetFocus
End Sub
Dim sum1, sum2, f, n, dianPrivate Sub Command1_Click(Index As Integer)
Label1.Caption = Label1.Caption & Index
Picture1.SetFocus
End SubPrivate Sub Command11_Click(Index As Integer)
sum1 = Val(Label1.Caption)
Label1.Caption = ""
dian = 0
f = Index
Picture1.SetFocus
End SubPrivate Sub Command15_Click()
sum2 = Val(Label1.Caption)
Select Case f
Case 0
Label1.Caption = sum1 + sum2
Case 1
Label1.Caption = sum1 - sum2
Case 2
Label1.Caption = sum1 * sum2
Case Else
Label1.Caption = sum1 / sum2
End Select
Picture1.SetFocus
End SubPrivate Sub Command16_Click()
Label1.Caption = ""
Picture1.SetFocus
End SubPrivate Sub Command17_Click()
sum1 = 0
sum2 = 0
Label1.Caption = ""
Picture1.SetFocus
End SubPrivate Sub Command2_Click()
If Label1.Caption <> "" Then
Label1.Caption = Left(Label1.Caption, Len(Label1.Caption) - 1)
End If
Picture1.SetFocus
End SubPrivate Sub Command3_Click(Index As Integer)
Dim a, b
n = Index
Select Case n
Case 0
a = ""
Text1.Visible = False
Case 1
Label1.Caption = a
Case 2
a = Val(Label1.Caption)
Text1.Visible = True
Case 3
a = a + Val(Label1.Caption)
Text1.Visible = True
End Select
Picture1.SetFocus
End SubPrivate Sub Command4_Click()
Label1.Caption = Not Label1.Caption - 1
Picture1.SetFocus
End SubPrivate Sub Command6_Click()
Label1.Caption = spr(Label1.Caption)
Picture1.SetFocus
End SubPrivate Sub Command7_Click()
Label1.Caption = Val(Label1.Caption) / 100
Picture1.SetFocus
End SubPrivate Sub Command8_Click()
Label1.Caption = 1 / Val(Label1.Caption)
Picture1.SetFocus
End SubPrivate Sub Command9_Click()
If dian < 1 Then
Label1.Caption = Label1.Caption & "."
dian = dian + 1
End If
Picture1.SetFocus
End SubPrivate Sub Form_Activate()
Picture1.SetFocus
End Sub
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
2013-06-06
展开全部
Private Sub Command1_Click()Dim x%, y%, c$, z%x = (Text1.Text)y = (Text2.Text)c = (Text3.Text) Select Case cCase "+"z = x + y Case "-" z = x - y Case "*" z = x * y Case "/" z = x / yEnd SelectText4.Text = z End Sub
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询