Adding a Property to ActiveX Control

I would like to add a  property to my ActiveX control. ( For Ex. Functionality should be just like Format property of MaskEdit control) How can i add it?
AnjaneyuluAsked:
Who is Participating?
 
HATCHETCommented:
If what you're asking is how to create different types of user-defined properties for your ActiveX control, I can help you out further with that.  Just specify what exactly you want the properties to do or what you want them to specify/change.

If what you're asking is how to change Enumeration variables at Run-Time (Design-Time of the .EXE project you're working on using your compiled ActiveX control), you can't do it.  You have to specify the values of the Enum at Design-Time of the ActiveX control before compiling it.  Below is what VB 5 Help file has to say about it :


" Enumeration variables are variables declared with an Enum type. Both variables and parameters can be declared with an Enum type. The elements of the Enum type are initialized to constant values within the Enum statement. The assigned values can't be modified at run time and can include both positive and negative numbers. For example:

Enum SecurityLevel
      IllegalEntry = -1
      SecurityLevel1 = 0
      SecurityLevel2 = 1
End Enum  "
0
 
AnjaneyuluAuthor Commented:
Edited text of question
0
 
mcixCommented:
The simplest way is to use the ActiveX Control Interface Wizard Add-In that is provided with Visual Basic.  This will provide a function stub in the ctl project.

From there it is a matter of actually writing the code to do what the format property does.  Off the top of my head, I can't remember all of the masking that is supported...

But basically you would have a RawData property, which would be the unformatted Text and a Format Property which would be the Format you want to mask the RawData with.  As the User types in the textbox, you would Update the TextBox.Text property with the result of the mask...
0
Ultimate Tool Kit for Technology Solution Provider

Broken down into practical pointers and step-by-step instructions, the IT Service Excellence Tool Kit delivers expert advice for technology solution providers. Get your free copy now.

 
dishaCommented:
Hi,
If u'r activex control is made up of some control of which u want u use thr property then u can just goto user control wizard and select the property. If u want to create a new property then u just have to write a new property in u'r wizard and specify the data type. Then in the code u can serach for the GET and LET procedures of the property and manipulate the code. Also u cant use the proerty in required events to get the affect of it.
0
 
AnjaneyuluAuthor Commented:
i can add a  property to activeX control as refered by disha.But what i want is i would like to add format  type property.I got uneditable list of values using datatype Enum what i want is i want to edit it(i want to add new values at design time).
0
 
AnjaneyuluAuthor Commented:
hello hatchet, i think u have used maskedit control.what i want is i would like to add format property to  my own control(ordinary  textbox) .which will contain some standard date/time formats and if user wants other than existing formats he can add new format.Now i am unable to add new format because i used Enum datype.how can i add this?

0
 
HATCHETCommented:
Well, lemme tell you how to go about it and you can play with it.  I really can't do much more without making the ActiveX control for you.  =)

1) Start an ActiveX Control project and add a standard Text Box and a Timer Control to it.

2) Put code in the Change Event (Text1_Change) that checks the format of the text (Text1.Text) entered in your control to make sure it's the right format.  For example, if the format that you want to restrict to is MM/DD/YY then check that the first two characters of the text entered are numbers using the IsNumeric() function, check that the third character is the "/" character, and so on.

3) The reason I said to add a timer control is that you may want to add a function to it where if you specify a Property in the Property Window it will update the time every second in your control.  To do this, set the Interval (Timer1.Interval) of the Timer Control to 1000 (milliseconds) and in the Timer Event (Timer1_Timer) have it update the text (Text1.Text) of your Text Box to the current Time.

How you design this and how you want it to act is completely up to you.  It all depends on how you want the user to be able to use it and how you want the user not to be able to use it.  To get you started, here's two bits of code for two of the things I mentioned above:


Private Sub Text1_Change()

  Dim MyCounter As Integer
  Dim LeftChar As String
  Dim RightChar As String
 
  For MyCounter = 0 To Len(Text1.Text)
    LeftChar = Left(Text1.Text, MyCounter)
    RightChar = Right(LeftChar, 1)
    If IsNumeric(RightChar) = False Or RightChar <> "/" Then
      ' Entry Invalid - Write routine here that corrects it or
      ' gives error message
    End If
  Next

End Sub


Private Sub Timer1_Timer()

  Text1.Text = Time

End Sub


This should answer your question sufficiently.  Please assign the points.  Thanks, and good luck.

HATCHET
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.