1

I'm a rookie at VBA(Excel) but I know some OOP stuff from java. What I want to do is extend the class MSForms.TextBox to add my own constructors and properties. I've tried using the implements keyword but my class won't compile. It would also be helpful to add these fields into some kind of container variable since they're arranged in a 9x9 pattern. Here's what I want my custom textbox to do. (It's for a game)

I need to be initiate it and place it on the form and put initial text into the box based on what is passed to the constructor. I also would like to have it check the values at runtime with an event to make sure they comply with the game rules. If it does not comply I would like to change the background color to red.

I'm able to do all of this when I just make a bunch of form controls the old fashioned way and use a sub controlled by a button to check the text box values.

Any help on extending classes would be much appreciated. Thanks

  • 1
    it seems like you're not very familiar with VBA. [see how to use the implements in VBA](http://stackoverflow.com/questions/19373081/how-to-use-the-implements-in-excel-vba/19379641#19379641) - but won't solve your problem in this case because you can't inherit an external classes properties via "implements". [There is no such thing as proper Constructor in VBA](http://stackoverflow.com/questions/15224113/pass-arguments-to-constructor-in-vba). Even the way you say it *`own constructors and properties`* doesn't really apply in VBA as you can't have multiple methods with the same name. –  May 01 '14 at 07:34

1 Answers1

3

I don't think you can do that in VBA. I would keep two arrays, one array of TextBox and one array of a new class representing your extended properties. Then you keep them in sync. e.g. Textbox #71 and extended properties #71.

You can look at the following link for making and working with control arrays.

http://www.siddharthrout.com/index.php/2018/01/15/vba-control-arrays/

Siddharth Rout
  • 147,039
  • 17
  • 206
  • 250
Derek
  • 7,615
  • 5
  • 33
  • 58