User Name Password Register
DaniWeb IT Discussion Community
All
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
Reply
Join Date: Oct 2006
Posts: 16
Reputation: Jupiter247 is an unknown quantity at this point 
Rep Power: 3
Solved Threads: 0
Jupiter247 Jupiter247 is offline Offline
Newbie Poster

Help VB.Net

  #1  
Oct 6th, 2006
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
AddThis Social Bookmark Button
Reply With Quote  
Join Date: Sep 2006
Posts: 90
Reputation: Inanna is on a distinguished road 
Rep Power: 3
Solved Threads: 6
Inanna's Avatar
Inanna Inanna is offline Offline
Junior Poster in Training

Re: VB.Net

  #2  
Oct 6th, 2006
I am at a loss with the code for the functions add, minus divide and multiply
kk, the functions themselves are easy. Just do some such like this.
Private Function Add(lhs As Integer, rhs As Integer) As Integer
    Return lhs + rhs
End Function
If you pull numbers from the display panel with something like CInt(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.
Reply With Quote  
Join Date: Apr 2005
Location: Old Hampshire, Old England (LOL)
Posts: 11,937
Reputation: jbennet is a jewel in the rough jbennet is a jewel in the rough jbennet is a jewel in the rough jbennet is a jewel in the rough 
Rep Power: 30
Solved Threads: 268
Moderator
Featured Poster
jbennet's Avatar
jbennet jbennet is offline Offline
Microsoft Fanboy

Re: VB.Net

  #3  
Oct 6th, 2006
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

 
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
Reply With Quote  
Join Date: Oct 2006
Posts: 16
Reputation: Jupiter247 is an unknown quantity at this point 
Rep Power: 3
Solved Threads: 0
Jupiter247 Jupiter247 is offline Offline
Newbie Poster

Re: VB.Net

  #4  
Oct 6th, 2006
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!!
Reply With Quote  
Join Date: Sep 2006
Posts: 90
Reputation: Inanna is on a distinguished road 
Rep Power: 3
Solved Threads: 6
Inanna's Avatar
Inanna Inanna is offline Offline
Junior Poster in Training

Re: VB.Net

  #5  
Oct 6th, 2006
I have a feeling that I am way off guys, and ask you to forgive me for being a total novice!!
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.
Reply With Quote  
Join Date: Oct 2006
Posts: 16
Reputation: Jupiter247 is an unknown quantity at this point 
Rep Power: 3
Solved Threads: 0
Jupiter247 Jupiter247 is offline Offline
Newbie Poster

Re: VB.Net

  #6  
Oct 7th, 2006
Originally Posted by Inanna View Post
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
Reply With Quote  
Join Date: Apr 2005
Location: Old Hampshire, Old England (LOL)
Posts: 11,937
Reputation: jbennet is a jewel in the rough jbennet is a jewel in the rough jbennet is a jewel in the rough jbennet is a jewel in the rough 
Rep Power: 30
Solved Threads: 268
Moderator
Featured Poster
jbennet's Avatar
jbennet jbennet is offline Offline
Microsoft Fanboy

Re: VB.Net

  #7  
Oct 7th, 2006
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
Reply With Quote  
Join Date: Sep 2006
Posts: 90
Reputation: Inanna is on a distinguished road 
Rep Power: 3
Solved Threads: 6
Inanna's Avatar
Inanna Inanna is offline Offline
Junior Poster in Training

Re: VB.Net

  #8  
Oct 7th, 2006
But is there a wrong or right way of doing things?
The only wrong way is the one that doesn't meet your requirements. Anything else is fair game.
Using 2 display boxes seems to be an easy way out!!
Using 2 boxes is harder, I think. You have to keep track of multiple input controls when you really only need one. Ignoring the tricky user interface details that make an app usable, your form really doesn't need more than this.
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
Reply With Quote  
Join Date: Oct 2006
Posts: 16
Reputation: Jupiter247 is an unknown quantity at this point 
Rep Power: 3
Solved Threads: 0
Jupiter247 Jupiter247 is offline Offline
Newbie Poster

Re: VB.Net

  #9  
Oct 7th, 2006
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!!!!!
Reply With Quote  
Join Date: Sep 2006
Posts: 90
Reputation: Inanna is on a distinguished road 
Rep Power: 3
Solved Threads: 6
Inanna's Avatar
Inanna Inanna is offline Offline
Junior Poster in Training

Re: VB.Net

  #10  
Oct 7th, 2006
I want to build a basic calculator with the 4 basic functions - but can't!!!!
Windows Forms apps are pretty basic. 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.
Reply With Quote  
Reply

Only community members can participate in forum threads. You must register or log in to contribute.

DaniWeb VB.NET Marketplace
Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)

 

Thread Tools Display Modes

Similar Threads
Other Threads in the VB.NET Forum

All times are GMT -4. The time now is 9:02 pm.
Forum system based on vBulletin Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
©2003 - 2008 DaniWeb® LLC