Odd Value

  • Thread starter George W. Barrowcliff
  • Start date
G

George W. Barrowcliff

2007
I have an access data base with dimensions of an item.
Field names height, width, length and volume.
Form fields are populated by height, weight and length

Software should calculate cubic feet volume.

All 4 db fields are dimensioned as long integers.

Running Debug shows Width as 12224 and type integer.

Height, Length and Volume are type: Object/Text Box

A local variable cuFT is dim long, and set:
cuFt = 12 * 12 * 12

I have tried renaming the db column as WidthX but no difference. I know
this is a simple mistake but I have not been able to fix it.

Also, is this allowed in VB: Volume = Volume / 100
I think that is illegal syntax in VB since the result is always 0

Thanks In Advance
 
G

George

I've read this three times, and maybe I'm just a bit slow, but I can't quite
figure out what you first question is.

The answer to your second question is that the syntax is okay. Basically it
is an assignment of a value to the "Volume" variable to be the result of
dividing the initial value of the variable by 100. Perfectly lgal. The fact
that it appears to be returning a value (e.g. 0) rather than throwing an
error lends support to the notion that it is working as expected. The fact
that it always returns 0 probably means that "Volume" is always 0. Dividing
0 by any value will always return an answer of 0.

Please post back with a more complete statement of the other problem you are
trying to solve.

Thanks.
 
G

George W. Barrowcliff

OK, here is the code triggered when I enter the form Volume box.
I added the VolumeX variable so I could see if Volume = Volume / cuFt was
legitimate and you are correct. It is OK.

height, width, length, and volume are all fields in the data base.

Width always has the value 12254 and is type integer, while height, lengtth
and volume are all object/text box type.

I deleted the entire form, re made it with no difference.

I deleted the width column, then added it back in with no difference.

for a while I thought it might be a reserved value defined some where else
but none of my documentation indicates this.

Hope this is clearer.

GWB




Private Sub Volume_Enter()
Dim cuFt As Single
Dim VolumeX As Single


cuFt = 12 * 12 * 12
If Height > 0 And Length > 0 And Width > 0 Then
VolumeX = Height * Length * Width
Else
VolumeX = 0
End If
If VolumeX > 0 Then
Volume = VolumeX / cuFt
End If
End Sub
 
T

Tom van Stiphout

On Mon, 21 Sep 2009 17:41:16 -0700, "George W. Barrowcliff"

I also have a very hard following your problem description. It appears
you have a table with H, W, L and Volume columns. That is a mistake.
As a calculated value the volume does not belong in a table, but in a
query. So keep the 3 dimensions in a table, and any time you need to
calculate or display volume simply use a query, with a column like
this:
Volume: Height * Width * Length

Of course you will be careful about the unit of measure. If you want
the volume in cuFt then you either enter H, W, L as feet, or you apply
a conversion factor. E.g. if you have those in inches your expression
would change to:
Volume: Height * Width * Length / (12*12*12)

Also note that with long integers you don't get very far; Volume will
likely be a fractional value. Using Double throughout may be your best
bet.

-Tom.
Microsoft Access MVP
 
J

John Spencer

If you are doing this in a form, then you could be running into the fact that
forms have a width property. So referring to Width as you have is going to be
ambiguous.


John Spencer
Access MVP 2002-2005, 2007-2009
The Hilltop Institute
University of Maryland Baltimore County
 
G

George W. Barrowcliff

Thanks Gina. My reference didn't say anthing about Width being a reserved
word, but I changed all the variables.

Once I could see what was happening, I tightened up the statements,
dropped extra variables etc and this is what is working for me. It took me
a while to find a definition of what event happens when the data in a form
changes when scrolling through the data but Form_Current seems to be the
right one.

George

Function CalcVol() As Double
Dim DblVolume As Double

' Calculates the square foot volume with field data in inches
' The single integer sqlCuFt is calculated when the form is opened as
Public Const
If invHt > 0 And invLn > 0 And invWd > 0 Then
CalcVol = (invHt * invLn * invWd) / sglCuFt
Else
CalcVol = 0
End If
End Function


Private Sub Form_Current()
' With change in data, recalculate Volume Field
Volume = CalcVol()
End Sub
 

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