property let/get for string


Hi,

I declared a string like this:

Dim sService as String * 16

How can I make property let/get for this?

*************************************
Public Property Get Service() As String * 16

    Service= m_sService

End Property
*************************************
Public Property Let Service(ByRef pValue As String * 16)

    m_sService = pValue

End Property
*************************************


Those functions give me errors..


Thanks
TungVanAsked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

nffvrxqgrcfqvvcCommented:
'Class 1

Option Explicit

Private m_Service As String * 16
   
Public Property Get Service() As String
    Service = m_Service
End Property

Public Property Let Service(ByVal pValue As String)
    m_Service = pValue
End Property

'Form 1

Option Explicit
Dim c As Class1

Private Sub Command1_Click()
Set c = New Class1
'String buffer is 16 so the return will only be 16 characters long if you go beyond 16
'If the string is less then 16 then the length remains 16 but with appended CHR(0)
' returns:  (123456789.123456)
' ommits:   (78)
c.Service = "123456789.12345678" '18 long
MsgBox c.Service

End Sub
nffvrxqgrcfqvvcCommented:
I think you just messed your variable up because it isn't the same name you declared it as.

Above you have Dim sService as String * 16

but it should actually be m_Sservice like you have in your Let/Get statements.
Éric MoreauSenior .Net ConsultantCommented:
Simply receive a string and truncate or validate:

Public Property Get Service() As String

    Service= m_sService

End Property
*************************************
Public Property Let Service(ByRef pValue As String )
if len(pvalue)> 16 then
    m_sService = mid$(pValue,1,16)
else
    m_sService = pValue
endif
End Property

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Visual Basic Classic

From novice to tech pro — start learning today.