Welcome!

Join our community of MMO enthusiasts and game developers! By registering, you'll gain access to discussions on the latest developments in MMO server files and collaborate with like-minded individuals. Join us today and unlock the potential of MMO server development!

Join Today!

[VB6] Preventing Division By Zero

Newbie Spellweaver
Joined
Oct 16, 2008
Messages
85
Reaction score
0
I had a thread up before and someone answered me but it was deleted so when I came back for reference it wasn't there. Can someone tell me what had to be done? I remember a pseudo code or something.

Anyway the problem was:

If I run my program and click the calculate command without entering any integers (therefore I am dividing by zero) my program Breaks.

What is the code to prevent division my zero?
 
Custom Title Activated
Loyal Member
Joined
Jun 28, 2007
Messages
2,986
Reaction score
3
Make a function which takes 2 numbers. Check the second number and see if it's zero. If so, throw an exception, if not, divide and return the result.
 
Newbie Spellweaver
Joined
Oct 16, 2008
Messages
85
Reaction score
0
I don't get it @_@ Look at my other post... It has the code.


I don't even know how to write a function....
 
i didnt do this.
Loyal Member
Joined
Jul 19, 2007
Messages
2,023
Reaction score
345
huh so you wanting to Divide by Zero? the code for a calculator is like

text3.text = val(text1.text) / val(text2.text)

is that what u mean??
 
Skilled Illusionist
Loyal Member
Joined
Jun 23, 2007
Messages
310
Reaction score
1
Check whether numOne or numTwo are 0 and if either/both are, just throw an error.

Code:
if(numOne == "0" || numTwo == "0")
{
cout << "Cannot divide by zero.";
} else {
//Contiune to show answer.
}
Just add that code into the section where it checks for division.
 
Banned
Banned
Joined
Jun 24, 2008
Messages
723
Reaction score
1
Code:
public function checkforzero(num1 as string, num2 as string)
if num1 = "0" or num2 = "0" then
msgbox "you can't use 0 - Monsta.", vbexclamation + vbokonly
else
form1.lblanswer.caption = val(num1) / val(num2)
end if
end function

Don't know, just made it up, try it ^^
 
Back
Top