Input Values
I have created input boxes to retrieve values that are inputed by the user. After all values are inputed I have a final message box to calculate those numbers but it isn't reading the second value correctly.
Value1 = InputBox(Message, Title, Entry1)
Value2 = InputBox(Message, Title, Entry2)
Value3 = InputBox(Message, Title, Entry3)
Calculation = Calculation using Value1, Value2, Value3
Does anyone know why this is? There is nothing incorrect in the calculations.
When I enter see 62 for Value2 it is reading it as 6002.
[568 byte] By [
CB77] at [2007-11-11 10:26:10]

# 2 Re: Input Values
'Display message, title
Value1 = InputBox(Message, Title, Weight1)
Value2 = InputBox(Message, Title, Weight2)
Value3 = InputBox(Message, Title, Weight3)
'Update weights on form
Forms!frmProdnEntry!frmQuality_Checks.Form!DS1_S1 = Value1
'Display current average
AvgWgt = ([Value1] + [Value2] + [Value3]) / 3
AvgMsg = MsgBox("Average weight is:" & " " & [AvgWgt])
CB77 at 2007-11-11 17:23:38 >

# 3 Re: Input Values
U haven't declared the vlaues (value1, value2 & value3) , so it consider it as it want like in your case as string , and the '+' operation concatinate strings only :
if value1 = 5 , value2 = 6 , value3 = 7 then avgWgt = 567 !!!
to solve this it's better for ever to "decalre" any used variables (in your case u need to dealre them As Integer) and to be safe about not missing any decalrtions, put the "Option Explicit" statment .
Amahdy at 2007-11-11 17:24:47 >

# 4 Re: Input Values
The variables Value1, etc are declared as Double.......sorry, when posting my code I thought it would just be implied that they were declared.
Dim Weight1, Weight2, Weight3, Value1, Value2, Value3 As Double
The 1st and 3rd entries calculate fine it is something happening with the 2nd entry. When I enter the following: 60, 62, 63.....I get
Average weight is: 2041.66666666667
CB77 at 2007-11-11 17:25:42 >

# 5 Re: Input Values
Dim Message, Title, AvgMsg
Dim AvgWgt, Weight1, Weight2, Weight3, Value1, Value2, Value3 As Double
Message = "Enter Weight"
Title = "Weight Entry"
Value1 = InputBox(Message, Title, Weight1)
Value2 = InputBox(Message, Title, Weight2)
Value3 = InputBox(Message, Title, Weight3)
AvgWgt = ([Value1] + [Value2] + [Value3]) / 3
AvgMsg = MsgBox("Average weight is:" & " " & [AvgWgt])
End Sub
CB77 at 2007-11-11 17:26:43 >

# 6 Re: Input Values
dim a, b ,c as type will make the c only of this type .
in your post the "value3" will be the only declared as double and all other variables will be as variant .. u may not feel problems with the "first" variable because u start with it, and the third because it's really as double .
to proove this try this :
dim x,y as byte
x = 300 'ok no errors
y = 300 'error over flow because y is of type byte !
what happen in your calculations is this :
60 (variant) + 62 (variant) + 63 (double) = 6062 + 63 = 6125
6125/3 = your posted result I'm sure .
Amahdy at 2007-11-11 17:27:41 >
