Daniel Bencik
Daniel Bencik

Reputation: 969

VBA automatic type conversion

I come from a C++ world and I am going through first steps in VBA classes.

Say I have a class for a smart Date, i.e. QDate

 *** Class Module ***
 Option explicit
 Private xDate_ As Date

 Property Let xDate(xVal As Date)
      xDate_ = xVal
 End Property

 Property Get xDate() As Date
     xDate = xDate_
 End Property

 ' ... some nice methods follow here...


 *** non-Class Module *** 
 Public Function makeQDate() As QDate
    Set makeQDate = New QDate
 End Function

Sample usage might be

 Dim xQDate as QDate :  xQDate = makeQDate()
 xQDate.xDate = DateSerial(2000,1,1)

The last line is not as nice as one could get in C++. If we could create implicit conversion that would allow to write

 xQDate = DateSerial(2000,1,1)

it would be awesome. Is something like that achievable in VBA? Many thanks.

Upvotes: 2

Views: 512

Answers (1)

Fls'Zen
Fls'Zen

Reputation: 4654

As far as I'm aware, VBA doesn't support custom implicit conversions, only built-in ones. But, you're right—it would be awesome.

Upvotes: 1

Related Questions