Solved

# Division by zero error

Posted on 2003-03-29
Medium Priority
134 Views
I get a "division by zero" error on this line:

M0_50 = MRest \ CDec(0.5)

M0_50 is declared as Integer and MRest as Double

Any idea ?
0
Question by:Junni
[X]
###### Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

• Help others & share knowledge
• Earn cash & points
• Learn & ask questions
• 3
• 3
• 2
• +3

LVL 70

Expert Comment

ID: 8230243
the \ is the integer division. You may want to use /.

or since you divide by .5, you may multiply by 2 to get the same result.
0

Author Comment

ID: 8230259
the M0_50 should be rounded down, not up..they told me that the \ does that, and the / rounds up !??
0

LVL 70

Expert Comment

ID: 8230269
\ is an integer division (you won't get any decimals with it)

/ is a real division.

maybe you should use m0_50 = clng(MRest)
0

Author Comment

ID: 8230271
the M0_50 should be rounded down, not up..they told me that the \ does that, and the / rounds up !??
0

Author Comment

ID: 8230276
what does the clng(MRest) ?
0

LVL 70

Expert Comment

ID: 8230279
it converts MRest as a long (it removes the decimals).
0

LVL 11

Expert Comment

ID: 8230625
M0_50 = CInt(MRest / CDec(0.5))

0

LVL 11

Accepted Solution

supunr earned 150 total points
ID: 8230628
M0_50 = CInt(MRest / CDec(0.5)) ' use this if you want the value to round to the closes integer

M0_50 = Int(MRest / CDec(0.5)) ' use this if you want only the integer part of the division, decimal will be ignored.
0

LVL 44

Expert Comment

ID: 8231319
easier, and faster:

M0_50 = CInt(MRest * 2.)
0

LVL 3

Expert Comment

ID: 8231580
"They told me", sounds like homework.
You have to tell what you want the algoritm to do?

Emorau has best answer so far...
0

LVL 101

Expert Comment

ID: 8231678
M0_50 = CInt(MRest * 2.0 -0.5)

will round down

mlmcc
0

## Featured Post

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

The debugging module of the VB 6 IDE can be accessed by way of the Debug menu item. That menu item can normally be found in the IDE's main menu line as shown in this picture.   There is also a companion Debug Toolbar that looks like the followin…
Since upgrading to Office 2013 or higher installing the Smart Indenter addin will fail. This article will explain how to install it so it will work regardless of the Office version installed.
As developers, we are not limited to the functions provided by the VBA language. In addition, we can call the functions that are part of the Windows operating system. These functions are part of the Windows API (Application Programming Interface). U…
Get people started with the process of using Access VBA to control Outlook using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Microsoft Outlook. Using automation, an Access applic…
###### Suggested Courses
Course of the Month9 days, 11 hours left to enroll

#### 762 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.