Join 136,469 VB.NET Programmers for FREE! Get instant access to thousands of VB.NET experts, tutorials, code snippets, and more! There are 1,552 people online right now. Registration is fast and FREE... Join Now!
Hi, I am wanting to build a panel that has number buttons from 0-9, a decimal, and a label for the numbers to be put into, how do I get the numbers to add to the previous number - like a calculator does, i.e. hit button 1 and button 3, label shows '13', thanks...
Dream.In.Code has a policy by which we prefer to see a good faith effort on your part before providing source code for homework assignments. Please post the code you have written in an effort to resolve the problem, and our members would be happy to provide some guidance. Be sure to include a description of any errors you are encountering as well.
Dream.In.Code has a policy by which we prefer to see a good faith effort on your part before providing source code for homework assignments. Please post the code you have written in an effort to resolve the problem, and our members would be happy to provide some guidance. Be sure to include a description of any errors you are encountering as well.
Please post like this:
Thank you for helping us helping you.
Just for the record, this is not homework, I am not a student, just a hobbiest. I don't have any code yet, not sure how to layout the button commands. Sorry i am just that new to this. After the button click event I would write something(wrong) like
CODE
label1.text = "1"
but for every button I would hit the value in the label would change, so this is why I have no code, cause I know I need to tell it something different to add the strings together, thanks and I understand if you can't help me cause I don't have enough code yet...
There is an error in the code for the decimal button:
CODE
Private Sub cmdDecimal_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles cmdDecimal.Click 'Check for input status (we want true) If inputStatus Then 'Check if it already has a decimal (if it does then do nothing) If Not hasDecimal Then 'Check to make sure the length is > than 1 'Dont want user to add decimal as first character If txtInput.Text.Length > 1 Then 'Make sure 0 isnt the first number If Not txtInput.Text = "0" Then 'It met all our requirements so add the zero txtInput.Text += cmdDecimal.Text 'Toggle the flag to true (only 1 decimal per calculation) hasDecimal = True End If Else 'Since the length isnt > 1 'make the text 0. txtInput.Text = "0." End If End If End If
in the line: <If txtInput.Text.Length > 1 Then> corrected to: <If txtInput.Text.Length > 0 Then>
otherwise it will erase the first number you pick with the leading zero with this correction it works fine...
That was actually intentional, not only did that not allow a decimal as the first character, it didn't allow 0 (zero) to be the first character (like most calculators I know of)