November 23, 2014
Hot Topics:

ActiveX Control Tutorial - Part 2

  • November 19, 2002
  • By Karl Moore
  • Send Email »
  • More Articles »

Now I want the person using this control to be able to decide whether the text box should accept just letters, numbers or both - and whether letters entered should be converted to upper or lower case.

So I've already determined two possible properties:

  • AcceptType — should it hold just letters, numbers or both?
  • ConvertCase — automatically convert to upper case, lower case or neither?

But how will the user tell me which they wish to use? I could perhaps tell them to set AcceptType=1 if they wish to hold letters, 2 if they only require numbers and so on. Err, but that ain't too user friendly. And you know how darn picky those users get.

This is where enumerations come into play. Yessiree, that's another geeky word designed to scare off potential programmer types. But it's really very simple.

  • Back in your project, open the code window
  • Enter the General Declarations section
  • Select (General) from the Object drop-down box and (Declarations) from the Procedure drop-down box
  • Type in the following code:
Public Enum CharacterType    All     Numbers     Letters End Enum

Let me explain what's happening here; the first line simply tells Visual Basic we're creating an enumeration christened CharacterType. The Public bit just ensures our end users can see the enumeration.

The next three lines list our options — no spaces allowed. The user can select All, Numbers or Letters.

Top Tip: You can also assign numbers to each of our options, so All might equal zero, Numbers might equal one and so on. Lookup the 'Enum Statement' in Visual Basic help for more information!

That final line of code simply states that the enumeration ends here.

So we've just defined the 'options' for our planned 'AcceptType' property. Now let's add another enumeration for the 'CaseConvert' property.

  • Type in the following code:
Public Enum CaseType    All    UpperCase    LowerCaseEnd Enum

Hmm, I guess you're not impressed in fact, I saw more impression the last time I drop a 1st class stamp onto a freshly produced ingot of 22 carat gold. But you will be, as soon as we get these things working.

Still, that's it for enumerations. Let's add a few properties!





Page 3 of 6



Comment and Contribute

 


(Maximum characters: 1200). You have characters left.

 

 


Enterprise Development Update

Don't miss an article. Subscribe to our newsletter below.

Sitemap | Contact Us

Rocket Fuel