Incorrect values returned

E

eschloss

Access 2003

I have not been able to figure why I get different results when I use a
variable name as opposed to the variable value. For example, the first
instance gives the following incorrect values:

Dim cal_width As Single
Dim cal_space As Single
Dim buffer As Single

cal_width = ((6.5 * 1440) - buffer - (cal_space * 2)) / 9
cal_space = 0.25 * 1440
buffer = 0.01 * 1440

The incorrect results I get back are:
cal_width: 1040
cal_space: 360
buffer: 14.4

I can only get the correct values when I use the following:
Dim cal_width As Single
Dim cal_space As Single
Dim buffer As Single

cal_width = ((6.5 * 1440) - (0.01 * 1440) - ((0.25 * 1440) * 2)) / 9
cal_space = 0.25 * 1440
buffer = 0.01 * 1440

The correct results I get back are:
cal_width: 958.4
cal_space: 360
buffer: 14.4

Is this a simple syntax issue? I have tried different declarations and
using different type conversion functions only to get the same incorrect
result.

Thank you.
 
S

Steve Sanford

Its because in your first example, the values for buffer and cal_space are
null.

You need to have the two variables **before** the formula:

Dim cal_width As Single
Dim cal_space As Single
Dim buffer As Single

buffer = 0.01 * 1440
cal_space = 0.25 * 1440
cal_width = ((6.5 * 1440) - buffer - (cal_space * 2)) / 9

results
cal_width: 958.4
cal_space: 360
buffer: 14.4


HTH
 
E

eschloss

Thanks Steve.

Steve Sanford said:
Its because in your first example, the values for buffer and cal_space are
null.

You need to have the two variables **before** the formula:

Dim cal_width As Single
Dim cal_space As Single
Dim buffer As Single

buffer = 0.01 * 1440
cal_space = 0.25 * 1440
cal_width = ((6.5 * 1440) - buffer - (cal_space * 2)) / 9

results
cal_width: 958.4
cal_space: 360
buffer: 14.4


HTH
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top