基本计算器百分比函数 [英] Basic Calculator Percentage function
本文介绍了基本计算器百分比函数的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我必须为我的编程课程创建一个基本的计算器,而我正在努力计算出计算器上百分比按钮的功能。我按照此视频构建了基本功能: https://www.youtube.com/watch?v = RhCzj5q6uqA
但我需要创建一个附加功能。
任何建议都会非常感激,因为我似乎无法自己解决这个问题
我正在使用以下代码:
Public Class Form1
Dim Firstnum As Decimal
Dim Secondnum As Decimal
Dim operations As Integer
Dim Operator_selector As Boolean = False
Private Sub Button7_Click(sender As Object,e As EventArgs)Handles Button7.Click
If TextBox1.Text<> " 0"然后
TextBox1.Text + =" 7"
Else
TextBox1.Text + =" 7"
End if
End Sub
Private Sub Form1_Load(sender As Object,e As EventArgs)Handles MyBase.Load
End Sub
Private Sub Button1_Click(发送者为对象,e为EventArgs)处理Button1.Click
如果TextBox1.Text<> " 0"然后
TextBox1.Text + =" 1"
Else
TextBox1.Text + =" 1"
End if
End Sub
Private Sub Button2_Click(sender As Object,e As EventArgs)处理Button2.Click
If TextBox1.Text<> " 0"然后
TextBox1.Text + =" 2"
Else
TextBox1.Text + =" 2"
End if
End Sub
Private Sub Button3_Click(sender As Object,e As EventArgs)处理Button3.Click
If TextBox1.Text<> " 0"然后
TextBox1.Text + =" 3"
Else
TextBox1.Text + =" 3"
End if
End Sub
Private Sub Button4_Click(sender As Object,e As EventArgs)Handles Button4.Click
If TextBox1.Text<> " 0"然后
TextBox1.Text + =" 4"
Else
TextBox1.Text + =" 4"
End if
End Sub
Private Sub Button5_Click(sender As Object,e As EventArgs)处理Button5.Click
If TextBox1.Text<> " 0"然后
TextBox1.Text + =" 5"
Else
TextBox1.Text + =" 5"
End if
End Sub
Private Sub Button6_Click(sender As Object,e As EventArgs)处理Button6.Click
If TextBox1.Text<> " 0"然后
TextBox1.Text + =" 6"
Else
TextBox1.Text + =" 6"
End if
End Sub
Private Sub Button8_Click(sender As Object,e As EventArgs)Handles Button8.Click
If TextBox1.Text<> " 0"然后
TextBox1.Text + =" 8"
Else
TextBox1.Text + =" 8"
End if
End Sub
Private Sub Button9_Click(sender As Object,e As EventArgs)处理Button9.Click
If TextBox1.Text<> " 0"然后
TextBox1.Text + =" 9"
Else
TextBox1.Text + =" 9"
End if
End Sub
Private Sub Button0_Click(sender As Object,e As EventArgs)Handles Button0.Click
If TextBox1.Text<> " 0"然后
TextBox1.Text + =" 0"
End if
End Sub
Private Sub TextBox1_TextChanged(sender As Object,e As EventArgs)Handles TextBox1.TextChanged
End Sub
Private Sub ButtonClear_Click(sender As Object,e As EventArgs)Handles ButtonClear.Click
TextBox1.Text =""
End Sub
Private Sub ButtonDecimal_Click(sender As Object,e As EventArgs)Handles ButtonDecimal.Click
If Not(TextBox1.Text.Contains("。")))然后
TextBox1.Text + ="。"
End if
End Sub
Private Sub ButtonEqual_Click(sender As Object,e As EventArgs)Handles ButtonEqual.Click
If Operator_selector = True Then
Secondnum = TextBox1.Text
如果操作= 1则
TextBox1.Text = Firstnum + Secondnum
ElseIf操作= 2然后
TextBox1.Text = Firstnum - Secondnum
ElseIf操作= 3然后
TextBox1.Text = Firstnum * Secondnum
否则
如果Secondnum = 0则
TextBox1.Text ="错误!"
其他
TextBox1.Text = Firstnum / Secondnum
结束如果
结束如果
Operator_selector = False
结束如果
结束Sub
Private Sub ButtonPercent_Click(sender As Object,e As EventArgs)Handles ButtonPercent.Click
End Sub
Private Sub ButtonDivide_Click(sender as Object ,e As EventArgs)处理ButtonDivide.Click
Firstnum = TextBox1.Text
TextBox1.Text =""
Operator_selector = True
operations = 4'= /
End Sub
Private Sub ButtonMultiply_Click(sender As Object,e As EventArgs)处理ButtonMultiply.Click
Firstnum = TextBox1.Text
TextBox1.Text =""
Operator_selector = True
operations = 3'= *
End Sub
Private Sub ButtonMinus_Click(sender As Object,e As EventArgs)处理ButtonMinus.Click
Firstnum = TextBox1.Text
TextBox1.Text =""
Operator_selector = True
operations = 2'= -
End Sub
Private Sub ButtonAdd_Click(sender As Object,e As EventArgs)Handles ButtonAdd.Click
Firstnum = TextBox1.Text
TextBox1.Text =" 0"
Operator_selector = True
operations = 1'= +
End Sub
Private Sub PictureBox3_Click(sender As Object,e As EventArgs)处理PictureBox3.Click
结束次级
结束等级
解决方案
请编辑您的帖子并使用代码的代码按钮。
I've got to create a basic calculator for my programming coursework, and I'm struggling to work out the function of a Percentage button on a calculator. I followed this video to build the basic functions: https://www.youtube.com/watch?v=RhCzj5q6uqA
But I need to create an additional feature.
Any advice would be really appreciated as I can't seem to work it out myself
I'm using the following code:
Public Class Form1 Dim Firstnum As Decimal Dim Secondnum As Decimal Dim operations As Integer Dim Operator_selector As Boolean = False Private Sub Button7_Click(sender As Object, e As EventArgs) Handles Button7.Click If TextBox1.Text <> "0" Then TextBox1.Text += "7" Else TextBox1.Text += "7" End If End Sub Private Sub Form1_Load(sender As Object, e As EventArgs) Handles MyBase.Load End Sub Private Sub Button1_Click(sender As Object, e As EventArgs) Handles Button1.Click If TextBox1.Text <> "0" Then TextBox1.Text += "1" Else TextBox1.Text += "1" End If End Sub Private Sub Button2_Click(sender As Object, e As EventArgs) Handles Button2.Click If TextBox1.Text <> "0" Then TextBox1.Text += "2" Else TextBox1.Text += "2" End If End Sub Private Sub Button3_Click(sender As Object, e As EventArgs) Handles Button3.Click If TextBox1.Text <> "0" Then TextBox1.Text += "3" Else TextBox1.Text += "3" End If End Sub Private Sub Button4_Click(sender As Object, e As EventArgs) Handles Button4.Click If TextBox1.Text <> "0" Then TextBox1.Text += "4" Else TextBox1.Text += "4" End If End Sub Private Sub Button5_Click(sender As Object, e As EventArgs) Handles Button5.Click If TextBox1.Text <> "0" Then TextBox1.Text += "5" Else TextBox1.Text += "5" End If End Sub Private Sub Button6_Click(sender As Object, e As EventArgs) Handles Button6.Click If TextBox1.Text <> "0" Then TextBox1.Text += "6" Else TextBox1.Text += "6" End If End Sub Private Sub Button8_Click(sender As Object, e As EventArgs) Handles Button8.Click If TextBox1.Text <> "0" Then TextBox1.Text += "8" Else TextBox1.Text += "8" End If End Sub Private Sub Button9_Click(sender As Object, e As EventArgs) Handles Button9.Click If TextBox1.Text <> "0" Then TextBox1.Text += "9" Else TextBox1.Text += "9" End If End Sub Private Sub Button0_Click(sender As Object, e As EventArgs) Handles Button0.Click If TextBox1.Text <> "0" Then TextBox1.Text += "0" End If End Sub Private Sub TextBox1_TextChanged(sender As Object, e As EventArgs) Handles TextBox1.TextChanged End Sub Private Sub ButtonClear_Click(sender As Object, e As EventArgs) Handles ButtonClear.Click TextBox1.Text = "" End Sub Private Sub ButtonDecimal_Click(sender As Object, e As EventArgs) Handles ButtonDecimal.Click If Not (TextBox1.Text.Contains(".")) Then TextBox1.Text += "." End If End Sub Private Sub ButtonEqual_Click(sender As Object, e As EventArgs) Handles ButtonEqual.Click If Operator_selector = True Then Secondnum = TextBox1.Text If operations = 1 Then TextBox1.Text = Firstnum + Secondnum ElseIf operations = 2 Then TextBox1.Text = Firstnum - Secondnum ElseIf operations = 3 Then TextBox1.Text = Firstnum * Secondnum Else If Secondnum = 0 Then TextBox1.Text = "Error!" Else TextBox1.Text = Firstnum / Secondnum End If End If Operator_selector = False End If End Sub Private Sub ButtonPercent_Click(sender As Object, e As EventArgs) Handles ButtonPercent.Click End Sub Private Sub ButtonDivide_Click(sender As Object, e As EventArgs) Handles ButtonDivide.Click Firstnum = TextBox1.Text TextBox1.Text = "" Operator_selector = True operations = 4 ' = / End Sub Private Sub ButtonMultiply_Click(sender As Object, e As EventArgs) Handles ButtonMultiply.Click Firstnum = TextBox1.Text TextBox1.Text = "" Operator_selector = True operations = 3 ' = * End Sub Private Sub ButtonMinus_Click(sender As Object, e As EventArgs) Handles ButtonMinus.Click Firstnum = TextBox1.Text TextBox1.Text = "" Operator_selector = True operations = 2 ' = - End Sub Private Sub ButtonAdd_Click(sender As Object, e As EventArgs) Handles ButtonAdd.Click Firstnum = TextBox1.Text TextBox1.Text = "0" Operator_selector = True operations = 1 ' = + End Sub Private Sub PictureBox3_Click(sender As Object, e As EventArgs) Handles PictureBox3.Click End Sub End Class
解决方案
Please edit your post and use the code button for your code.
这篇关于基本计算器百分比函数的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文