Solved

Adding a Property to ActiveX Control

Posted on 1998-08-30
7
151 Views
Last Modified: 2010-04-30
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?
0
Comment
Question by:Anjaneyulu
7 Comments
 

Author Comment

by:Anjaneyulu
ID: 1431896
Edited text of question
0
 
LVL 4

Expert Comment

by:mcix
ID: 1431897
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
 
LVL 1

Expert Comment

by:disha
ID: 1431898
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
Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

 

Author Comment

by:Anjaneyulu
ID: 1431899
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
 
LVL 3

Accepted Solution

by:
HATCHET earned 200 total points
ID: 1431900
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
 

Author Comment

by:Anjaneyulu
ID: 1431901
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
 
LVL 3

Expert Comment

by:HATCHET
ID: 1431902
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

Featured Post

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Introduction While answering a recent question about filtering a custom class collection, I realized that this could be accomplished with very little code by using the ScriptControl (SC) library.  This article will introduce you to the SC library a…
Have you ever wanted to restrict the users input in a textbox to numbers, and while doing that make sure that they can't 'cheat' by pasting in non-numeric text? Of course you can do that with code you write yourself but it's tedious and error-prone …
As developers, we are not limited to the functions provided by the VBA language. In addition, we can call the functions that are part of the Windows operating system. These functions are part of the Windows API (Application Programming Interface). U…
Show developers how to use a criteria form to limit the data that appears on an Access report. It is a common requirement that users can specify the criteria for a report at runtime. The easiest way to accomplish this is using a criteria form that a…

863 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

23 Experts available now in Live!

Get 1:1 Help Now