Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. General Programming
  3. Visual Basic
  4. How to build a simple calculator?

How to build a simple calculator?

Scheduled Pinned Locked Moved Visual Basic
helpcsharptutorialquestion
24 Posts 6 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • A aurora56

    hmmm... well... i have done the codings for each individual buttons. Eg for the button 9: Private Sub btn9_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btn9.Click TextBox1.Text = 9 temp = 9 End Sub However, I can't figure out what should the code of '+' be. Since when a user clicks on it, he/she will select another number button. So is it simply this: TextBox1.Text = Int(TextBox1.Text) + Int(TextBox1.Text)

    L Offline
    L Offline
    Lost User
    wrote on last edited by
    #12

    u remind for someone called safrooooooooooooooooooooooooooooooot

    Mohamad A. Flefel C#.net Developer

    1 Reply Last reply
    0
    • A aurora56

      -_-".... ur r making things diff4 me.. n i'm a she not him. n yes, this is a homework. =p

      L Offline
      L Offline
      Lost User
      wrote on last edited by
      #13

      hi ( SHE ) u had entered a programmers site u can't ask questions like this

      Mohamad A. Flefel mflefel@hotmail.com C#.net Developer

      A 1 Reply Last reply
      0
      • L Lost User

        hi ( SHE ) u had entered a programmers site u can't ask questions like this

        Mohamad A. Flefel mflefel@hotmail.com C#.net Developer

        A Offline
        A Offline
        aurora56
        wrote on last edited by
        #14

        Really? oh, ok. thx for trying to help me. i'll try to figure it out then . thank u....

        L 1 Reply Last reply
        0
        • A aurora56

          Really? oh, ok. thx for trying to help me. i'll try to figure it out then . thank u....

          L Offline
          L Offline
          Lost User
          wrote on last edited by
          #15

          i had made a sample calculater i can send it to u its code is very easy

          Mohamad A. Flefel mflefel@hotmail.com +962 79 5963865 C#.net Developer

          A L 2 Replies Last reply
          0
          • L Lost User

            i had made a sample calculater i can send it to u its code is very easy

            Mohamad A. Flefel mflefel@hotmail.com +962 79 5963865 C#.net Developer

            A Offline
            A Offline
            aurora56
            wrote on last edited by
            #16

            Hmm.. no thank you. I think is better if i figure it out myself or maybe you can try help me with my codings. =)

            1 Reply Last reply
            0
            • L Lost User

              i had made a sample calculater i can send it to u its code is very easy

              Mohamad A. Flefel mflefel@hotmail.com +962 79 5963865 C#.net Developer

              L Offline
              L Offline
              Lost User
              wrote on last edited by
              #17

              ok , here is my e-mail u can ask for help any time :)

              Mohamad A. Flefel mflefel@hotmail.com +962 79 5963865 C#.net Developer

              A T 2 Replies Last reply
              0
              • L Lost User

                ok , here is my e-mail u can ask for help any time :)

                Mohamad A. Flefel mflefel@hotmail.com +962 79 5963865 C#.net Developer

                T Offline
                T Offline
                Tamimi Code
                wrote on last edited by
                #18

                dont ever put you email on a fourm :suss:

                Tamimi - Code

                1 Reply Last reply
                0
                • L Lost User

                  ok , here is my e-mail u can ask for help any time :)

                  Mohamad A. Flefel mflefel@hotmail.com +962 79 5963865 C#.net Developer

                  A Offline
                  A Offline
                  aurora56
                  wrote on last edited by
                  #19

                  =) thank you. i have done the codings for each individual buttons. Eg for the button 9: Private Sub btn9_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btn9.Click TextBox1.Text = 9 temp = 9 End Sub However, I can't figure out what should the code of '+' be. Since when a user clicks on it, he/she will select another number button. So is it simply this: TextBox1.Text = Int(TextBox1.Text) + Int(TextBox1.Text)

                  C 1 Reply Last reply
                  0
                  • A aurora56

                    =) thank you. i have done the codings for each individual buttons. Eg for the button 9: Private Sub btn9_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btn9.Click TextBox1.Text = 9 temp = 9 End Sub However, I can't figure out what should the code of '+' be. Since when a user clicks on it, he/she will select another number button. So is it simply this: TextBox1.Text = Int(TextBox1.Text) + Int(TextBox1.Text)

                    C Offline
                    C Offline
                    Colin Angus Mackay
                    wrote on last edited by
                    #20

                    Here are some pointers: You need to hold some state somewhere. You also need to hold the fact that the user can type numbers like 98 (the code you showed does not append more digits, it replaces them). When a use clicks on an operator button (+-/*=) the program needs to store the current display, then it needs to accept a new number. When the user next pressed an operator it performs the function of the operator on the stored value and the current value. When a user clicks on a digit button it has to append the value on to the other digits received.


                    Upcoming Scottish Developers events: * UK Security Evangelists On Tour (2nd November, Edinburgh) * Developer Day Scotland: are you interested in speaking or attending? My: Website | Blog

                    1 Reply Last reply
                    0
                    • A aurora56

                      I had a problem. I had to create a simple calculator with VB.Net and this calculator had 0-9 buttons, add and minus function, a = button and a textbox for display of answer. I couldnt figure out the codings for the buttons. hope your can help me. thank you! =)

                      R Offline
                      R Offline
                      Reuven Elliassi
                      wrote on last edited by
                      #21

                      I have some idea for you: A. For the numeric buttons write scrip like this: private sub btn1_click(..) txtT.text = txtT.text & "1 end sub ' etc. for all numeric buttons B. For command buttons ( + - * / etc. ) write this script: private sub plus_click(..) Tmp1 = cint(txtT.text) act="plus" txtT.text="" end sub C. For = button write: private sub ans_click(..) Tmp2 = cint(txtT.text) select case act case "plus" : txtT.text = tmp1+tmp2 case "minus" : txtT.text = tmp1-tmp2 .... end select end sub This code handle only one action per two numbers. If you wans to handle lot of actions, like windows calculator, you need to add a boolean trigger that will be True if one action had been chosen and when the user select another action it will do the action selected before, then put the result in Tmp1 and then reset the trigger to False. This process will continue until the user click the = button. I'll don't give the answer for this so quickly .. ;) I give you time to think about it.

                      A 1 Reply Last reply
                      0
                      • R Reuven Elliassi

                        I have some idea for you: A. For the numeric buttons write scrip like this: private sub btn1_click(..) txtT.text = txtT.text & "1 end sub ' etc. for all numeric buttons B. For command buttons ( + - * / etc. ) write this script: private sub plus_click(..) Tmp1 = cint(txtT.text) act="plus" txtT.text="" end sub C. For = button write: private sub ans_click(..) Tmp2 = cint(txtT.text) select case act case "plus" : txtT.text = tmp1+tmp2 case "minus" : txtT.text = tmp1-tmp2 .... end select end sub This code handle only one action per two numbers. If you wans to handle lot of actions, like windows calculator, you need to add a boolean trigger that will be True if one action had been chosen and when the user select another action it will do the action selected before, then put the result in Tmp1 and then reset the trigger to False. This process will continue until the user click the = button. I'll don't give the answer for this so quickly .. ;) I give you time to think about it.

                        A Offline
                        A Offline
                        aurora56
                        wrote on last edited by
                        #22

                        =) thank u! i'll try later. oh ya. do you know of some websites which have tutorials? our lecturers just threw us this homework without giving any help... once again, thanks! hope you have a great day!!

                        C R 2 Replies Last reply
                        0
                        • A aurora56

                          =) thank u! i'll try later. oh ya. do you know of some websites which have tutorials? our lecturers just threw us this homework without giving any help... once again, thanks! hope you have a great day!!

                          C Offline
                          C Offline
                          Christian Graus
                          wrote on last edited by
                          #23

                          aurora56 wrote:

                          do you know of some websites which have tutorials?

                          Well, based on this question

                          aurora56 wrote:

                          our lecturers just threw us this homework without giving any help...

                          I suspect this is not true. Giving you code is not helping you. The answer to all of this is just a google away. If you can't do the most basic research, you need to quit your course.

                          Christian Graus - Microsoft MVP - C++ Metal Musings - Rex and my new metal blog

                          1 Reply Last reply
                          0
                          • A aurora56

                            =) thank u! i'll try later. oh ya. do you know of some websites which have tutorials? our lecturers just threw us this homework without giving any help... once again, thanks! hope you have a great day!!

                            R Offline
                            R Offline
                            Reuven Elliassi
                            wrote on last edited by
                            #24

                            Has Christian Graus said, if you can't do the basic research source codes may not help you. The idea of programming is to think about the algorithm you want to write and then think how to make it work in the easiest and quickly way you can. The speed is not only for saving project develop time yet also to increase the computer efficient. Processing resources is an expensive resource. There are few tips for you, when you want to write a computer program: 1. Define your needs and targets and the system the program will run over it (ex. windows XP, CE, Mobile Phone, etc.) 2. Multiply the targets into missions and sub-missions that will be easy to implement. 3. After you define the targets try to write algorithm (not in VB but in piece of paper) this will help you to rearrange your minds and way of work. you may also draw your tasks to think about visually. 4. The next step is to write it in VB and debugging. Good Luck ! Web site with source codes: http://www.planetsourcecode.com/ You may use such web sites (you may find a lot of them in one Google simple search) only for helping you with scripts you can't think about your own algorithm. those sites are not good for learning from the beginning.

                            Hope I helped you

                            &

                            1 Reply Last reply
                            0
                            Reply
                            • Reply as topic
                            Log in to reply
                            • Oldest to Newest
                            • Newest to Oldest
                            • Most Votes


                            • Login

                            • Don't have an account? Register

                            • Login or register to search.
                            • First post
                              Last post
                            0
                            • Categories
                            • Recent
                            • Tags
                            • Popular
                            • World
                            • Users
                            • Groups