473,388 Members | 1,230 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,388 software developers and data experts.

IDIV - divide be zero: error handling

Hello.
I've got a problem. My software crashes and maybe it's because IDIV instruction - division by 0. Please help me how to handle it in VB6 (check value before dividing) . I found articles on that but only Java and C++ and nothing about VB6.
Best regards
Edit/Delete Message
Aug 28 '06 #1
5 9673
Hemant Pathak
92 Expert
Hi..............
First check ur datatype if Datatype is String then simly check
if VariableName="0" then
otherwise
if VaribleName=0 then

thats all

if it is not working then send me us Validation Code i will try..........
at this email address..
pathak.pathak@gmail.com
Aug 29 '06 #2
sashi
1,754 Expert 1GB
Hi there,

This is when error handling comes handy, please refer to below code segment, hope it helps to solve your problem.. take care my fren.. :)

Division by Zero generates error number 6, which means you need to trap this error number in order to prevent your application from crashing, rite?

Expand|Select|Wrap|Line Numbers
  1. ublic Sub OnErrorDemo()
  2.    On Error GoTo ErrorHandler   ' Enable error-handling routine.
  3.    Dim x As Integer = 32
  4.    Dim y As Integer = 0
  5.    Dim z As Integer
  6.    z = x / y   ' Creates a divide by zero error
  7.    On Error GoTo 0   ' Turn off error trapping.
  8.    On Error Resume Next   ' Defer error trapping.
  9.    z = x / y   ' Creates a divide by zero error again
  10.    If Err.Number = 6 Then
  11.       ' Tell user what happened. Then clear the Err object.
  12.       Dim Msg As String
  13.       Msg = "There was an error attempting to divide by zero!"
  14.       MsgBox(Msg, , "Divide by zero error")
  15.       Err.Clear() ' Clear Err object fields.
  16.    End If
  17. Exit Sub      ' Exit to avoid handler.
  18. ErrorHandler:  ' Error-handling routine.
  19.    Select Case Err.Number   ' Evaluate error number.
  20.       Case 6   ' Divide by zero error
  21.          MsgBox("You attempted to divide by zero!")
  22.          ' Insert code to handle this error
  23.       Case Else
  24.          ' Insert code to handle other situations here...
  25.    End Select
  26.    Resume Next  ' Resume execution at same line
  27.                 ' that caused the error.
  28. End Sub
  29.  
Aug 30 '06 #3
Hello.

My error is internal error - I cannot trap it inside VB because whole VB crashes. Thank you for your help but this time simple error handler can't do the job.
Best regards
Aug 30 '06 #4
sashi
1,754 Expert 1GB
Hi there,

if this type error handler is not good enough to trap error, then i don't know on how to help you.. take care my fren..
Aug 30 '06 #5
Hi!
I heave almost the same problem! but my Msg Error is the 11th, I have some Textboxes and I did a division between those controls!

ex: Text3= Val( Text1* 1000) / Val(Text2)
but Text2=0
is not a string datatype, I made my DB in Access and the Dtype was Numeric
Int so I don't know whats going on!!!!

Please help with these problem!!!
Thanks
Sep 4 '06 #6

Sign in to post your reply or Sign up for a free account.

Similar topics

3
by: Ryan | last post by:
I have the following line in a select statement which comes up with a divide by zero error. CAST(CASE Splinter_Status WHEN 'SUR' THEN 0 ELSE CASE WHEN Sacrifice>=1 THEN...
2
by: Mike Leahy | last post by:
All... I have a query that calculates various using variables from a survey database. As with any survey, there are many instantces of null values. I'm wondering if there is any way to escape...
0
by: Gary Carson | last post by:
Can anyone tell why the query below would throw a divide-by-zero error? The only reason I can see for the error happening would be if SUM() came out to be zero, but this never happens with the...
5
by: Neo | last post by:
Hi Friends, I am trying following code int main(void) { try { int i,j,k; i=10; j=0;
2
by: Omar Abid | last post by:
Reason of this project: Error handling is one of the most difficult thing that may afford a programmer. It isn't as easy as you think and handling errors in a program some time can make errors...
1
by: stephen | last post by:
Hi, I am a lil confused about exception handling. I have a main app and i am importing 2 DLL's. one of the DLL's is for connection/datasets etc and the other has logging errors to file.Both...
11
by: pereges | last post by:
Hi, I have written a small function that can (I think) deal with overflow/underflow while adding integers and divide by zero problem. Can some one please tell me if I have done it correctly ? Would...
4
by: raylopez99 | last post by:
See comment below. This is a simple problem but I'm a little rusty. How to break out of a event loop (here _Paint)? I've tried if/else, case, etc but not quite what I want--I keep getting the JIT...
1
by: zufie | last post by:
Help! How do I divide by zero on my form (in a text box). That is, how do I carry out a division problem when the denominator is zero? Thanks!, John
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.