Infinity / Divide by Zero

bones

Well-known member
Joined
Aug 23, 2014
Messages
143
Programming Experience
Beginner
I have a situation where dividing by zero can't be avoided until the user enters a value into a textbox. My DGV formulated cell values need the textbox value to complete their math functions. Thus until that happens, "Infinity" populates the respective DGV cells...I read a few articles on how VS2010 handles this differently than earlier versions.

No problems with the code running in debug. The DGV cells show infinity until the required textbox data is input. Then all is well.

Question - Will there be compile issues if this is left not addressed?

Suggestions or pointers to links containing solutions to such situation would be appreciated.

I just don't see a way around it. The formulas are what they are and they can't be altered. Have thought about hiding the word infinity by masking the cell fore color with an if statement... thoughts on that?
 
VS2010 handles this differently than earlier versions
Nothing has changed that I know of.
No problems with the code running in debug.
Question - Will there be compile issues if this is left not addressed?
Debug can only follow a compile, application can't run if it wasn't first successfully compiled. When debugging IDE executes the compiled assembly and attaches debugger, allowing for inspecting app state and error conditions during run.
I just don't see a way around it. The formulas are what they are and they can't be altered.
Use If statement to check for condition and act upon that. You could check if relevant textbox has some value, or you could check if part of formula expression is valid, or you could check if result has a valid value, all this can happen before you assign something to grid cell.
user enters a value into a textbox
Why use TextBox control for numeric input from user? I recommend the NumericUpDown control instead. If not you should validate/TryParse input before using it.
 
When VB changed to .Net is when MS removed the Divison By Zero error and incorporated the more accurate ways of handling such computations. Only integer division (a\b instead of a/b) has maintained this error. Otherwise, if the equation is 0/0, that results in NAN (Not a Number), and X/0 results in +/- Infinity (where X is any number; if X<0, the result being a negative infinity). Regardless, the program will still compile.
 
Back
Top