如何用VB.NET编写计算器???
<P>各位大虾</P><P> 小弟最近在学习VB编程,近日需要编写一个计算器,但小弟资质尚浅,还请各位大虾能指点一二。</P>
<P> 希望哪位大哥有空帮我写个比较全面的计算器代码,并能把一些重要的代码解释一下,小弟谢过了!!!</P>[em01]
<P>#Region " Web 窗体设计器生成的代码 "</P>
<P> '该调用是 Web 窗体设计器所必需的。<BR> <System.Diagnostics.DebuggerStepThrough()> Private Sub InitializeComponent()</P>
<P> End Sub<BR> Protected WithEvents Button1 As System.Web.UI.WebControls.Button<BR> Protected WithEvents Button2 As System.Web.UI.WebControls.Button<BR> Protected WithEvents Button3 As System.Web.UI.WebControls.Button<BR> Protected WithEvents Button4 As System.Web.UI.WebControls.Button<BR> Protected WithEvents Button5 As System.Web.UI.WebControls.Button<BR> Protected WithEvents Button6 As System.Web.UI.WebControls.Button<BR> Protected WithEvents Button7 As System.Web.UI.WebControls.Button<BR> Protected WithEvents Button8 As System.Web.UI.WebControls.Button<BR> Protected WithEvents Button9 As System.Web.UI.WebControls.Button<BR> Protected WithEvents Button10 As System.Web.UI.WebControls.Button<BR> Protected WithEvents Button11 As System.Web.UI.WebControls.Button<BR> Protected WithEvents Button12 As System.Web.UI.WebControls.Button<BR> Protected WithEvents Button13 As System.Web.UI.WebControls.Button<BR> Protected WithEvents Button14 As System.Web.UI.WebControls.Button<BR> Protected WithEvents Button15 As System.Web.UI.WebControls.Button<BR> Protected WithEvents Button16 As System.Web.UI.WebControls.Button<BR> Protected WithEvents Button17 As System.Web.UI.WebControls.Button<BR> Protected WithEvents Button18 As System.Web.UI.WebControls.Button<BR> Protected WithEvents Button19 As System.Web.UI.WebControls.Button<BR> Protected WithEvents Button20 As System.Web.UI.WebControls.Button<BR> Protected WithEvents TextBox1 As System.Web.UI.WebControls.TextBox<BR> Protected WithEvents Label1 As System.Web.UI.WebControls.Label<BR> Protected WithEvents Label2 As System.Web.UI.WebControls.Label<BR> Protected WithEvents Label3 As System.Web.UI.WebControls.Label<BR> Protected WithEvents Label4 As System.Web.UI.WebControls.Label<BR> Protected WithEvents Label5 As System.Web.UI.WebControls.Label</P>
<P> '注意: 以下占位符声明是 Web 窗体设计器所必需的。<BR> '不要删除或移动它。<BR> Private designerPlaceholderDeclaration As System.Object</P>
<P> Private Sub Page_Init(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Init<BR> 'CODEGEN: 此方法调用是 Web 窗体设计器所必需的<BR> '不要使用代码编辑器修改它。<BR> InitializeComponent()<BR> End Sub</P>
<P>#End Region</P>
<P> Private Sub Page_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load<BR> '在此处放置初始化页的用户代码<BR> End Sub</P>
<P> Private Sub Button15_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button15.Click<BR> If Label2.Text = "" Then '除法的实现<BR> Label3.Text = "/"<BR> Label1.Text = TextBox1.Text<BR> Label4.Text = TextBox1.Text<BR> Else<BR> Label2.Text = TextBox1.Text<BR> Select Case Label3.Text<BR> Case "+"<BR> TextBox1.Text = CDbl(Label1.Text) + CDbl(Label2.Text)<BR> Case "*"<BR> TextBox1.Text = CDbl(Label1.Text) * CDbl(Label2.Text)<BR> Case "-"<BR> TextBox1.Text = CDbl(Label1.Text) - CDbl(Label2.Text)<BR> Case "/"<BR> TextBox1.Text = CDbl(Label1.Text) / CDbl(Label2.Text)<BR> Case "1/x"<BR> TextBox1.Text = 1 / CDbl(Label1.Text)<BR> End Select<BR> Label3.Text = "/"<BR> Label1.Text = TextBox1.Text<BR> Label4.Text = TextBox1.Text</P>
<P> End If<BR> End Sub</P>
<P> Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click<BR> If Label4.Text = "" Then<BR> TextBox1.Text = TextBox1.Text & "1"<BR> Else<BR> TextBox1.Text = ""<BR> TextBox1.Text = TextBox1.Text & "1"<BR> Label4.Text = ""<BR> End If</P>
<P> End Sub</P>
<P> Private Sub Button2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button2.Click<BR> If Label4.Text = "" Then<BR> TextBox1.Text = TextBox1.Text & "2"<BR> Else<BR> TextBox1.Text = ""<BR> TextBox1.Text = TextBox1.Text & "2"<BR> Label4.Text = ""<BR> End If<BR> End Sub</P>
<P> Private Sub Button3_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button3.Click<BR> If Label4.Text = "" Then<BR> TextBox1.Text = TextBox1.Text & "3"<BR> Else<BR> TextBox1.Text = ""<BR> TextBox1.Text = TextBox1.Text & "3"<BR> Label4.Text = ""<BR> End If<BR> End Sub</P>
<P> Private Sub Button4_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button4.Click<BR> If Label4.Text = "" Then<BR> TextBox1.Text = TextBox1.Text & "4"<BR> Else<BR> TextBox1.Text = ""<BR> TextBox1.Text = TextBox1.Text & "4"<BR> Label4.Text = ""<BR> End If<BR> End Sub</P>
<P> Private Sub Button5_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button5.Click<BR> If Label4.Text = "" Then<BR> TextBox1.Text = TextBox1.Text & "5"<BR> Else<BR> TextBox1.Text = ""<BR> TextBox1.Text = TextBox1.Text & "5"<BR> Label4.Text = ""<BR> End If<BR> End Sub</P>
<P> Private Sub Button6_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button6.Click<BR> If Label4.Text = "" Then<BR> TextBox1.Text = TextBox1.Text & "6"<BR> Else<BR> TextBox1.Text = ""<BR> TextBox1.Text = TextBox1.Text & "6"<BR> Label4.Text = ""<BR> End If<BR> End Sub</P>
<P> Private Sub Button7_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button7.Click<BR> If Label4.Text = "" Then<BR> TextBox1.Text = TextBox1.Text & "7"<BR> Else<BR> TextBox1.Text = ""<BR> TextBox1.Text = TextBox1.Text & "7"<BR> Label4.Text = ""<BR> End If<BR> End Sub</P>
<P> Private Sub Button8_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button8.Click<BR> If Label4.Text = "" Then<BR> TextBox1.Text = TextBox1.Text & "8"<BR> Else<BR> TextBox1.Text = ""<BR> TextBox1.Text = TextBox1.Text & "8"<BR> Label4.Text = ""<BR> End If<BR> End Sub</P>
<P> Private Sub Button9_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button9.Click<BR> If Label4.Text = "" Then<BR> TextBox1.Text = TextBox1.Text & "9"<BR> Else<BR> TextBox1.Text = ""<BR> TextBox1.Text = TextBox1.Text & "9"<BR> Label4.Text = ""<BR> End If<BR> End Sub</P>
<P> Private Sub Button10_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button10.Click<BR> If Label4.Text = "" Then<BR> TextBox1.Text = TextBox1.Text & "0"<BR> Else<BR> TextBox1.Text = ""<BR> TextBox1.Text = TextBox1.Text & "0"<BR> Label4.Text = ""<BR> End If<BR> End Sub</P>
<P> Private Sub Button11_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button11.Click<BR> If Label4.Text = "" Then<BR> TextBox1.Text = TextBox1.Text & "."<BR> Else<BR> TextBox1.Text = ""<BR> TextBox1.Text = TextBox1.Text & "."<BR> Label4.Text = ""<BR> End If<BR> End Sub</P>
<P> Private Sub Button12_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button12.Click<BR> If Label2.Text = "" Then '加法的实现<BR> Label3.Text = "+"<BR> Label1.Text = TextBox1.Text<BR> Label4.Text = TextBox1.Text<BR> Else<BR> Label2.Text = TextBox1.Text<BR> Select Case Label3.Text<BR> Case "+"<BR> TextBox1.Text = CDbl(Label1.Text) + CDbl(Label2.Text)<BR> Case "*"<BR> TextBox1.Text = CDbl(Label1.Text) * CDbl(Label2.Text)<BR> Case "-"<BR> TextBox1.Text = CDbl(Label1.Text) - CDbl(Label2.Text)<BR> Case "/"<BR> TextBox1.Text = CDbl(Label1.Text) / CDbl(Label2.Text)<BR> Case "1/x"<BR> TextBox1.Text = 1 / CDbl(Label1.Text)<BR> End Select<BR> Label3.Text = "+"<BR> Label1.Text = TextBox1.Text<BR> Label4.Text = TextBox1.Text</P>
<P> End If</P>
<P> End Sub</P>
<P> Private Sub Button13_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button13.Click<BR> If Label2.Text = "" Then '减法的实现<BR> Label3.Text = "-"<BR> Label1.Text = TextBox1.Text<BR> Label4.Text = TextBox1.Text<BR> Else<BR> Label2.Text = TextBox1.Text<BR> Select Case Label3.Text<BR> Case "+"<BR> TextBox1.Text = CDbl(Label1.Text) + CDbl(Label2.Text)<BR> Case "*"<BR> TextBox1.Text = CDbl(Label1.Text) * CDbl(Label2.Text)<BR> Case "-"<BR> TextBox1.Text = CDbl(Label1.Text) - CDbl(Label2.Text)<BR> Case "/"<BR> TextBox1.Text = CDbl(Label1.Text) / CDbl(Label2.Text)<BR> Case "1/x"<BR> TextBox1.Text = 1 / CDbl(Label1.Text)<BR> End Select<BR> Label3.Text = "-"<BR> Label1.Text = TextBox1.Text<BR> Label4.Text = TextBox1.Text</P>
<P> End If<BR> End Sub</P>
<P> Private Sub Button14_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button14.Click<BR> If Label2.Text = "" Then '乘法的实现<BR> Label3.Text = "*"<BR> Label1.Text = TextBox1.Text<BR> Label4.Text = TextBox1.Text<BR> Else<BR> Label2.Text = TextBox1.Text<BR> Select Case Label3.Text<BR> Case "+"<BR> TextBox1.Text = CDbl(Label1.Text) + CDbl(Label2.Text)<BR> Case "*"<BR> TextBox1.Text = CDbl(Label1.Text) * CDbl(Label2.Text)<BR> Case "-"<BR> TextBox1.Text = CDbl(Label1.Text) - CDbl(Label2.Text)<BR> Case "/"<BR> TextBox1.Text = CDbl(Label1.Text) / CDbl(Label2.Text)<BR> Case "1/x"<BR> TextBox1.Text = 1 / CDbl(Label1.Text)<BR> End Select<BR> Label3.Text = "*"<BR> Label1.Text = TextBox1.Text<BR> Label4.Text = TextBox1.Text</P>
<P> End If<BR> End Sub</P>
<P> Private Sub Button20_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button20.Click<BR> Label2.Text = TextBox1.Text '等于的实现<BR> Select Case Label3.Text<BR> Case "+"<BR> TextBox1.Text = CDbl(Label1.Text) + CDbl(Label2.Text)<BR> Case "*"<BR> TextBox1.Text = CDbl(Label1.Text) * CDbl(Label2.Text)<BR> Case "-"<BR> TextBox1.Text = CDbl(Label1.Text) - CDbl(Label2.Text)<BR> Case "/"<BR> TextBox1.Text = CDbl(Label1.Text) / CDbl(Label2.Text)<BR> Case "1/x"<BR> TextBox1.Text = 1 / CDbl(Label1.Text)<BR> End Select<BR> Label2.Text = ""<BR> End Sub</P>
<P> Private Sub Button16_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button16.Click<BR> If Label2.Text = "" Then '倒数的实现<BR> Label3.Text = "1/x"<BR> Label1.Text = TextBox1.Text<BR> Label4.Text = TextBox1.Text<BR> Else<BR> Label2.Text = TextBox1.Text<BR> Select Case Label3.Text<BR> Case "+"<BR> TextBox1.Text = CDbl(Label1.Text) + CDbl(Label2.Text)<BR> Case "*"<BR> TextBox1.Text = CDbl(Label1.Text) * CDbl(Label2.Text)<BR> Case "-"<BR> TextBox1.Text = CDbl(Label1.Text) - CDbl(Label2.Text)<BR> Case "/"<BR> TextBox1.Text = CDbl(Label1.Text) / CDbl(Label2.Text)<BR> Case "1/x"<BR> TextBox1.Text = 1 / CDbl(Label1.Text)<BR> End Select<BR> Label3.Text = "1/x"<BR> Label1.Text = TextBox1.Text<BR> Label4.Text = TextBox1.Text</P>
<P> End If<BR> End Sub</P>
<P> Private Sub Button18_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button18.Click<BR> TextBox1.Text = "" 'CE的实现<BR> End Sub</P>
<P> Private Sub Button19_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button19.Click<BR> Label1.Text = "" ' C的实现<BR> Label2.Text = ""<BR> Label3.Text = ""<BR> Label4.Text = ""<BR> TextBox1.Text = ""<BR> End Sub</P>
<P> Private Sub Button17_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button17.Click<BR> Dim s As String 'Backspace的实现<BR> Dim t As String<BR> s = TextBox1.Text<BR> t = Left(s, Len(s) - 1)<BR> TextBox1.Text = t</P>
<P><BR> End Sub</P>
<P>End Class<BR></P> 给我邮箱 给你发过去 是呀给我你的邮箱我保证给你的是一个出错最少的程序<BR>是上学期没事的时候 写的 你写很不错吗?你今年大几了呢?你可以编一个《才数字》的吗?[em31] 我也要<a href="mailto:guobin609@163.com" target="_blank" >guobin609@163.com</A> 谢谢 我也要<a href="mailto:zxb096@163.com" target="_blank" ><FONT color=#000000>zxb096@163.com</FONT></A> 谢谢 你们就知道这样!!害得大哥在忙啊~<BR>大哥快编好了啊 ~~~~~~<BR><猜数字><BR> <P>编好了也不白费啊,一样可以拿来大家学习嘛</P> <P>我也要<a href="mailto:.furong_63@163.com" target="_blank" >.furong_63@163.com</A>.谢谢!!!</P> 好全呀,佩服 你们怎么不自己写啊 晕.楼主比我懒哦! 要要要要要要,我要,<a href="mailto:568697407@QQ.com" target="_blank" >568697407@QQ.com</A> 谢谢!!!!! 这个计算器我们这个学期做过,你现在还要不要了? 我也想要 程序啊 [em08] <a href="mailto:lihaijun___@sohu.com" target="_blank" >lihaijun___@sohu.com</A>谢谢你哦[em22] <P>简单有复杂~</P> 非常感谢啊,代码我考回去研究研究啊
页:
[1]
2
