Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.misc
Tetsuya Oguma
 
Posts: n/a
Default Property Let: assign return value of Double when passing String

Hi all,

I have a class called clsTrade and in it:

+++
Dim m_dtSettleDate As Date

Property Let SettleDate(szSettleDate As String)
m_dtSettleDate = ParseStringToDate(szSettleDate)
End Property

Property Get SettleDate() As Date
SettleDate = m_dtSettleDate
End Property

Private Function ParseStringToDate(szDate As String) As Date
Const HYPHEN As String = "-"
Dim lYearPos As Long
Dim lMonthPos As Long

On Error GoTo ErrorHandler
With VBA
lYearPos = .InStr(1, szDate, HYPHEN, vbTextCompare)
lMonthPos = .InStr(lYearPos + 1, szDate, HYPHEN, vbTextCompare)

ParseStringToDate = .DateSerial(.Left$(szSettleDate, lYearPos - 1), _
.Mid$(szSettleDate, lYearPos + 1, lMonthPos
- lYearPos - 1), _
.Right$(szSettleDate, .Len(szSettleDate) -
lMonthPos))

End Function

ErrorHandler:
'Put today's day as default first
ParseStringToDate = .DateSerial(.Year(Now), .Month(Now), .Day(Now))
End With
End Function
+++

When compiled an error says by highlilghting the above Property Let,
"Definitions of property procedures for the same property are inconsistent,
or property procedure has an optional parameter, a ParamArray. Or an invalid
Set final parameter"

My intention:
1) Taking a string of Date (e.g., "2005-11-23")
2) Parse and convert it to Date format through ParseStringToDate function
and store it in m_dtSettleDate

Now, I am trying to set a return value of Property Let statement as Date and
cannot!

My convictions:
1) I think it is reasonbale to have Private Function ParseStringToDate in
this clsTrade
2) The Property Let takes 1 parameter of String, converts it to Date and
store it, which I think is again reasonable.

My questions:
1) Am I coding in a good OO principle (to some extent)?
2) How can I get around the error I am getting?

Thanks for your time.
---
Tetsuya Oguma, Singapore

  #2   Report Post  
Posted to microsoft.public.excel.misc
Chris Marlow
 
Posts: n/a
Default Property Let: assign return value of Double when passing String

Hi,

Your OO is fine, as far as VBA Excel OO goes.

Your property let & property get must be of the same type. They are more for
accessing the underlying variable, rather than manipulating it (although you
can do some manipulation - that is not really how it is intended to be used).
You should use a Public Sub (say 'Public Sub SetSettleDate') to which you can
pass the text & then use the function to return the correctly cast value to
set the property.

Regards,

Chris.

--
Chris Marlow
MCSD.NET, Microsoft Office XP Master


"Tetsuya Oguma" wrote:

Hi all,

I have a class called clsTrade and in it:

+++
Dim m_dtSettleDate As Date

Property Let SettleDate(szSettleDate As String)
m_dtSettleDate = ParseStringToDate(szSettleDate)
End Property

Property Get SettleDate() As Date
SettleDate = m_dtSettleDate
End Property

Private Function ParseStringToDate(szDate As String) As Date
Const HYPHEN As String = "-"
Dim lYearPos As Long
Dim lMonthPos As Long

On Error GoTo ErrorHandler
With VBA
lYearPos = .InStr(1, szDate, HYPHEN, vbTextCompare)
lMonthPos = .InStr(lYearPos + 1, szDate, HYPHEN, vbTextCompare)

ParseStringToDate = .DateSerial(.Left$(szSettleDate, lYearPos - 1), _
.Mid$(szSettleDate, lYearPos + 1, lMonthPos
- lYearPos - 1), _
.Right$(szSettleDate, .Len(szSettleDate) -
lMonthPos))

End Function

ErrorHandler:
'Put today's day as default first
ParseStringToDate = .DateSerial(.Year(Now), .Month(Now), .Day(Now))
End With
End Function
+++

When compiled an error says by highlilghting the above Property Let,
"Definitions of property procedures for the same property are inconsistent,
or property procedure has an optional parameter, a ParamArray. Or an invalid
Set final parameter"

My intention:
1) Taking a string of Date (e.g., "2005-11-23")
2) Parse and convert it to Date format through ParseStringToDate function
and store it in m_dtSettleDate

Now, I am trying to set a return value of Property Let statement as Date and
cannot!

My convictions:
1) I think it is reasonbale to have Private Function ParseStringToDate in
this clsTrade
2) The Property Let takes 1 parameter of String, converts it to Date and
store it, which I think is again reasonable.

My questions:
1) Am I coding in a good OO principle (to some extent)?
2) How can I get around the error I am getting?

Thanks for your time.
---
Tetsuya Oguma, Singapore

Reply
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules

Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
Return a digit in a string of numbers W M Excel Discussion (Misc queries) 5 May 11th 05 06:51 PM
Updating master workbook from source that may/may not exist [email protected] Excel Worksheet Functions 20 April 7th 05 03:37 PM
How to make a cell return the formatted value in a text string (i. n.almeida Excel Worksheet Functions 3 February 2nd 05 01:59 PM
How can I assign a number to a string? Jog Dial Excel Discussion (Misc queries) 3 January 14th 05 03:44 AM
Read Text File into Excel Using VBA Willie T Excel Discussion (Misc queries) 13 January 8th 05 12:37 AM


All times are GMT +1. The time now is 09:43 AM.

Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
Copyright ©2004-2025 ExcelBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Excel"