•
•
•
•
What is DaniWeb IT Discussion Community?
You're currently browsing the VB.NET section within the Software Development category of DaniWeb, a massive community of 425,926 software developers, web developers, Internet marketers, and tech gurus who are all enthusiastic about making contacts, networking, and learning from each other. In fact, there are 1,682 IT professionals currently interacting right now! Registration is free, only takes a minute and lets you enjoy all of the interactive features of the site.
Please support our VB.NET advertiser: Programming Forums
Views: 3371 | Replies: 15
![]() |
•
•
Join Date: Oct 2006
Posts: 16
Reputation:
Rep Power: 3
Solved Threads: 0
Hi,
I am a total novice to VB.Net, and have been asked to develop a simple 4 function calculator as part of my coursework.
I am really struggling!!! I would be extremely grateful if anyone could please help???
( I have managed to use AppendText to get the numbers in the display panel, but I am at a loss with the code for the functions add, minus divide and multiply)
Thanks
I am a total novice to VB.Net, and have been asked to develop a simple 4 function calculator as part of my coursework.
I am really struggling!!! I would be extremely grateful if anyone could please help???
( I have managed to use AppendText to get the numbers in the display panel, but I am at a loss with the code for the functions add, minus divide and multiply)
Thanks
•
•
•
•
I am at a loss with the code for the functions add, minus divide and multiply
Private Function Add(lhs As Integer, rhs As Integer) As Integer
Return lhs + rhs
End FunctionCInt(pnlDisplay.Text) then you can save each of the numbers punched in. Once you have 'em, you can pass 'em to the functions and push the result to the panel with something like pnlDisplay.Text = CStr(result). Easy squeezy, don't forget to check for division by zero.
•
•
Join Date: Apr 2005
Location: Old Hampshire, Old England (LOL)
Posts: 11,937
Reputation:
Rep Power: 30
Solved Threads: 268
im doing this at a level now just remember that Integer type variables are for simple math (or double type variables for more complex stuff) . Tex/string isnt and for add use +, divide use / and multiply use *
e.g
e.g
Dim var1 as double
dim var2 as double
dim ans as double
var1 = Inputbox("Enter the 1st number")
var2 = Inputbox("Enter the 2nd number")
ans = var1 * var2
msgbox "The answer is " & ans & " "
TRY MY SUGGESTIONS AT YOUR OWN RISK!
james.bennet1@ntlworld.com
james.bennet1@ntlworld.com
•
•
Join Date: Oct 2006
Posts: 16
Reputation:
Rep Power: 3
Solved Threads: 0
Thanks for replying guys..
Another problem I also have, is that the calculator is to be similar to a real one... i.e. only one display box for input & output..
I have declared Num1, Num2 and Total As DECIMAL
For the addition button, I have used the code..
Num1+= Val(txtDisplay.text)
Num2+= Val(txtDisplay.text)
then I've entered txtDisplay.Clear () to clear the display box
Then for the = button, the code: txtDisplay.text = Total
The idea being that I added the 2 numbers together and then they would be displayed when I press the = sign.
I have a feeling that I am way off guys, and ask you to forgive me for being a total novice!!
Another problem I also have, is that the calculator is to be similar to a real one... i.e. only one display box for input & output..
I have declared Num1, Num2 and Total As DECIMAL
For the addition button, I have used the code..
Num1+= Val(txtDisplay.text)
Num2+= Val(txtDisplay.text)
then I've entered txtDisplay.Clear () to clear the display box
Then for the = button, the code: txtDisplay.text = Total
The idea being that I added the 2 numbers together and then they would be displayed when I press the = sign.
I have a feeling that I am way off guys, and ask you to forgive me for being a total novice!!
•
•
•
•
I have a feeling that I am way off guys, and ask you to forgive me for being a total novice!!

I look forward to seeing your results.
•
•
Join Date: Oct 2006
Posts: 16
Reputation:
Rep Power: 3
Solved Threads: 0
•
•
•
•
No fair! For a novice you've got your head screwed on pretty good. That's basically the same setup I was thinking of, and I can boast a few more years of .NET experience.
I look forward to seeing your results.
With regards to my problem, I have found that if I make 2 display boxes (exactly the same) and then add the two values from i.e. textbox1 and textbox2 - the show the result in textbox1 (so it appears there is only 1 text box)- it works.
But is there a wrong or right way of doing things?
Using 2 display boxes seems to be an easy way out!!
I will welcome any critcal comments
•
•
Join Date: Apr 2005
Location: Old Hampshire, Old England (LOL)
Posts: 11,937
Reputation:
Rep Power: 30
Solved Threads: 268
i think maybe the proper way would be to use a control array
Last edited by jbennet : Oct 7th, 2006 at 9:23 am.
TRY MY SUGGESTIONS AT YOUR OWN RISK!
james.bennet1@ntlworld.com
james.bennet1@ntlworld.com
•
•
•
•
But is there a wrong or right way of doing things?

•
•
•
•
Using 2 display boxes seems to be an easy way out!!
Imports System
Public Class MainForm
Private _lhs As Decimal
Private _rhs As Decimal
Private _op As String
Private Sub Operator_Click(ByVal sender As Object, ByVal e As EventArgs) _
Handles btnAdd.Click, btnSub.Click, btnMul.Click, btnDiv.Click
' Set up the first half of our calculation
_lhs = CType(uOperand.Text, Decimal)
_op = DirectCast(sender, Button).Text
' Reset the input box for the next operand
uOperand.ResetText()
uOperand.Focus()
End Sub
Private Sub Result_Click(ByVal sender As Object, ByVal e As EventArgs) _
Handles btnDone.Click
' Yay! Get the second half
_rhs = CType(uOperand.Text, Decimal)
' Calculate the result
uOperand.Text = CStr(result)
End Sub
End Class•
•
Join Date: Oct 2006
Posts: 16
Reputation:
Rep Power: 3
Solved Threads: 0
I am feeling totally deflated when I read you guys' knowledge on the subject, because I am feeling very useless about my basic programming skills!!!
I want to build a basic calculator with the 4 basic functions - but can't!!!!
If anyone would be so kind as to guide a thicky like me (who has got swallowed up in it all!!) - then I promise to be the best man at their daughter's wedding!!!!!
Please explain!!!!!
I want to build a basic calculator with the 4 basic functions - but can't!!!!
If anyone would be so kind as to guide a thicky like me (who has got swallowed up in it all!!) - then I promise to be the best man at their daughter's wedding!!!!!
Please explain!!!!!
•
•
•
•
I want to build a basic calculator with the 4 basic functions - but can't!!!!
The first thing you need to do is build the interface. That's just a game of dragging controls around and playing with properties until you have a good prototype. It's a lot easier now than it used to be. After you've got the interface, you make it work by filling out the events. Do it one by one so you don't get swamped. Once that's all working, you tweak until the app is production quality. The last step is the hardest.Don't get me wrong, programming is really hard and it takes tons of dedication and passion to get good at it. The only way to learn this stuff is to slosh through the muck on your own. But it's worth every bead of sweat you shed. :cheesy:
k, that's a dreary picture. Let's say that most of the work is on your head and if you really get stuck on something specific, I can help.
![]() |
•
•
•
•
•
•
•
•
DaniWeb VB.NET Marketplace
•
•
•
•
Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
- Anyone a VB.NET Guru? (VB.NET)
- Windows .NET RC1 (Windows NT / 2000 / XP / 2003)
- digital imaging in 2k/.net? (Windows NT / 2000 / XP / 2003)
- .NET Speech SDK for ASP.NET (ASP.NET)
- Visual Basic.net (VB.NET)
Other Threads in the VB.NET Forum
- Previous Thread: Countdown Timer
- Next Thread: new to vb.net



Linear Mode