hello
i am not getting the correct percentage results from the following
code. the "prelimpercent" variable = 0? why would that be the case
when i try to divide numrecs by numrecs2?
any advise would be appreciated. thanks in advance - jung
************************************************** ***********************
Dim rst, rst2 As DAO.Recordset
Dim db As DAO.Database
Dim numrecs, numrecs2 As Integer
Dim percent, prelimpercent As Integer
Dim x As String
Set db = CurrentDb
'counts current records
x = Me![SQLStatement]
Set rst = db.OpenRecordset(x)
With rst
If rst.EOF = False Then
rst.MoveLast
numrecs = rst.RecordCount
Debug.Print numrecs '(19)
Else
numrecs = 0
End If
End With
'count records in qryAllOpenItems
Set rst2 = db.OpenRecordset("SELECT [Exception Tracking].*, [Loan
Tracking].[LT DB Database], [Loan Tracking].[LT Internal Number] FROM
[Loan Tracking] INNER JOIN [Exception Tracking] ON [Loan Tracking].[LT
Loan Shortname] = [Exception Tracking].[ET LN Shortname] WHERE
((((((Not [ET Closed]=-1))) AND ((Not [ET Amount]=0))) AND ((Not [ET
Erroneous Entry]=-1))))")
With rst2
If rst2.EOF = False Then
rst2.MoveLast
numrecs2 = rst2.RecordCount
Debug.Print numrecs2 '(74 records)
Else
numrecs2 = 0
End If
End With
prelimpercent = numrecs / numrecs2 '19/74
percent = prelimpercent * 100
Debug.Print percent 4 1941
-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1
Don't know if this is the solution, just saw it right-off:
Change this:
Dim rst, rst2 As DAO.Recordset
Dim db As DAO.Database
Dim numrecs, numrecs2 As Integer
Dim percent, prelimpercent As Integer
to this:
Dim rst as DAO.Recordset, rst2 As DAO.Recordset
Dim db As DAO.Database
Dim numrecs As Integer, numrecs2 As Integer
Dim percent As Integer, prelimpercent As Integer
Variables dimmed w/o their data type default to Variants.
--
MGFoster:::mgf00 <at> earthlink <decimal-point> net
Oakland, CA (USA)
-----BEGIN PGP SIGNATURE-----
Version: PGP for Personal Privacy 5.0
Charset: noconv
iQA/AwUBQYahTYechKqOuFEgEQLD1QCfegG1dIdt0cioN5RuSKoWN9 yaEOcAoLZX
eYnPuUemIPGtXfXcSp6Xg4TJ
=Dukc
-----END PGP SIGNATURE-----
JMCN wrote: hello i am not getting the correct percentage results from the following code. the "prelimpercent" variable = 0? why would that be the case when i try to divide numrecs by numrecs2?
any advise would be appreciated. thanks in advance - jung ************************************************** ***********************
Dim rst, rst2 As DAO.Recordset Dim db As DAO.Database Dim numrecs, numrecs2 As Integer Dim percent, prelimpercent As Integer Dim x As String
Set db = CurrentDb 'counts current records x = Me![SQLStatement] Set rst = db.OpenRecordset(x) With rst If rst.EOF = False Then rst.MoveLast numrecs = rst.RecordCount Debug.Print numrecs '(19) Else numrecs = 0 End If End With
'count records in qryAllOpenItems Set rst2 = db.OpenRecordset("SELECT [Exception Tracking].*, [Loan Tracking].[LT DB Database], [Loan Tracking].[LT Internal Number] FROM [Loan Tracking] INNER JOIN [Exception Tracking] ON [Loan Tracking].[LT Loan Shortname] = [Exception Tracking].[ET LN Shortname] WHERE ((((((Not [ET Closed]=-1))) AND ((Not [ET Amount]=0))) AND ((Not [ET Erroneous Entry]=-1))))") With rst2 If rst2.EOF = False Then rst2.MoveLast numrecs2 = rst2.RecordCount Debug.Print numrecs2 '(74 records) Else numrecs2 = 0 End If End With
prelimpercent = numrecs / numrecs2 '19/74 percent = prelimpercent * 100 Debug.Print percent
You have declared prelimpercent as an integer -
so it will round any value less than .5 to 0.
HTH
- Turtle
"JMCN" <pi******@yahoo.fr> wrote in message
news:27**************************@posting.google.c om... hello i am not getting the correct percentage results from the following code. the "prelimpercent" variable = 0? why would that be the case when i try to divide numrecs by numrecs2?
any advise would be appreciated. thanks in advance - jung ************************************************** ***********************
Dim rst, rst2 As DAO.Recordset Dim db As DAO.Database Dim numrecs, numrecs2 As Integer Dim percent, prelimpercent As Integer Dim x As String
Set db = CurrentDb 'counts current records x = Me![SQLStatement] Set rst = db.OpenRecordset(x) With rst If rst.EOF = False Then rst.MoveLast numrecs = rst.RecordCount Debug.Print numrecs '(19) Else numrecs = 0 End If End With
'count records in qryAllOpenItems Set rst2 = db.OpenRecordset("SELECT [Exception Tracking].*, [Loan Tracking].[LT DB Database], [Loan Tracking].[LT Internal Number] FROM [Loan Tracking] INNER JOIN [Exception Tracking] ON [Loan Tracking].[LT Loan Shortname] = [Exception Tracking].[ET LN Shortname] WHERE ((((((Not [ET Closed]=-1))) AND ((Not [ET Amount]=0))) AND ((Not [ET Erroneous Entry]=-1))))") With rst2 If rst2.EOF = False Then rst2.MoveLast numrecs2 = rst2.RecordCount Debug.Print numrecs2 '(74 records) Else numrecs2 = 0 End If End With
prelimpercent = numrecs / numrecs2 '19/74 percent = prelimpercent * 100 Debug.Print percent
[re-arranged for readability, bottom posting] JMCN wrote:
hello i am not getting the correct percentage results from the following code. the "prelimpercent" variable = 0? why would that be the case when i try to divide numrecs by numrecs2?
any advise would be appreciated. thanks in advance - jung ************************************************** ***********************
Dim rst, rst2 As DAO.Recordset Dim db As DAO.Database Dim numrecs, numrecs2 As Integer Dim percent, prelimpercent As Integer Dim x As String
Set db = CurrentDb 'counts current records x = Me![SQLStatement] Set rst = db.OpenRecordset(x) With rst If rst.EOF = False Then rst.MoveLast numrecs = rst.RecordCount Debug.Print numrecs '(19) Else numrecs = 0 End If End With
'count records in qryAllOpenItems Set rst2 = db.OpenRecordset("SELECT [Exception Tracking].*, [Loan Tracking].[LT DB Database], [Loan Tracking].[LT Internal Number] FROM [Loan Tracking] INNER JOIN [Exception Tracking] ON [Loan Tracking].[LT Loan Shortname] = [Exception Tracking].[ET LN Shortname] WHERE ((((((Not [ET Closed]=-1))) AND ((Not [ET Amount]=0))) AND ((Not [ET Erroneous Entry]=-1))))") With rst2 If rst2.EOF = False Then rst2.MoveLast numrecs2 = rst2.RecordCount Debug.Print numrecs2 '(74 records) Else numrecs2 = 0 End If End With
prelimpercent = numrecs / numrecs2 '19/74 percent = prelimpercent * 100 Debug.Print percent
MGFoster <me@privacy.com> wrote in message news:<hj****************@newsread3.news.pas.earthl ink.net>... -----BEGIN PGP SIGNED MESSAGE----- Hash: SHA1
Don't know if this is the solution, just saw it right-off:
Change this:
Dim rst, rst2 As DAO.Recordset Dim db As DAO.Database Dim numrecs, numrecs2 As Integer Dim percent, prelimpercent As Integer
to this:
Dim rst as DAO.Recordset, rst2 As DAO.Recordset Dim db As DAO.Database Dim numrecs As Integer, numrecs2 As Integer Dim percent As Integer, prelimpercent As Integer
Variables dimmed w/o their data type default to Variants.
-- MGFoster:::mgf00 <at> earthlink <decimal-point> net Oakland, CA (USA)
-----BEGIN PGP SIGNATURE----- Version: PGP for Personal Privacy 5.0 Charset: noconv
iQA/AwUBQYahTYechKqOuFEgEQLD1QCfegG1dIdt0cioN5RuSKoWN9 yaEOcAoLZX eYnPuUemIPGtXfXcSp6Xg4TJ =Dukc -----END PGP SIGNATURE-----
What you didn't spot is that he's storing his prelimpercent (a number
between 0 and 1) into an INTEGER - which can only be 0 or 1, and so
the result will always be either 0% or 100%, after the multiplication.
Option 1) Store the prelimpercent into a Double,
Option 2) Multiply numrecs by 100 BEFORE doing the division.
Either will work, whatever floats your boat really (although,
obviously, if you want fractional percentages, option 1 is the way to
go).
Damien
thank you for your advise! i realized that after writing it that i
should have declared the prelimpercent as double!
thanks again!!!! jung Da*******************@hotmail.com (Damien) wrote in message news:<ac**************************@posting.google. com>... [re-arranged for readability, bottom posting]
JMCN wrote:
hello i am not getting the correct percentage results from the following code. the "prelimpercent" variable = 0? why would that be the case when i try to divide numrecs by numrecs2?
any advise would be appreciated. thanks in advance - jung ************************************************** ***********************
Dim rst, rst2 As DAO.Recordset Dim db As DAO.Database Dim numrecs, numrecs2 As Integer Dim percent, prelimpercent As Integer Dim x As String
Set db = CurrentDb 'counts current records x = Me![SQLStatement] Set rst = db.OpenRecordset(x) With rst If rst.EOF = False Then rst.MoveLast numrecs = rst.RecordCount Debug.Print numrecs '(19) Else numrecs = 0 End If End With
'count records in qryAllOpenItems Set rst2 = db.OpenRecordset("SELECT [Exception Tracking].*, [Loan Tracking].[LT DB Database], [Loan Tracking].[LT Internal Number] FROM [Loan Tracking] INNER JOIN [Exception Tracking] ON [Loan Tracking].[LT Loan Shortname] = [Exception Tracking].[ET LN Shortname] WHERE ((((((Not [ET Closed]=-1))) AND ((Not [ET Amount]=0))) AND ((Not [ET Erroneous Entry]=-1))))") With rst2 If rst2.EOF = False Then rst2.MoveLast numrecs2 = rst2.RecordCount Debug.Print numrecs2 '(74 records) Else numrecs2 = 0 End If End With
prelimpercent = numrecs / numrecs2 '19/74 percent = prelimpercent * 100 Debug.Print percent
MGFoster <me@privacy.com> wrote in message news:<hj****************@newsread3.news.pas.earthl ink.net>... -----BEGIN PGP SIGNED MESSAGE----- Hash: SHA1
Don't know if this is the solution, just saw it right-off:
Change this:
Dim rst, rst2 As DAO.Recordset Dim db As DAO.Database Dim numrecs, numrecs2 As Integer Dim percent, prelimpercent As Integer
to this:
Dim rst as DAO.Recordset, rst2 As DAO.Recordset Dim db As DAO.Database Dim numrecs As Integer, numrecs2 As Integer Dim percent As Integer, prelimpercent As Integer
Variables dimmed w/o their data type default to Variants.
-- MGFoster:::mgf00 <at> earthlink <decimal-point> net Oakland, CA (USA)
-----BEGIN PGP SIGNATURE----- Version: PGP for Personal Privacy 5.0 Charset: noconv
iQA/AwUBQYahTYechKqOuFEgEQLD1QCfegG1dIdt0cioN5RuSKoWN9 yaEOcAoLZX eYnPuUemIPGtXfXcSp6Xg4TJ =Dukc -----END PGP SIGNATURE-----
What you didn't spot is that he's storing his prelimpercent (a number between 0 and 1) into an INTEGER - which can only be 0 or 1, and so the result will always be either 0% or 100%, after the multiplication.
Option 1) Store the prelimpercent into a Double,
Option 2) Multiply numrecs by 100 BEFORE doing the division.
Either will work, whatever floats your boat really (although, obviously, if you want fractional percentages, option 1 is the way to go).
Damien This thread has been closed and replies have been disabled. Please start a new discussion. Similar topics
by: akickdoe22 |
last post by:
Please help me finish this program. i have completed the addition and
the subtraction parts, but i am stuck on the multiplication and
division. any suggestions, hints, code, anyhting. it's not a...
|
by: Sean C. |
last post by:
Helpful folks,
Most of my previous experience with DB2 was on s390 mainframe systems
and the optimizer on this platform always seemed very predictable and
consistent. Since moving to a WinNT/UDB...
|
by: Peter Frost |
last post by:
Please help
I don't know if this is possible but what I would really like to do is
to use On Error Goto to capture the code that is being executed when
an error occurs.
Any help would be much...
|
by: seb.haase |
last post by:
Hi,
Is it true that that "Python 3000" is dead ?
Honestly I think that e.g. changing 5/2 to be 2.5 (instead of 2) would
just break to much code :-(
On the otherhand I'm using Python as "Matlab...
|
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 =...
|
by: kermit |
last post by:
For a long time,, There has been a discussion of trueFor division
versus integer division in Python.
I myslef prefer that / be used for integer division since almost
always, I want the...
|
by: youjay |
last post by:
I've been out of perl for a while, so I am starting from scratch. I have a small applet which scans a set of directories, getting information from some files in each one, and displaying selected...
|
by: Excel 009 |
last post by:
Hi,
In my office I have Office 2003 on the PC. I created an Access
application which has a component reference to Microsoft Office 12.0
Object Library.
The problem that I am having now it...
|
by: spl |
last post by:
To increase the performance, how to change the / operator with bitwise
operators?
for ex: 25/5, 225/25 or 25/3 or any division, but I am not bothered
of any remainder.
|
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,...
|
by: aa123db |
last post by:
Variable and constants
Use var or let for variables and const fror constants.
Var foo ='bar';
Let foo ='bar';const baz ='bar';
Functions
function $name$ ($parameters$) {
}
...
|
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...
|
by: ryjfgjl |
last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
|
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...
|
by: Sonnysonu |
last post by:
This is the data of csv file
1 2 3
1 2 3
1 2 3
1 2 3
2 3
2 3
3
the lengths should be different i have to store the data by column-wise with in the specific length.
suppose the i have to...
|
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,...
|
by: Oralloy |
last post by:
Hello folks,
I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>".
The problem is that using the GNU compilers,...
|
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...
| |