|
-
Dec 4th, 2001, 10:03 PM
#1
Thread Starter
Junior Member
i am not sure what is wrong
This s my code. it is exercise 2 chapter 6 in the micrsoft vb book version 5 and 6 by the Lawrenceville Press
i need the number of times this is run put into a label, but everytime i run i highlightsthe counter = counter +1 please help thank you
Private Sub cmdcalculate_Click()
Dim initial As Double
Dim interest As Double
Dim value As Double
Dim year As Double
Dim counter As Integer
initial = txtinitial.Text
interest = txtinterest.Text
value = txtendvalue.Text
counter = 0
Do While value > year
year = (initial * (interest / 100)) + initial
counter = counter + 1
Loop
lbloutput.Caption = counter
End Sub
Private Sub Command1_Click()
Unload Me
End Sub
-
Dec 4th, 2001, 10:07 PM
#2
Frenzied Member
Which runtime error is it?
You just proved that sig advertisements work.
-
Dec 4th, 2001, 10:07 PM
#3
does it give you an error? if so what error does it give?
-
Dec 4th, 2001, 10:08 PM
#4
Thread Starter
Junior Member
run time error
it is run time error 6 overflow
-
Dec 4th, 2001, 10:19 PM
#5
then somhow your counter variable is exceding 32,000 I think try typinhg in the imedate window the following
debug.print counter and see what the value is
-
Dec 4th, 2001, 10:22 PM
#6
PowerPoster
Do While value > year
year = (initial * (interest / 100)) + initial
counter = counter + 1
Loop
The technical reason for this error, is that you try to assign counter = 32767 + 1 (Which is 1 more than the limit of an integer variable)
I don't know what this code is actually supposed to do, but the loop never ends when value > year in the first place, since nothing within the loop ever changes. AS you can see, from above, for this loop to ever exit, once it had entered, you would need to change the loop code; perhaps this is what it wants -
Code:
year = year + (initial * (interest / 100)) + initial
And is that how it was in the book?
Cause that's pretty bad coding style...
-----------------------------------------
-RJ
[email protected]
-----------------------------------------
-
Dec 4th, 2001, 10:22 PM
#7
Thread Starter
Junior Member
it dosent let me type that in in the immediate window, it just automatically goes back to the code
-
Dec 4th, 2001, 10:24 PM
#8
Frenzied Member
Make the change rjlohan stated, and it should work.
You just proved that sig advertisements work.
-
Dec 4th, 2001, 10:27 PM
#9
rjlohan is right now that I see that duh i think I need sleep now
-
Dec 4th, 2001, 10:28 PM
#10
Thread Starter
Junior Member
Thanks rjlohan it worked now
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
|