Division Question

  • Thread starter Thread starter Guest
  • Start date Start date
G

Guest

Greetings,

I have the following code and I am trying to return a result of two numeric
variables being divided. However, a "0" is being returned for some reason.
I have dimensioned all variables as "double", but this still has not resolved
the issue. Any suggestions?

Sub Return_All_Turning_Point_Loans()
Dim lngRecordCount As Double
Dim lngSurveysReturned As Double
Dim db As DAO.Database
Dim PercentageofSurveysReturned As Double
Dim rs As ADODB.Recordset
Dim rs2 As DAO.Recordset
Dim strSQL As String
Dim strSQL2 As String

Set db = CurrentDb
Set rs = RunSPReturnRSet
(moddbHelper.EDACConnStr, "get_AllTurningPointLoans")

If Not rs.EOF Then
lngRecordCount = rs.RecordCount
strSQL = "SELECT * from [Survey Results]"
Set rs2 = db.OpenRecordset(strSQL, dbOpenDynaset)
rs2.MoveLast

If Not rs2.EOF Then
lngSurveysReturned = rs2.RecordCount
End If

' <-- "PercentageofSurveysReturned" returns a "0" every time.
"lngSurveysReturned" contains '245', "lngRecordCount" contains '515'. -->
PercentageofSurveysReturned = lngSurveysReturned \ lngRecordCount
......
......
End If
End Sub
 
"normal" division, using a forward slash, returns

245 / 515 = 0.4757281

the backward slash ( \ ) is the *integer* division operator. it returns a
non-rounded integer, regardless of whether the numerator and denominator are
whole numbers or doubles. so the fraction of the return value is simply
truncated, from
0.4757281
to
0

here's an quote from Chapter 12, page 297 of Microsoft Access 2000 Bible by
Prague and Irwin:
"Should you ever need to to take two numbers, round them both to integers,
divide the two rounded integers, and receive a nonrounded integer, the
integer division operator does it in one step."

hth
 
Back
Top