| 网站首页 | 业界新闻 | 小组 | 威客 | 人才 | 下载频道 | 博客 | 代码贴 | 在线编程 | 编程论坛
欢迎加入我们,一同切磋技术
用户名:   
 
密 码:  
共有 13810 人关注过本帖
标题:如何用VB.NET编写计算器???
只看楼主 加入收藏
mojoy
Rank: 1
等 级:新手上路
帖 子:2
专家分:0
注 册:2004-12-28
收藏
 问题点数:0 回复次数:26 
如何用VB.NET编写计算器???

各位大虾

小弟最近在学习VB编程,近日需要编写一个计算器,但小弟资质尚浅,还请各位大虾能指点一二。

希望哪位大哥有空帮我写个比较全面的计算器代码,并能把一些重要的代码解释一下,小弟谢过了!!!

搜索更多相关主题的帖子: 计算器 NET 编写 
2004-12-28 10:11
Mari
Rank: 1
等 级:新手上路
帖 子:20
专家分:0
注 册:2004-11-10
收藏
得分:0 
数字计算器还是科学计算器?

Face the powder not powder the face
2004-12-28 19:49
mojoy
Rank: 1
等 级:新手上路
帖 子:2
专家分:0
注 册:2004-12-28
收藏
得分:0 
我先学简单的,是数字计算器,科学的太深奥,一时半会搞不懂。还请指教!!!!
2004-12-30 09:35
150640643
Rank: 1
等 级:新手上路
帖 子:2
专家分:0
注 册:2005-11-7
收藏
得分:0 

Public Class WebForm1
Inherits System.Web.UI.Page

#Region " Web 窗体设计器生成的代码 "

'该调用是 Web 窗体设计器所必需的。
<System.Diagnostics.DebuggerStepThrough()> Private Sub InitializeComponent()

End Sub
Protected WithEvents Button1 As System.Web.UI.WebControls.Button
Protected WithEvents Button2 As System.Web.UI.WebControls.Button
Protected WithEvents Button3 As System.Web.UI.WebControls.Button
Protected WithEvents Button4 As System.Web.UI.WebControls.Button
Protected WithEvents Button5 As System.Web.UI.WebControls.Button
Protected WithEvents Button6 As System.Web.UI.WebControls.Button
Protected WithEvents Button7 As System.Web.UI.WebControls.Button
Protected WithEvents Button8 As System.Web.UI.WebControls.Button
Protected WithEvents Button9 As System.Web.UI.WebControls.Button
Protected WithEvents Button10 As System.Web.UI.WebControls.Button
Protected WithEvents Button11 As System.Web.UI.WebControls.Button
Protected WithEvents Button12 As System.Web.UI.WebControls.Button
Protected WithEvents Button13 As System.Web.UI.WebControls.Button
Protected WithEvents Button14 As System.Web.UI.WebControls.Button
Protected WithEvents Button15 As System.Web.UI.WebControls.Button
Protected WithEvents Button16 As System.Web.UI.WebControls.Button
Protected WithEvents Button17 As System.Web.UI.WebControls.Button
Protected WithEvents Button18 As System.Web.UI.WebControls.Button
Protected WithEvents Button19 As System.Web.UI.WebControls.Button
Protected WithEvents Button20 As System.Web.UI.WebControls.Button
Protected WithEvents TextBox1 As System.Web.UI.WebControls.TextBox
Protected WithEvents Label1 As System.Web.UI.WebControls.Label
Protected WithEvents Label2 As System.Web.UI.WebControls.Label
Protected WithEvents Label3 As System.Web.UI.WebControls.Label
Protected WithEvents Label4 As System.Web.UI.WebControls.Label
Protected WithEvents Label5 As System.Web.UI.WebControls.Label

'注意: 以下占位符声明是 Web 窗体设计器所必需的。
'不要删除或移动它。
Private designerPlaceholderDeclaration As System.Object

Private Sub Page_Init(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Init
'CODEGEN: 此方法调用是 Web 窗体设计器所必需的
'不要使用代码编辑器修改它。
InitializeComponent()
End Sub

#End Region

Private Sub Page_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
'在此处放置初始化页的用户代码
End Sub

Private Sub Button15_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button15.Click
If Label2.Text = "" Then '除法的实现
Label3.Text = "/"
Label1.Text = TextBox1.Text
Label4.Text = TextBox1.Text
Else
Label2.Text = TextBox1.Text
Select Case Label3.Text
Case "+"
TextBox1.Text = CDbl(Label1.Text) + CDbl(Label2.Text)
Case "*"
TextBox1.Text = CDbl(Label1.Text) * CDbl(Label2.Text)
Case "-"
TextBox1.Text = CDbl(Label1.Text) - CDbl(Label2.Text)
Case "/"
TextBox1.Text = CDbl(Label1.Text) / CDbl(Label2.Text)
Case "1/x"
TextBox1.Text = 1 / CDbl(Label1.Text)
End Select
Label3.Text = "/"
Label1.Text = TextBox1.Text
Label4.Text = TextBox1.Text

End If
End Sub

Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
If Label4.Text = "" Then
TextBox1.Text = TextBox1.Text & "1"
Else
TextBox1.Text = ""
TextBox1.Text = TextBox1.Text & "1"
Label4.Text = ""
End If

End Sub

Private Sub Button2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button2.Click
If Label4.Text = "" Then
TextBox1.Text = TextBox1.Text & "2"
Else
TextBox1.Text = ""
TextBox1.Text = TextBox1.Text & "2"
Label4.Text = ""
End If
End Sub

Private Sub Button3_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button3.Click
If Label4.Text = "" Then
TextBox1.Text = TextBox1.Text & "3"
Else
TextBox1.Text = ""
TextBox1.Text = TextBox1.Text & "3"
Label4.Text = ""
End If
End Sub

Private Sub Button4_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button4.Click
If Label4.Text = "" Then
TextBox1.Text = TextBox1.Text & "4"
Else
TextBox1.Text = ""
TextBox1.Text = TextBox1.Text & "4"
Label4.Text = ""
End If
End Sub

Private Sub Button5_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button5.Click
If Label4.Text = "" Then
TextBox1.Text = TextBox1.Text & "5"
Else
TextBox1.Text = ""
TextBox1.Text = TextBox1.Text & "5"
Label4.Text = ""
End If
End Sub

Private Sub Button6_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button6.Click
If Label4.Text = "" Then
TextBox1.Text = TextBox1.Text & "6"
Else
TextBox1.Text = ""
TextBox1.Text = TextBox1.Text & "6"
Label4.Text = ""
End If
End Sub

Private Sub Button7_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button7.Click
If Label4.Text = "" Then
TextBox1.Text = TextBox1.Text & "7"
Else
TextBox1.Text = ""
TextBox1.Text = TextBox1.Text & "7"
Label4.Text = ""
End If
End Sub

Private Sub Button8_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button8.Click
If Label4.Text = "" Then
TextBox1.Text = TextBox1.Text & "8"
Else
TextBox1.Text = ""
TextBox1.Text = TextBox1.Text & "8"
Label4.Text = ""
End If
End Sub

Private Sub Button9_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button9.Click
If Label4.Text = "" Then
TextBox1.Text = TextBox1.Text & "9"
Else
TextBox1.Text = ""
TextBox1.Text = TextBox1.Text & "9"
Label4.Text = ""
End If
End Sub

Private Sub Button10_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button10.Click
If Label4.Text = "" Then
TextBox1.Text = TextBox1.Text & "0"
Else
TextBox1.Text = ""
TextBox1.Text = TextBox1.Text & "0"
Label4.Text = ""
End If
End Sub

Private Sub Button11_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button11.Click
If Label4.Text = "" Then
TextBox1.Text = TextBox1.Text & "."
Else
TextBox1.Text = ""
TextBox1.Text = TextBox1.Text & "."
Label4.Text = ""
End If
End Sub

Private Sub Button12_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button12.Click
If Label2.Text = "" Then '加法的实现
Label3.Text = "+"
Label1.Text = TextBox1.Text
Label4.Text = TextBox1.Text
Else
Label2.Text = TextBox1.Text
Select Case Label3.Text
Case "+"
TextBox1.Text = CDbl(Label1.Text) + CDbl(Label2.Text)
Case "*"
TextBox1.Text = CDbl(Label1.Text) * CDbl(Label2.Text)
Case "-"
TextBox1.Text = CDbl(Label1.Text) - CDbl(Label2.Text)
Case "/"
TextBox1.Text = CDbl(Label1.Text) / CDbl(Label2.Text)
Case "1/x"
TextBox1.Text = 1 / CDbl(Label1.Text)
End Select
Label3.Text = "+"
Label1.Text = TextBox1.Text
Label4.Text = TextBox1.Text

End If

End Sub

Private Sub Button13_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button13.Click
If Label2.Text = "" Then '减法的实现
Label3.Text = "-"
Label1.Text = TextBox1.Text
Label4.Text = TextBox1.Text
Else
Label2.Text = TextBox1.Text
Select Case Label3.Text
Case "+"
TextBox1.Text = CDbl(Label1.Text) + CDbl(Label2.Text)
Case "*"
TextBox1.Text = CDbl(Label1.Text) * CDbl(Label2.Text)
Case "-"
TextBox1.Text = CDbl(Label1.Text) - CDbl(Label2.Text)
Case "/"
TextBox1.Text = CDbl(Label1.Text) / CDbl(Label2.Text)
Case "1/x"
TextBox1.Text = 1 / CDbl(Label1.Text)
End Select
Label3.Text = "-"
Label1.Text = TextBox1.Text
Label4.Text = TextBox1.Text

End If
End Sub

Private Sub Button14_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button14.Click
If Label2.Text = "" Then '乘法的实现
Label3.Text = "*"
Label1.Text = TextBox1.Text
Label4.Text = TextBox1.Text
Else
Label2.Text = TextBox1.Text
Select Case Label3.Text
Case "+"
TextBox1.Text = CDbl(Label1.Text) + CDbl(Label2.Text)
Case "*"
TextBox1.Text = CDbl(Label1.Text) * CDbl(Label2.Text)
Case "-"
TextBox1.Text = CDbl(Label1.Text) - CDbl(Label2.Text)
Case "/"
TextBox1.Text = CDbl(Label1.Text) / CDbl(Label2.Text)
Case "1/x"
TextBox1.Text = 1 / CDbl(Label1.Text)
End Select
Label3.Text = "*"
Label1.Text = TextBox1.Text
Label4.Text = TextBox1.Text

End If
End Sub

Private Sub Button20_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button20.Click
Label2.Text = TextBox1.Text '等于的实现
Select Case Label3.Text
Case "+"
TextBox1.Text = CDbl(Label1.Text) + CDbl(Label2.Text)
Case "*"
TextBox1.Text = CDbl(Label1.Text) * CDbl(Label2.Text)
Case "-"
TextBox1.Text = CDbl(Label1.Text) - CDbl(Label2.Text)
Case "/"
TextBox1.Text = CDbl(Label1.Text) / CDbl(Label2.Text)
Case "1/x"
TextBox1.Text = 1 / CDbl(Label1.Text)
End Select
Label2.Text = ""
End Sub

Private Sub Button16_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button16.Click
If Label2.Text = "" Then '倒数的实现
Label3.Text = "1/x"
Label1.Text = TextBox1.Text
Label4.Text = TextBox1.Text
Else
Label2.Text = TextBox1.Text
Select Case Label3.Text
Case "+"
TextBox1.Text = CDbl(Label1.Text) + CDbl(Label2.Text)
Case "*"
TextBox1.Text = CDbl(Label1.Text) * CDbl(Label2.Text)
Case "-"
TextBox1.Text = CDbl(Label1.Text) - CDbl(Label2.Text)
Case "/"
TextBox1.Text = CDbl(Label1.Text) / CDbl(Label2.Text)
Case "1/x"
TextBox1.Text = 1 / CDbl(Label1.Text)
End Select
Label3.Text = "1/x"
Label1.Text = TextBox1.Text
Label4.Text = TextBox1.Text

End If
End Sub

Private Sub Button18_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button18.Click
TextBox1.Text = "" 'CE的实现
End Sub

Private Sub Button19_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button19.Click
Label1.Text = "" ' C的实现
Label2.Text = ""
Label3.Text = ""
Label4.Text = ""
TextBox1.Text = ""
End Sub

Private Sub Button17_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button17.Click
Dim s As String 'Backspace的实现
Dim t As String
s = TextBox1.Text
t = Left(s, Len(s) - 1)
TextBox1.Text = t


End Sub

End Class

2005-11-07 21:58
ocean_263
Rank: 1
等 级:新手上路
帖 子:11
专家分:0
注 册:2005-11-20
收藏
得分:0 
给我邮箱 给你发过去

2005-11-20 00:51
smoonmoon
Rank: 1
等 级:新手上路
帖 子:2
专家分:0
注 册:2006-1-8
收藏
得分:0 
是呀给我你的邮箱我保证给你的是一个出错最少的程序
是上学期没事的时候 写的
2006-01-08 12:35
meiwang2008
Rank: 1
等 级:新手上路
帖 子:42
专家分:0
注 册:2006-1-8
收藏
得分:0 
你写很不错吗?你今年大几了呢?你可以编一个《才数字》的吗?

我爱这里的会员,我将权利支持你们学习!
2006-01-08 15:45
jasonchen888
Rank: 1
等 级:新手上路
帖 子:4
专家分:0
注 册:2005-8-8
收藏
得分:0 
我也要guobin609@163.com 谢谢
2006-01-09 17:19
zxb096
Rank: 1
等 级:新手上路
帖 子:2
专家分:0
注 册:2006-1-11
收藏
得分:0 
我也要zxb096@163.com 谢谢
2006-01-11 22:58
meiwang2008
Rank: 1
等 级:新手上路
帖 子:42
专家分:0
注 册:2006-1-8
收藏
得分:0 
你们就知道这样!!害得大哥在忙啊~
大哥快编好了啊 ~~~~~~
<猜数字>

我爱这里的会员,我将权利支持你们学习!
2006-01-14 22:48
快速回复:如何用VB.NET编写计算器???
数据加载中...
 
   



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

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