PDA

View Full Version : VBA Strongly Typed Arguments



ChloeRadshaw
06-02-2009, 05:07 AM
I always use Option Explicit and the compiler to check I am not doing anything stupid but I cannot understand why this is not flagged up as an incorrect type issue.


The function explcitily requests a fields datatype, whereas I am passing a recordset.

Why is this allowed?



Dim resultSet as ADODB.RecordSet

Call getDouble(resultSet, "SomeColumn")

Public Function getDouble(flds As fields, columnName As String) As Double
If (IsNull(flds.Item(columnName))) Then
getDouble = DEFAULT_DOUBLE
Else
getDouble = CDbl(flds.Item(columnName))
End If
End Function

Oorang
06-02-2009, 09:57 AM
Hi Chloe,
You need to pass resultSet.Fields.

Bob Phillips
06-02-2009, 10:04 AM
I think that Chloe probably knows that alraedy, but it doesn't tell her why the compiler allows it and doesn't choke.

Oorang
06-02-2009, 10:16 AM
Ah, right... Helps if you read :oops: The reason the compiler is allowing you to not use Fields, is because Fields is the default method of the Class. You can tell from the little blue dot in the object browser.

http://img3.imageshack.us/img3/910/objectbrowser.png

ChloeRadshaw
06-02-2009, 10:40 AM
Awesome - Thanks

This site rocks.