|
-
Feb 19th, 2006, 04:14 PM
#1
Thread Starter
New Member
-
Feb 19th, 2006, 04:58 PM
#2
Re: Math Practice
VB Code:
Private Sub btnCheck_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles btnCheck.Click
Dim answer As Integer 'This guy here never gets a value.
[b]Me.txtAnswer.Text = result
result = Val(Me.txtAnswer.Text)[/b]' Here you set txtanswer.txt to result.. then result to txtanswer.text?
compareSum(answer) 'Yet you call the sub with it.
End Sub
Sub compareSum(ByVal answer As Integer) 'This guy is then passed zero.
If result <> answer Then 'So this guy will almost always fire.
lblMessage.Text = "Incorrect"
End If
If answer = result Then
lblMessage.Text = "Correct"
End If
End Sub
There are a few problems I see right off the bat. (I made comments above). One thing you might consider doing is to just think it all through logically, then throw down the code to do what you want. Even writing it down can help sometimes. Also, this subsection of the forum is typically for language independent math logic and whatnot.. you should probably post this kind of stuff in the VB.NET forum 
Welcome aboard,
Bill
-
Feb 19th, 2006, 05:47 PM
#3
Re: Math Practice
It looks to me as though your big problem is variable declaration. Declaring answer as integer in the add button means that it will only retain its value whilst this sub is running. Similarly in your comparesum sub you use result to check against answer - but result has not been assigned a value within this sub. There are ways around this - first of all you don't need result at all - simply compare answer with the textbox. You may want to beware with Val, because this converts to the Double number format, which may differ slightly in a very small decimal place from the integer value. You can also declare variables outside of the subs - simply move it to a module or to the top of the class in which you are working. You might want to use the Friend declaration for answer in this case.
Hope that gives you some ideas on where to look.
zaza
-
Feb 21st, 2006, 06:29 PM
#4
Thread Starter
New Member
Re: Math Practice
thanks for the help. I figured my problem was in the declaring of my variables. I corrected it, and now it works perfectly. Thanks again.
I am now trying to write a program dealing with guessing a number. I am suppose to use a random number generator to determine the number to be guessed. It should be between 1 and some upperbound. I need to use the Math. log function to determine the logarithm of a number.
My question is exactly how would I use this Math.log function to determine the logarithm. I need to get an understanding of this before I begin.
Any information you all can give me to point me in the direction I need to go will be much appreciated.
Thanks
computer_mom44
-
Feb 21st, 2006, 06:30 PM
#5
Re: Math Practice
Just don't forget to use [VBCODE] [/VBCODE] tags around your VB code.
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|