473,327 Members | 1,919 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,327 software developers and data experts.

division by zero

Hello everyone this is my first post.

My problem is dividing a variable with another variable when the last variable is a decimal. The program returns "division with zero" even though its not zero at all.

Public firstvariable As Long
Public secondvariable As Long
laks = 100
discolaks = 0.3
willcausethebug = firstvariable / secondvariable
Apr 25 '07 #1
4 2222
Tig201
103 100+
use \ as apposed to /
\ = Division (float)
/ = Division (integer)
Apr 25 '07 #2
Tig201
103 100+
Sorry I got dyslexic yours is correct
/ = Division (float)
\ = Division (integer)
Apr 25 '07 #3
Tig201
103 100+
you need do dim as double not long
Apr 25 '07 #4
Killer42
8,435 Expert 8TB
Hello everyone this is my first post.

My problem is dividing a variable with another variable when the last variable is a decimal. The program returns "division with zero" even though its not zero at all.

Public firstvariable As Long
Public secondvariable As Long
laks = 100
discolaks = 0.3
willcausethebug = firstvariable / secondvariable
Ok, at first glance there are two bugs here.
  1. The variables you used are not the ones you defined.
    Since secondvariable was never assigned a value, of course it is zero.
    You should always keep the "require explicit variable declaration" option turned on to prevent this sort of bug. If it's off, whenever you refer to a variable VB will just go ahead and create it for you. Usually meaning that if you use the wrong name it will take ages to work out what's wrong. If it's on, this code will simply refuse to compile, with the message "variable not defined".
  2. Assuming you meant to use secondvariable, the Long data type only holds whole numbers. So the value would have been rounded to the nearest whole number (zero) anyway.
    As Tig201 suggested, use a data type which can handle decimal places.
    I'd recommend Single rather than Double, unless you need a lot of decimal places. the documentation will tell you the limitations of the various data types. It's generally best to use the smallest one that will work, though there are exceptions (Eg. it's generally better to use Long than Integer)
Apr 25 '07 #5

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

Similar topics

1
by: florian.boldt | last post by:
Hi Folks, one of our developers uses a statement with a where clause which usually does not match to any rows. In case of one or more rows found she wrote a an expression in the select clause...
6
by: bart van deun | last post by:
Hello, i have a problem with a division by zero fault in my report trough a query... this is the expression in the query: Name: Sum(IIF(=0,0,/)) what is wrong with this expression?
9
by: Marcin | last post by:
How I can make division of two numbers placed in arrays, example: short int a = {2,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,2}; short int b =...
16
by: Greg Donald | last post by:
Converting some MySQL code to work with Postgres here. I have this query: SELECT tasks.task_id, (tasks.task_duration * tasks.task_duration_type / count(user_tasks.task_id)) as...
2
by: subnunciation | last post by:
i know, this shouldnt be a conundrum right? one just shouldnt divide by zero. but this is suddenly happening *all over* my site. after chasing the error here and there, i simplified things down to:...
10
by: Mike S | last post by:
Does anyone know the logic behind why in VB.NET the result of a floating-point division ('/') is -rounded- on being converted to an integer type, such as with statements like Dim x As Integer =...
2
by: Pakna | last post by:
Why do I have a zero result on this query for all non-zero rows? Do I have to declare specifically the precision of ratio division? How do I do that? And is there a way to make DB2 'ignore'...
94
by: krypto.wizard | last post by:
Last month I appeared for an interview with EA sports and they asked me this question. How would you divide a number by 7 without using division operator ? I did by doing a subtraction and...
9
by: Joe Cool | last post by:
Hello, I am using VS2005. I am trying to convert a VB.NET app to C#.NET. The VB app uses a progress meter to indiate how far a file has been read. I use the following assignment statement in VB: ...
2
by: cobolman | last post by:
I've got the following SQL SELECT count(*) FROM tablea A JOIN tableb B ON ..etc.. WHERE a.string_val = 'test' AND b.divider 0 AND a.number 0 AND (a.number / b.divider 0) The b.divider...
0
by: DolphinDB | last post by:
Tired of spending countless mintues downsampling your data? Look no further! In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
0
by: ryjfgjl | last post by:
ExcelToDatabase: batch import excel into database automatically...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: ArrayDB | last post by:
The error message I've encountered is; ERROR:root:Error generating model response: exception: access violation writing 0x0000000000005140, which seems to be indicative of an access violation...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
1
by: Defcon1945 | last post by:
I'm trying to learn Python using Pycharm but import shutil doesn't work
1
by: Shællîpôpï 09 | last post by:
If u are using a keypad phone, how do u turn on JavaScript, to access features like WhatsApp, Facebook, Instagram....
0
by: af34tf | last post by:
Hi Guys, I have a domain whose name is BytesLimited.com, and I want to sell it. Does anyone know about platforms that allow me to list my domain in auction for free. Thank you
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...

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.