![]() |
|
|
|
| ||||||
|
Welcome to the The ProgrammersTalk Community forums. You are currently viewing our boards as a guest which gives you limited access to view most discussions and access our other features. By joining our free community you will have access to post topics, communicate privately with other members (PM), respond to polls, upload content and access many other special features. Registration is fast, simple and absolutely free so please, join our community today! If you have any problems with the registration process or your account login, please contact contact us. |
| Tags: |
![]() |
![]() | | LinkBack | Thread Tools | Display Modes | ![]() |
| |||
| [SOLVED] Write in Visual basic language a program of a calculator, please? That calculator has to do: addition, subtraction, multiplication and division. And it should have an icon to delete the former results and start again. I really need it, and I will appreciate this a lot, thank you all. |
| |
| |||
| I don't think anyone is going to just "write" this application for you but we would be willing to help you out You would have a class with a private variable holding the Current Value (_CurrentValue). This _CurrentValue starts out with 0... then you can just encapsulate the already existing methods in VB to do addition, subtraction, etc...__________________ Day Cares | Golf Courses | Disc Golf Courses | Campgrounds | Ice Rinks | Paintball Fields | Dentists | Plastic Surgeons | Aging Jokes Catholic Churches | Lutheran Churches | Methodist Churches | Episcopal Churches | Clean Jokes |
| ||||
| This is my first post on this forum so I want to make it useful. I think this is your assignment so you have to do it on your own. However, I can provide you some hints to do it on your own. Creating simple calculator like this is pretty easy. Follow these steps you will able to complete that program in just a hour: 1) Creating a form, a textbox which is for input and output the result, 10 buttons of number from 0 to 9, and math operations buttons. 2) Creating 2 variables: first one is for store the first inputed number, and the second one is operation variable which store what operation that currently use. Code: Dim intVal As Integer Dim intOp As Integer textbox will be store in intVal and then store the operation that you clicked into intOp. intOp = 1 mean the addition operation is used if intOp = 2 mean the subtraction operation is used, 3 for multipilcation and 4 for division. The code probally look like this: Code: Private Sub bAddtion_Click()
intOp = 1
intVal = Text1.Text
Text1.Text = ""
End Sub
Private Sub bSubtraction_Click()
intOp = 2
intVal = Text1.Text
Text1.Text = ""
End Sub
.... so on..... 4) On the equal button, the program will calculate between those two values. Code: Private Sub bEqual_Click()
Select Case intOp
Case 1:
Text1.Text = intVal + CInt(Text1.Text)
Case 2:
Text1.Text = intVal - CInt(Text1.Text)
Case 3:
Text1.Text = intVal * CInt(Text1.Text)
Case 4:
Text1.Text = intVal \ CInt(Text1.Text)
End Case
intOp = 0
End Sub click on other operations to continues calculate more number... Here the solutio. Whenever the users click on each operations button, the program will check if any operations is currently use. if there is then goto equal button first. On each operations button should be look like this Code: Private Sub bAddtion_Click()
If intOp <> 0 Then bEqual_Click()
intOp = 1
intVal = Text1.Text
Text1.Text = ""
End Sub
Private Sub bSubtraction_Click()
If intOp <> 0 Then bEqual_Click()
intOp = 2
intVal = Text1.Text
Text1.Text = ""
End Sub
.... so on..... explain. If anyone think is not the best way to do it or have any other way please give comment ![]() From siLenTz My first lovely post! |
| The Following User Says Thank You to siLenTz For This Useful Post: | ||
HelloWorld (06-26-2007) | ||
| |||
| Quote:
I am just a beginner like yourself. I took a fancy on calculators - ( right now I am trying to finish imitating the MoffSoft Calculator's core ). I will post it also, when and if I am able to finish it). There is an other Calculator ( the new era one) called Practicalc. This is something awesome for a calculator. Check it out. I got some of the screen functions coded. On the other hand, I see on this Forum programmers that can do a calculator probably in hours. I would be glad hear for them, because I certainly need some direction with PractiCalc. |
![]() |
| Thread Tools | |
| Display Modes | |
| |