I'm having problems with if statements
present value (PV) should be no larger than $10000
interest rate is not higher than 10 and no less than 2
and number of years at least 3
I've tried the if statements with error messageboxs but I was getting confused with all the if's and the messagebox didn't show up right. The following code is my code before entering the if's. Any insight would be very helpful, thank you.
I'm assuming you want to check the values before making the call to the FV function. If that's the case, you could accomplish what you're trying to do with three simple if statements. Something like the following would probably work just fine:
PrivateSub compute_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles compute.Click
'This procedure will calculate Future Value
Dim FutureVal As Decimal
Dim PresentVal As Decimal
Dim interest As Object
Dim period As Object
PresentVal = PV.Text
interest = rate.Text
period = years.Text
IfCDbl(PresentVal) > 10000.00Then
MessageBox.Show("Present Value must not be larger than 10000")
EndSub
EndIf
IfCDbl(interest) < 2OrCDbl(interest) > 10Then
MessageBox.Show("Interest Rate must be between 2 and 10")
EndSub
EndIf
IfCInt(period) < 3Then
MessageBox.Show("The Period must be at least 3 years")
EndSub
EndIf
FutureVal = FV(PresentVal, interest, period)
lblFV.Text = FormatCurrency(FutureVal)
EndSub
If you just need something simple, this should work. You may want to change the conversions depending on what you're assuming will be input from the text fields, and you would obviously want to use some kind of exception handling anytime you're converting the text from user input into various data types.
The way I should implement is : using the LostFocus event for the textboxes. After the lostfocus you can warn a user corresponding the maximum or minimum values needed. Second is creating yourself a class in which you calculate the FV.
Either the thread starter or a moderator has marked this thread as solved. You can most likely trust the responses and answers given. There is most likely no reason for any further responses to be posted here. If you have a related question, please start a new thread in this forum instead.
This thread is more than three months old
No one has posted to this discussion for at least three months. Please let old threads die and do not reply to them unless you feel you have something new and valuable to contribute that absolutely must be added to make the discussion complete. Otherwise, please start a new thread in this forum instead.