|
-
Apr 8th, 2001, 05:19 PM
#1
Thread Starter
New Member
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
-
Apr 8th, 2001, 05:41 PM
#2
Addicted Member
What exactly is your problem?
Code that I author is neither elegant nor efficient. It is, however, functional. Once I get something that works, I'm generally satisfied with myself - I mean, if it works, that's good enough, right?
Originally posted by aknisely
Sorry, but I feel uncomfortable on CC with clothes on
__________________
The truth ... is out there!
-
Apr 8th, 2001, 06:24 PM
#3
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!"
-
Apr 9th, 2001, 04:10 AM
#4
Addicted Member
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
-
Apr 9th, 2001, 04:38 AM
#5
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.
Last edited by alex_read; Apr 9th, 2001 at 04:44 AM.
-
Apr 9th, 2001, 07:40 AM
#6
Frenzied Member
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
-
Apr 9th, 2001, 09:35 AM
#7
Thread Starter
New Member
Thanks for the responses. This is exactly what I need. I'll post another rsp. to let you know how it works out.
Tracey
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|