-
Hmmmm.... This is a puzzle.
I have five columns on my screen, as follows (sorry, it's wrapping here):
storeID Units TotalStores AvgUnitsStore Retail ($000)
--------------------------------------------------------------------------------------------------------------------------------
txtSt(0) txtUnits(0) txtTotalStores(0) lblAvg(0) lblRetail(0)
txtSt(1) txtUnits(1) txtTotalStores(1) lblAvg(1) lblRetail(1)
txtSt(2) txtUnits(2) txtTotalStores(2) lblAvg(2) lblRetail(2)
Each column continues through an index of 7...
Note the indexes are set up the same for each element within the same storeID.
When the user opens this screen, the TotalStores column will contain a default values which can be changed... no problem. The Units column, however, will be empty until the user enters a number, which is where I could run into problems.
The AvgUnitsStore column fields lblAvg will be calculated like so:
For i = 0 to 7
lblAvg(i) =txtUnits(i) / txtTotalStores(i)
Next
When the calculation is performed, some of the txtUnits(i) fields will still be empty, which will cause an error unless I put additional instructions within the For...Next, telling it to skip the calculation for lblAvg(i) where txtUnits(i) equals null, and then to continue to the next (i).
The lblRetail( ) field will be calculated similarly in the For...Next, using a different formula.
Thanks for any and all suggestions in advance.
Tracey
-
What exactly is your problem? :confused:
-
Hmm,
To Quote:
When the calculation is performed, some of the txtUnits(i) fields will still be empty, which will cause an error unless I put additional instructions within the For...Next, telling it to skip the calculation for lblAvg(i) where txtUnits(i) equals null, and then to continue to the next (i).
:End Quote
So, Sorry for being dense, It seems you know your problem and your solution. Can you elucidate?
Seems to be a variant of the following
Patient:
"Doctor, it hurts when I do this"
Doctor:
"Then don't do that!"
-
If you use the following code, the val() ensures a value of 0 is used for the calculation instead of any null values.
For i = 0 to 7
lblAvg(i)=val(txtUnits(i) )/ val(txtTotalStores(i) )
Next
Chris
-
Code:
For i = 0 to 7
If Not IsNull(TxtUnits(i).text) then
lblAvg(i) =txtUnits(i) / txtTotalStores(i)
End If
Next
This one will just skip that textbox if it's blank which I'm not too sure if you want or not.
Code:
For i = 0 to 7
lblAvg(i).caption =val(txtUnits(i).text)/ val(txtTotalStores(i).text)
Next
Chris' example is much better, but I noticed that you're leaving vb to find the default property of the control. Instead of using Txtunits(i) try using Txtunits(i).text etc. ;)
-
you need to make sure Val(txtTotalStores(i).Text) <> 0
ie. empty or contains text.
Code:
For i = 0 To 7
If Val(txtTotalStores(i).Text) <> 0 Then
lblAvg(i).Caption = Val(txtUnits(i).Text) / Val(txtTotalStores(i).Text)
End If
Next
-
Thanks for the responses. This is exactly what I need. I'll post another rsp. to let you know how it works out.
:D Tracey