Vb Classic Programming Model

Can you help with these questions?

In order to properly model VisualBasic applications I'm trying to understand the basic principles of the VB programming model.

AbstractModelsAnswerQuestions, but models require that some questions are asked in the first place.

Here are some questions that don't seem clear cut (to me) from the documentation :
Hope this helps:

Forms are simply a specific type of class, with the added ability that they have a visible component. The also have an hWnd assoicated with them, and can hence contain visible (or invisible) controls.

The relationship between a time and its form is simply that there is an implicit declaration of the form:

  Dim WithEvents mytimer as Timer

You can use the timer (or any other control) in any class you like. Simply DIM it WithEvents and then handle the one's you're interested in. Of course, the control itself still has to be sited on a Form. But you then just pass a reference to it into your class.

I often use this to customise the way standard controls work. For example, say I have a TextBox? and I want to ensure that whenever it gets the focus it selects the entire contents. I have a helper class call TextSelector? which looks like this:

  ' Class TextSelector?

Public WithEvents TheControl? As TextBox?

Private Sub TheControl_GotFocus() With TheControl? .SelStart? = 0 .SelLength? = Len(.Text) End With End Sub

In the form I might have

 Private selector1 as new TextSelector?

Private Sub Form_Load() ' ... set selector1.TheControl? = text1 End Sub

and that's all I have to do. You can use this approach for things like, restricting input to numerics, forcing it to upper case, and so on.

It may seem like work for this simple example, but if you have a *lot* of text boxes in your application ...

this is one of the ways to get code re-use.

I actually have a classwhich contains many of these "decorations" of a text box. Part of the initialisation is selecting which ones I want to apply to a particular text box.

-- KeithDerrick

VisualBasic is a ProceduralLanguage

A lot of programmers know a lot about Object Oriented Programming. Also in this Wiki is a lot of talking about programming from the OOPs point of view. Some people think VisualBasic is some badly implemented OO language, but it is a procedural language.

When you read about unit testing you may think you should structure all your code in a 'neat' way, in Classes but you shouldn't. Classes are just a simple add on, an extended Type definition, nothing more.

I figure, because VisualBasic is a procedural language all testing and structuring of your code should be done in a different way. However, I still have to find out how.


The core of the code should be written in modules (*.Bas).

Why? Possibly

View edit of January 31, 2009 or FindPage with title or text search