VB统计计算器1/2

该博客介绍了使用VB编写的统计计算器程序,详细展示了如何通过输入数字进行最大值、总和、最小值、平均值和计数等统计计算。用户可以通过依次点击数字按钮输入数值,然后点击Max、Sum、Min、Ave和Counter按钮获取相应的统计结果。部分源代码展示了数字按钮的响应事件及结果显示逻辑。
摘要由CSDN通过智能技术生成

1.运行程序,输入参数,结果如下。

1.1 最大值

分别点击按钮:1、NextNum、3、NextNum、6,将三个数存入计算器中。
点击按钮:Max,结果如下:
在这里插入图片描述

1.2 总和

点击按钮:Sum,结果如下:
在这里插入图片描述

1.3 最小值

点击按钮:Min,结果如下:
在这里插入图片描述

1.4 平均值

点击按钮:Ave,结果如下:
在这里插入图片描述

1.5 计数

点击按钮:Counter,结果如下:
在这里插入图片描述

1.6 重试

点击按钮:Retry,结果如下:
在这里插入图片描述

2.部分源代码

Option Explicit
Dim counter As Integer
Dim data As Single
Dim max As Single
Dim min As Single
Dim sum As Single
Dim ave As Single

Private Sub Command10_Click()
Text1.Text = Text1.Text + "0"
End Sub

Private Sub Command1_Click()
Text1.Text = Text1.Text + "1"
End Sub

***

Private Sub Command13_Click()
Text1.Text = Val(min)
Text2.Text = "Min="
End Sub

Private Sub Command14_Click()
Text1.Text = Val(sum)
Text2.Text = "Sum="
End Sub

Private Sub Command15_Click()
Text1.Text = Val(sum / counter)
Text2.Text = "Ave="
End Sub

******

Private Sub Command18_Click()
Text1.Text = Val(counter)
Text2.Text = "Counter="
End Sub

Private Sub Command19_Click()
Text1.Text = "-" + Text1.Text
End Sub

Private Sub Command2_Click()
Text1.Text = Text1.Text + "2"
End Sub

Private Sub Command3_Click()
Text1.Text = Text1.Text + "3"
End Sub

Private Sub Command4_Click()
Text1.Text = Text1.Text + "4"
End Sub

Private Sub Command5_Click()
Text1.Text = Text1.Text + "5"
End Sub

Private Sub Command6_Click()
Text1.Text = Text1.Text + "6"
End Sub

Private Sub Command7_Click()
Text1.Text = Text1.Text + "7"
End Sub

Private Sub Command8_Click()
Text1.Text = Text1.Text + "8"
End Sub

Private Sub Command9_Click()
Text1.Text = Text1.Text + "9"
End Sub

Private Sub Command11_Click()
Text1.Text = Text1.Text + "."
End Sub

Private Sub Command17_Click()
Text1.Text = Val(max)
Text2.Text = "Max="
End Sub
代码如下 <%@ Page Language="VB" %> <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <script runat="server"> Class Ent Public Shared total, num1, num2 As String Public Shared sign As String Public Shared Sub click(ByVal a As String) total = total + a End Sub End Class Sub Count() Ent.num2 = TextBox1.Text Try Select Case Ent.sign Case "+" TextBox1.Text = CStr(CDbl(Ent.num1) + CDbl(Ent.num2)) Case "-" TextBox1.Text = CStr(CDbl(Ent.num1) - CDbl(Ent.num2)) Case "*" TextBox1.Text = CStr(CDbl(Ent.num1) * CDbl(Ent.num2)) Case "/" TextBox1.Text = CStr(CDbl(Ent.num1) / CDbl(Ent.num2)) End Select Catch ex As Exception Label1.Text = "同志请不要那数字以外的字符开计算器的玩笑!" TextBox1.Text = "0" Ent.total = "0" Ent.sign = "" End Try Ent.total = "" Ent.sign = "" End Sub Protected Sub Button1_Click(ByVal sender As Object, ByVal e As System.EventArgs) Ent.click("1") TextBox1.Text = Ent.total Call CleanLabel() End Sub Protected Sub Button2_Click(ByVal sender As Object, ByVal e As System.EventArgs) Ent.click("2") TextBox1.Text = Ent.total Call CleanLabel() End Sub Protected Sub Button3_Click(ByVal sender As Object, ByVal e As System.EventArgs) Ent.click("3") TextBox1.Text = Ent.total Call CleanLabel() End Sub Protected Sub Button4_Click(ByVal sender As Object, ByVal e As System.EventArgs) Ent.click("4") TextBox1.Text = Ent.total Call CleanLabel() End Sub Protected Sub Button5_Click(ByVal sender As Object, ByVal e As System.EventArgs) Ent.click("5") TextBox1.Text = Ent.total Call CleanLabel() End Sub Protected Sub Button6_Click(ByVal sender As Object, ByVal e As System.EventArgs) Ent.click("6") TextBox1.Text = Ent.total Call CleanLabel() End Sub Protected Sub Button7_Click(ByVal sender As Object, ByVal e As System.EventArgs) Ent.click("7") TextBox1.Text = Ent.total Call CleanLabel() End Sub Protected Sub Button8_Click(ByVal sender As Object, ByVal e As System.EventArgs) Ent.click("8") TextBox1.Text = Ent.total Call CleanLabel() End Sub Protected Sub Button9_Click(ByVal sender As Object, ByVal e As System.EventArgs) Ent.click("9") TextBox1.Text = Ent.total Call CleanLabel() End Sub Protected Sub Button10_Click(ByVal sender As Object, ByVal e As System.EventArgs) If Len(Ent.total) > 0 Then Call CleanLabel() Ent.click("0") TextBox1.Text = Ent.total End If End Sub Protected Sub Button18_Click(ByVal sender As Object, ByVal e As System.EventArgs) Call CleanLabel() Ent.total = "" Ent.sign = "" TextBox1.Text = "0" End Sub Protected Sub Button11_Click(ByVal sender As Object, ByVal e As System.EventArgs) If Len(Ent.total) >= 0 Then If InStr(Ent.total, ".") = 0 Then Ent.click(".") TextBox1.Text = Ent.total End If End If Call CleanLabel() End Sub Protected Sub Button12_Click(ByVal sender As Object, ByVal e As System.EventArgs) If Len(Ent.sign) = 1 Then Call Count() Ent.num1 = TextBox1.Text Ent.sign = "+" Else Ent.num1 = TextBox1.Text TextBox1.Text = "0" Ent.total = "" Ent.sign = "+" End If End Sub Protected Sub Button16_Click(ByVal sender As Object, ByVal e As System.EventArgs) Call Count() End Sub Protected Sub Button13_Click(ByVal sender As Object, ByVal e As System.EventArgs) If Len(Ent.sign) = 1 Then Call Count() Ent.num1 = TextBox1.Text Ent.sign = "-" Else Ent.num1 = TextBox1.Text TextBox1.Text = "0" Ent.total = "" Ent.sign = "-" End If End Sub Protected Sub Button14_Click(ByVal sender As Object, ByVal e As System.EventArgs) If Len(Ent.sign) = 1 Then Call Count() Ent.num1 = TextBox1.Text Ent.sign = "*" Else Ent.num1 = TextBox1.Text TextBox1.Text = "0" Ent.total = "" Ent.sign = "*" End If End Sub Protected Sub Button15_Click(ByVal sender As Object, ByVal e As System.EventArgs) If Len(Ent.sign) = 1 Then Call Count() Ent.num1 = TextBox1.Text Ent.sign = "/" Else Ent.num1 = TextBox1.Text TextBox1.Text = "0" Ent.total = "" Ent.sign = "/" End If End Sub Protected Sub Button17_Click(ByVal sender As Object, ByVal e As System.EventArgs) TextBox1.Text = "0" Ent.total = "" Call CleanLabel() End Sub Protected Sub Button19_Click(ByVal sender As Object, ByVal e As System.EventArgs) If Len(TextBox1.Text) > 1 Then TextBox1.Text = Left(TextBox1.Text, (Len(TextBox1.Text) - 1)) Ent.total = TextBox1.Text Else : TextBox1.Text = "0" End If End Sub Protected Sub TextBox1_TextChanged(ByVal sender As Object, ByVal e As System.EventArgs) Dim a As Double Try a = CDbl(TextBox1.Text) Call CleanLabel() Catch ex As Exception Label1.Text = "同志请不要那数字以外的字符开计算器的玩笑!" TextBox1.Text = "0" Ent.total = "0" Ent.sign = "" End Try End Sub Sub CleanLabel() Label1.Text = "" End Sub </script> <html xmlns="http://www.w3.org/1999/xhtml" > <head id="Head1" runat="server"> <title>计算器</title> </head> <body> <form id="form1" runat="server"> <div style=" text-align :center "><h3>计算器</h3></div> <div style=" text-align :center "> <asp:Label ID="Label1" runat="server" ForeColor="Red"></asp:Label>  <table style=" width: 164px; border :ridge 1px #000000"> <tr> <td style="width: 187px"> <div style=" text-align :center "> <asp:TextBox ID="TextBox1" runat="server" BorderStyle="Solid" BorderWidth="1px" Width="180px" CausesValidation="True" OnTextChanged="TextBox1_TextChanged" ForeColor="Transparent">0</asp:TextBox> </div> </td> </tr> <tr> <td style="width: 187px; height: 23px;"> <asp:Button ID="Button19" runat="server" OnClick="Button19_Click" Text="BackSpace" Width="72px" UseSubmitBehavior="False" /> <asp:Button ID="Button17" runat="server" Text="CE" OnClick="Button17_Click" Width="48px" UseSubmitBehavior="False" /> <asp:Button ID="Button18" runat="server" Text="C" OnClick="Button18_Click" Width="47px" UseSubmitBehavior="False" /> </td> </tr> <tr><td style="width: 187px;"><asp:Button ID="Button7" runat="server" Text="7" OnClick="Button7_Click" Width="40px" UseSubmitBehavior="False" /> <asp:Button ID="Button8" runat="server" Text="8" OnClick="Button8_Click" Width="40px" UseSubmitBehavior="False" /> <asp:Button ID="Button9" runat="server" Text="9" OnClick="Button9_Click" Width="40px" UseSubmitBehavior="False" /> <asp:Button ID="Button15" runat="server" Text="/" OnClick="Button15_Click" Width="40px" UseSubmitBehavior="False" /></td></tr> <tr><td style="width: 187px;"> <asp:Button ID="Button4" runat="server" Text="4" OnClick="Button4_Click" Width="40px" UseSubmitBehavior="False" /> <asp:Button ID="Button5" runat="server" Text="5" OnClick="Button5_Click" Width="40px" UseSubmitBehavior="False" /> <asp:Button ID="Button6" runat="server" Text="6" OnClick="Button6_Click" Width="40px" UseSubmitBehavior="False" /> <asp:Button ID="Button14" runat="server" Text="*" OnClick="Button14_Click" Width="40px" UseSubmitBehavior="False" /></td></tr> <tr><td style="width: 187px;"> <asp:Button ID="Button1" runat="server" Text="1" OnClick="Button1_Click" Width="40px" UseSubmitBehavior="False" /> <asp:Button ID="Button2" runat="server" Text="2" OnClick="Button2_Click" Width="40px" UseSubmitBehavior="False" /> <asp:Button ID="Button3" runat="server" Text="3" OnClick="Button3_Click" Width="40px" UseSubmitBehavior="False" /> <asp:Button ID="Button13" runat="server" Text="-" OnClick="Button13_Click" Width="40px" UseSubmitBehavior="False" /></td></tr> <tr><td style="width: 187px;"> <asp:Button ID="Button10" runat="server" Text="0" OnClick="Button10_Click" Width="40px" UseSubmitBehavior="False" /> <asp:Button ID="Button11" runat="server" Text="." OnClick="Button11_Click" Width="40px" UseSubmitBehavior="False" /> <asp:Button ID="Button12" runat="server" Text="+" OnClick="Button12_Click" Width="40px" UseSubmitBehavior="False" /> <asp:Button ID="Button16" runat="server" Text="=" OnClick="Button16_Click" Width="40px" UseSubmitBehavior="False" /></td></tr> </table> </div> </form> </body> </html>
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

peter_young1990

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值