Level Extreme platform
Subscription
Corporate profile
Products & Services
Support
Legal
Français
Properties in ActiveX Controls
Message
 
 
To
All
General information
Forum:
Visual Basic
Category:
ActiveX controls
Title:
Properties in ActiveX Controls
Miscellaneous
Thread ID:
00820165
Message ID:
00820165
Views:
62
Hi!

I have a property for a user-defined control,

In design mode of a Form I insert my Control and modify the property, and I can see the changes, but, when I execute the form, the property initializes.

The question would be: How to preserve the value of a property that has been changed in design mode?

Here's the code for the user control:
Option Explicit

Dim cDateFormat(3) As String
Private nDateFormat As DateFormat_Enum

Enum DateFormat_Enum
    YMD_Format = 1
    MDY_Format = 2
    DMY_Format = 3
End Enum

Public Property Get DateFormat() As DateFormat_Enum
    DateFormat = nDateFormat
End Property

Public Property Let DateFormat(pDateFormat As DateFormat_Enum)
    If nDateFormat <> pDateFormat Then
        With txtDate
            .Text = ChangeDateFormat(.Text, cDateFormat(nDateFormat), cDateFormat(pDateFormat))
        End With
        nDateFormat = pDateFormat
    End If
End Property

Function ChangeDateFormat(ByVal sDate As String _
, ByVal cOldFormat As String, ByVal cNewFormat As String) As String

    Dim nY As Integer
    Dim nM As Integer
    Dim nD As Integer

    Dim cY As String
    Dim cM As String
    Dim cD As String

    Dim cS As String
    Dim cR As String

    cS = LCase(cOldFormat)
    cR = LCase(cNewFormat)

    nY = InStr(1, cS, "yyyy")
    nM = InStr(1, cS, "mm")
    nD = InStr(1, cS, "dd")

    cY = Mid(sDate, nY, 4)
    cM = Mid(sDate, nM, 2)
    cD = Mid(sDate, nD, 2)

    cR = Replace(cR, "yyyy", cY)
    cR = Replace(cR, "mm", cM)
    cR = Replace(cR, "dd", cD)

    ChangeDateFormat = cR

End Function

Sub InitDateFormat()

    cDateFormat(1) = "yyyy/MM/dd"
    cDateFormat(2) = "MM/dd/yyyy"
    cDateFormat(3) = "dd/MM/yyyy"
    
    ' begin. comment.
    ' Without this code, the format will explode
    ' because the element 0 of the array is empty
    If nDateFormat = 0 Then
        nDateFormat = YMD_Format
    End If
    ' end. comment.

End Sub

Private Sub UserControl_Initialize()
    InitDateFormat
End Sub
Any help would by appreciated

thanks in advance!
Next
Reply
Map
View

Click here to load this message in the networking platform