angelictorment Posted November 20, 2006 Share Posted November 20, 2006 Ok I have to code an RPN Calculator for class for my Introduction to VB .NET Class. I've been trying to get this stupid thing to work for the past few days and I keep having issues. First I get this error "Statement not valid in a namespace." I can't find any help on this. Here is part of the coding please help. Thank You! Public Class frmCalculator Inherits System.Windows.Forms.Form Dim total1 As Integer Dim total2 As Integer End Class Private Sub btnOne_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnOne.Click txtDisplay.Text = btnOne.Text End Sub Private Sub btnTwo_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnTwo.Click txtDisplay.Text = btnTwo.Text End Sub Private Sub cmdExit_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles cmdExit.Click End End Sub Private Sub btnZero_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnZero.Click txtDisplay.Text = btnZero.Text End Sub Private Sub btnThree_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnThree.Click txtDisplay.Text = btnThree.Text End Sub Private Sub btnFour_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnFour.Click txtDisplay.Text = btnFour.Text End Sub Private Sub btnFive_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnFive.Click txtDisplay.Text = btnFive.Text End Sub Private Sub btnSix_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnSix.Click txtDisplay.Text = btnSix.Text End Sub Private Sub btnSeven_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnSeven.Click txtDisplay.Text = btnSeven.Text End Sub Private Sub btnEight_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnEight.Click txtDisplay.Text = btnEight.Text End Sub Private Sub btnNine_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnNine.Click txtDisplay.Text = btnNine.Text End Sub Quote Link to comment Share on other sites More sharing options...
psychoaliendog Posted November 20, 2006 Share Posted November 20, 2006 on which line is the error occurring? I haven't programmed in VB in a couple years, but aren't the sub procedures supposed to be in the class definition? *looks it up* yup they are, that may be your problem. Quote Link to comment Share on other sites More sharing options...
angelictorment Posted November 20, 2006 Author Share Posted November 20, 2006 In the class definition? Hmmm... example please this is week 1 of VB for me... Also the error underlines all the lines. Quote Link to comment Share on other sites More sharing options...
jool Posted November 20, 2006 Share Posted November 20, 2006 What he is trying to say is that the line that says 'End Class' should be at the very end so that it encloses all the methods. Quote Link to comment Share on other sites More sharing options...
angelictorment Posted November 20, 2006 Author Share Posted November 20, 2006 Ok, thanx... :) Lets try and see then I can finish adding the rest of the code I hope. Quote Link to comment Share on other sites More sharing options...
angelictorment Posted November 20, 2006 Author Share Posted November 20, 2006 Ok now I have this issue... But first. Ok everyone, wanted to say thanx for the links and the guidance. Now here is the rest of my issue. See code below. I need to find out how to get these numbers to also display in lstBox2 along with the symbols for + - * and /. Also need to know how to make it total everything up. Like what we have to do is 9+9 in lstBox2 and to get the answer I'd have to hit +,-,*, or / to make it show 9+9=19/ Since there is no equals key for this type of calculator. HELP please... Now for the code. Public Class frmCalculator Inherits System.Windows.Forms.Form Dim total1 As Integer Dim total2 As Integer Private Sub btnOne_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnOne.Click txtDisplay.Text = txtDisplay.Text & btnOne.Text End Sub Private Sub btnTwo_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnTwo.Click txtDisplay.Text = txtDisplay.Text & btnTwo.Text End Sub Private Sub cmdExit_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles cmdExit.Click End End Sub Private Sub btnZero_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnZero.Click txtDisplay.Text = txtDisplay.Text & btnZero.Text End Sub Private Sub btnThree_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnThree.Click txtDisplay.Text = txtDisplay.Text & btnThree.Text End Sub Private Sub btnFour_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnFour.Click txtDisplay.Text = txtDisplay.Text & btnFour.Text End Sub Private Sub btnFive_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnFive.Click txtDisplay.Text = txtDisplay.Text & btnFive.Text End Sub Private Sub btnSix_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnSix.Click txtDisplay.Text = txtDisplay.Text & btnSix.Text End Sub Private Sub btnSeven_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnSeven.Click txtDisplay.Text = txtDisplay.Text & btnSeven.Text End Sub Private Sub btnEight_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnEight.Click txtDisplay.Text = txtDisplay.Text & btnEight.Text End Sub Private Sub btnNine_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnNine.Click txtDisplay.Text = txtDisplay.Text & btnNine.Text End Sub Private Sub btnPlus_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnPlus.Click total1 = total1 + Val(lstBox2.Text) txtDisplay.Clear() End Sub Private Sub cmdClear_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles cmdClear.Click txtDisplay.Clear() End Sub Private Sub btnSubtract_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnSubtract.Click total1 = total1 - Val(lstBox2.Text) txtDisplay.Clear() End Sub Private Sub btnMultiply_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnMultiply.Click total1 = total1 * Val(lstBox2.Text) txtDisplay.Clear() End Sub Private Sub btnDivide_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnDivide.Click total1 = total1 / Val(lstBox2.Text) txtDisplay.Clear() End Sub Private Sub cmdClearList_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles cmdClearList.Click lstBox2.ClearSelected() End Sub End Class Quote Link to comment Share on other sites More sharing options...
psychoaliendog Posted November 20, 2006 Share Posted November 20, 2006 <rant> In other words you want us to do your home work for you? Isn't the point of homework to learn? It you're not doing your homework, how are you supposed to make in the real world writing real programs? </rant> Alright I know you're new to programming, and it can be confusing sometimes. However the most important skill needed by a programmer is problem solving. You should be able to figure out the algorithm, it may be buggy, it may not be efficient, but you're learning all the way. Try breaking it[the problem] down into smaller pieces. Wikipedia has a lot of programming resources, http://en.wikipedia.org/wiki/RPN_calculator should get you started. Quote Link to comment Share on other sites More sharing options...
jool Posted November 20, 2006 Share Posted November 20, 2006 Well to display values you just assign it to the Text property and to add text you just add it, the behind the scenes magic will figure out that you want a string. lstBox2.Text = theValue + "a string" For a RPN calculator I would think inputting one element at a time and pressing enter after each would be the simplest way of doing it, that way you could just listen to the KeyPress event and read the input when you get a newline. Quote Link to comment Share on other sites More sharing options...
angelictorment Posted November 20, 2006 Author Share Posted November 20, 2006 <rant>In other words you want us to do your home work for you? Isn't the point of homework to learn? It you're not doing your homework, how are you supposed to make in the real world writing real programs? </rant> Well no, I just need some pointers and some input is all and a litl help along the way. This class I'm in is only 5 weeks long. Crash courses suck a$$ is all... Just wait for this next project, I think I have it done already though, I haven't tested it yet. Decimal to Binary Converter. But I'd also like to take it one step further and convert Binary to Decimal. Anyhow thanx for the help Psycho.... jool- I think I get what your saying. Thank you also... Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.