Welcome to Dream.In.Code
Getting VB.NET Help is Easy!

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!




How to build a number generator?

 
Reply to this topicStart new topic

How to build a number generator?

hawkvalley1
2 Jul, 2008 - 09:16 AM
Post #1

New D.I.C Head
*

Joined: 2 Jul, 2008
Posts: 15

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...


User is offlineProfile CardPM
+Quote Post

PsychoCoder
RE: How To Build A Number Generator?
2 Jul, 2008 - 09:25 AM
Post #2

using DIC.Core;
Group Icon

Joined: 26 Jul, 2007
Posts: 8,993



Thanked: 125 times
Dream Kudos: 8625
Expert In: VB, VB.Net, C#, SQL, ASP, ASP.Net, Web Development, HTML, CSS, Win32 API, Javascript, mySQL, J#, Boo.Net

My Contributions
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.
User is offlineProfile CardPM
+Quote Post

hawkvalley1
RE: How To Build A Number Generator?
2 Jul, 2008 - 09:52 AM
Post #3

New D.I.C Head
*

Joined: 2 Jul, 2008
Posts: 15

QUOTE(PsychoCoder @ 2 Jul, 2008 - 10:25 AM) *

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...


User is offlineProfile CardPM
+Quote Post

PsychoCoder
RE: How To Build A Number Generator?
2 Jul, 2008 - 09:54 AM
Post #4

using DIC.Core;
Group Icon

Joined: 26 Jul, 2007
Posts: 8,993



Thanked: 125 times
Dream Kudos: 8625
Expert In: VB, VB.Net, C#, SQL, ASP, ASP.Net, Web Development, HTML, CSS, Win32 API, Javascript, mySQL, J#, Boo.Net

My Contributions
Take a look at this tutorial on creating a calculator in VB.NET, it should be able to help you get started smile.gif
User is offlineProfile CardPM
+Quote Post

hawkvalley1
RE: How To Build A Number Generator?
2 Jul, 2008 - 10:27 AM
Post #5

New D.I.C Head
*

Joined: 2 Jul, 2008
Posts: 15


Thanks, I see the code and it makes sense now. Everything hurts more in the beginning!
User is offlineProfile CardPM
+Quote Post

PsychoCoder
RE: How To Build A Number Generator?
2 Jul, 2008 - 10:28 AM
Post #6

using DIC.Core;
Group Icon

Joined: 26 Jul, 2007
Posts: 8,993



Thanked: 125 times
Dream Kudos: 8625
Expert In: VB, VB.Net, C#, SQL, ASP, ASP.Net, Web Development, HTML, CSS, Win32 API, Javascript, mySQL, J#, Boo.Net

My Contributions
But it does get easier, trust me. Glad I could help smile.gif
User is offlineProfile CardPM
+Quote Post

hawkvalley1
RE: How To Build A Number Generator?
2 Jul, 2008 - 12:33 PM
Post #7

New D.I.C Head
*

Joined: 2 Jul, 2008
Posts: 15


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...

User is offlineProfile CardPM
+Quote Post

PsychoCoder
RE: How To Build A Number Generator?
2 Jul, 2008 - 12:36 PM
Post #8

using DIC.Core;
Group Icon

Joined: 26 Jul, 2007
Posts: 8,993



Thanked: 125 times
Dream Kudos: 8625
Expert In: VB, VB.Net, C#, SQL, ASP, ASP.Net, Web Development, HTML, CSS, Win32 API, Javascript, mySQL, J#, Boo.Net

My Contributions
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)
User is offlineProfile CardPM
+Quote Post

Fast ReplyReply to this topicStart new topic
Time is now: 12/2/08 05:35PM

Live VB.NET Help!

VB.NET Tutorials

Reference Sheets

VB.NET Snippets

DIC Chatroom

Bye Bye Ads

Monthly Drawing

Thumb Drive

Top Contributors

Top 10 Kudos This Month