Hi,
I started on the Main Form with the Add button, but I do know I'm missing something. Arguments? I'm just unsure of what goes into the argument if it is a user-defined value. I wanted to see what I was missing before finishing the rest of the buttons. Is this the right direction?
Not a bad effort for a first time but you do seem to have made a few mistakes based on what you are trying to do. Let's start with the MathOP class:-
1) You define 3 private variables and then create a Constructor to populate those 3 variables when a New instance of your class is declared. This is fine when you NEED to have a class declared with incoming values but in your case I would suggest that you do not need this constructor since you cannot get any results out of the class until you call additional methods later on in your code. Even if you do decide to leave it like this then you should NOT be expecting an incoming argument called Result since what you will be returning from the class, via your methods, will be the result of the various calculations.
2) So, considering point 1 above, and looking at your Public Sub Add routine. The first thing to remember is the difference between a Sub and a Function. That being that a Function can return a value to the routine that called it whereas a Sub Cannot. So another way to declare your Add routine is to declare it as a Function, which accepts two arguments being FirstNum and SecondNum and then returns a Value being the Result of the Functions work.
Now if you followed these two points you could now have a class that looks like this:-
Public Class MathOP
'Add method
Public Function Add(ByVal FirstNum As Single, ByVal SecondNum As Single) As Single
Return FirstNum + SecondNum
End Function
End Class
You could then use this class in your Form like this:-
Private Sub btnAdd_Click(sender As System.Object, e As System.EventArgs) Handles Button1.Click
Dim myMathClass As New MathOP
lblResult.Text = myMathClass.Add(CSng(txtFirstNum.Text), CSng(txtSecondNum.Text)).ToString
End Sub
Note: You should also always do Data Validation when obtaining information from the user interface by using TryParse of the Numeric Type that you are expecting, but I have skipped that part here since I do not know whether you have touched on that as yet?
3) Now that you have got that far you can then expand the class to add as many calculation methods as you need returning the correct result of the calculation to the calling routine.
Also, the save button is supposed to save the current equation, and the display button adds it to a list box.
One way to do this is to again expand your class to have a ReadOnly Property that will return the Equation that has just been used in any given calculation. So when you call the Add Function, or any other function, you can build the equation and save that equation to this property before you Return the result of your calculation. So, your class could now look like this:-
Public Class MathOP
Private _EquationUsed As String
Public ReadOnly Property EquationUsed As String
Get
Return _EquationUsed
End Get
End Property
'Add method
Public Function Add(ByVal FirstNum As Single, ByVal SecondNum As Single) As Single
_EquationUsed = FirstNum.ToString & " + " & SecondNum.ToString & " = " & (FirstNum + SecondNum).ToString
Return FirstNum + SecondNum
End Function
End Class
And your Form1 may look like this:-
Private Sub btnAdd_Click(sender As System.Object, e As System.EventArgs) Handles Button1.Click
Dim myMathClass As New MathOP
lblResult.Text = myMathClass.Add(CSng(txtFirstNum.Text), CSng(txtSecondNum.Text)).ToString
ListBox1.Items.Add(myMathClass.EquationUsed)
End Sub
Hope that helps.
Cheers,
Ian
BTW, Turn Option Strict On in your projects to help you avoid bad habits and also please enclose you Code in Code Tags when posting to the Forum.