×
INTELLIGENT WORK FORUMS
FOR COMPUTER PROFESSIONALS

Contact US

Log In

Come Join Us!

Are you a
Computer / IT professional?
Join Tek-Tips Forums!
  • Talk With Other Members
  • Be Notified Of Responses
    To Your Posts
  • Keyword Search
  • One-Click Access To Your
    Favorite Forums
  • Automated Signatures
    On Your Posts
  • Best Of All, It's Free!

*Tek-Tips's functionality depends on members receiving e-mail. By joining you are opting in to receive e-mail.

Posting Guidelines

Promoting, selling, recruiting, coursework and thesis posting is forbidden.

Students Click Here

Division by zero

Division by zero

Division by zero

(OP)
I keep getting a 'division by zero error' in this code:

FOR a% = 0 to 1800
  IF bt(a%) = 0 THEN bt(a%) = .01
  tangent(a%) = ct(a%) / bt(a%)
NEXT

I don't understand how that is possible, could somebody help me out?

If a man says something in the forest and no woman hears it is he still wrong?

RE: Division by zero

Hey. I need to know what "bt" and "ct" are. I can't figure it out without the values. Obviously the program is trying to divide something by zero, but without the other values I can't find the error.

Doug

RE: Division by zero

Maybe I'm presumptious but "bt/tangent/ct" are ARRAYS.  But, I too need the numbers as well.  

All I keep getting is "subscript out of range" and it stops at A% = 11.  

So, I changed the % [which is for INTEGER data types] to a "low floating point" variable by using the ! [which is for SINGLE data types] because you are using a fraction (".01") in your IF clause.

Also, the FOR/NEXT will NOT BREAK OUT until it reaches 1 number higher than the number it was told to count upto (see note after test code)


'--------start test
CLS

DIM Bt!(1801), Ct!(1801), Tangent!(1801)

FOR a! = 0 TO 1800
  IF Bt(a!) = 0 THEN Bt(a!) = .01
  Tangent(a!) = Ct(a!) / Bt(a!)
NEXT

PRINT "The total counted: ";
PRINT a!
'--------end test

if you run the above the a! should show you 1801--double check your arrays, are they high enough? redimmed higher?.

--MiggyD

RE: Division by zero

(OP)
FOR t% = 0 TO 1800
   bt(t%) = COS(t% * ATN(1) / 225)
   ct(t%) = SIN(t% * ATN(1) / 225)
NEXT t%
st(0) = 10 ^ -9
st(900) = st(0)
st(1800) = st(0)
ct(450) = st(0)
ct(1350) = st(0)

The values for ct() and bt() have been BSAVEd, so I couldn't get them directly.  I am pretty sure that these are the equations I used to get them.

If a man says something in the forest and no woman hears it is he still wrong?

RE: Division by zero

put it together as


DIM bt(1800), ct(1800), tangent(1800), st(1800)

FOR t% = 0 TO 1800
   bt(t%) = COS(t% * ATN(1) / 225)
   ct(t%) = SIN(t% * ATN(1) / 225)
NEXT t%
st(0) = 10 ^ -9
st(900) = st(0)
st(1800) = st(0)
ct(450) = st(0)
ct(1350) = st(0)

FOR a% = 0 TO 1800
   IF bt(a%) = 0 THEN bt(a%) = .01
   tangent(a%) = ct(a%) / bt(a%)
NEXT



- it doesn't say any error in QB 1.1!

Red Flag This Post

Please let us know here why this post is inappropriate. Reasons such as off-topic, duplicates, flames, illegal, vulgar, or students posting their homework.

Red Flag Submitted

Thank you for helping keep Tek-Tips Forums free from inappropriate posts.
The Tek-Tips staff will check this out and take appropriate action.

Reply To This Thread

Posting in the Tek-Tips forums is a member-only feature.

Click Here to join Tek-Tips and talk with other members! Already a Member? Login

Close Box

Join Tek-Tips® Today!

Join your peers on the Internet's largest technical computer professional community.
It's easy to join and it's free.

Here's Why Members Love Tek-Tips Forums:

Register now while it's still free!

Already a member? Close this window and log in.

Join Us             Close