|
-
Mar 8th, 2007, 02:43 PM
#1
Thread Starter
PowerPoster
check cells before division by zero
I want to make sure of no divison by zero error messages
I am doing division on a mshflexgrid like this:
with grid
.textmatrix(2, 12) = .textmatrix(2, 11) / .textmatrix(2, 9)
some of the cells maybe empty and some maybe formated as currency with a dollar sign
is this the best method:
vb Code:
If val(.textmatrix(2, 11) <> 0 then
If val(.textmatrix(2, 9) <> 0 then
.textmatrix(2, 12) = .textmatrix(2, 11) / .textmatrix(2, 9)
else
textmatrix(2, 12) = ""
end if
end if
would this code be appropriate?
Last edited by Hack; Mar 8th, 2007 at 02:48 PM.
Reason: Added VB Highlight Tags and Indenting
-
Mar 8th, 2007, 02:47 PM
#2
Re: check cells before division by zero
 Originally Posted by isnoend07
would this code be appropriate?
It looks Ok. Does it work? Are you havinga problem?
-
Mar 8th, 2007, 02:55 PM
#3
Thread Starter
PowerPoster
Re: check cells before division by zero
 Originally Posted by Hack
It looks Ok. Does it work? Are you havinga problem?
Yes i am having having a problem, but i am not sure if this is it.
I have a huge program with about 50 of these. It has gotton very hard to
debug. Many are if this chbox is checked then divide by this cell if not divide by this cell etc, etc....
-
Mar 8th, 2007, 03:17 PM
#4
Thread Starter
PowerPoster
Re: check cells before division by zero
 Originally Posted by isnoend07
Yes i am having having a problem, but i am not sure if this is it.
I have a huge program with about 50 of these. It has gotton very hard to
debug. Many are if this chbox is checked then divide by this cell if not divide by this cell etc, etc....
After experimenting i have found this code will fail if val(contents) is formatted as currency. It will return 0 even though it contains a valid number
-
Mar 8th, 2007, 05:04 PM
#5
Re: check cells before division by zero
Consider using the INSTR function to determine if any number other than zero exists in the cell string. If it does, you can then next pinpoint the starting position of the first non-zero integer and determine the value of the midstring using Val from that point on.
It's rather amazing what we have to do sometimes to evaluate strings.
-
Mar 8th, 2007, 07:46 PM
#6
Thread Starter
PowerPoster
Re: check cells before division by zero
 Originally Posted by Edwin Hackleman
Consider using the INSTR function to determine if any number other than zero exists in the cell string. If it does, you can then next pinpoint the starting position of the first non-zero integer and determine the value of the midstring using Val from that point on.
It's rather amazing what we have to do sometimes to evaluate strings. 
I have decided to use currency only for totals and not subtotals. Saves a lot of ifs
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
|