Results 1 to 10 of 10

Thread: i am not sure what is wrong

  1. #1

    Thread Starter
    Junior Member
    Join Date
    Dec 2001
    Posts
    18

    Angry 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

  2. #2
    Frenzied Member nishantp's Avatar
    Join Date
    Jan 2001
    Location
    Where you least expect me to be
    Posts
    1,375
    Which runtime error is it?
    You just proved that sig advertisements work.

  3. #3
    egiggey
    Guest
    does it give you an error? if so what error does it give?

  4. #4

    Thread Starter
    Junior Member
    Join Date
    Dec 2001
    Posts
    18

    run time error

    it is run time error 6 overflow

  5. #5
    egiggey
    Guest
    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

  6. #6
    PowerPoster rjlohan's Avatar
    Join Date
    Sep 2001
    Location
    Sydney, Australia
    Posts
    3,205

    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]
    -----------------------------------------

  7. #7

    Thread Starter
    Junior Member
    Join Date
    Dec 2001
    Posts
    18
    it dosent let me type that in in the immediate window, it just automatically goes back to the code

  8. #8
    Frenzied Member nishantp's Avatar
    Join Date
    Jan 2001
    Location
    Where you least expect me to be
    Posts
    1,375
    Make the change rjlohan stated, and it should work.
    You just proved that sig advertisements work.

  9. #9
    egiggey
    Guest
    rjlohan is right now that I see that duh i think I need sleep now

  10. #10

    Thread Starter
    Junior Member
    Join Date
    Dec 2001
    Posts
    18
    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
  •  



Click Here to Expand Forum to Full Width