Styles of programming in VBA

tiredofit

Well-known Member
Joined
Apr 11, 2013
Messages
1,926
Office Version
  1. 365
  2. 2019
Platform
  1. Windows
I have come to the conclusion there appears to be two distinct styles of programming in VBA.

1. Those with no prior experience of programming.
2. Others who are already conversant with Java, C#, etc.

I have seen VBA code such as:

Rich (BB code):
Function MyFunc (somearg As Burger) As McDonalds

and then I start to panic as I believe this has been written by someone who has a formal training in programming because Burger and McDonalds (in my humble opinion) are classes.

Most VBA books focus on getting programs written without delving too deeply into classes, collections, etc.

Can someone please post some examples of:

Rich (BB code):
Dim MyObj As Object 'why might they create their own object (and I don't mean just for late binding purposes).

Classes and hierarchies, such as parent / child relationships

I have tried reading Ramblings by Bruce McPherson:

Rich (BB code):
[FONT=Verdana,Arial,Tahoma,Calibri,Geneva,sans-serif]http://ramblings.mcpher.com/

but find it difficult to understand everything, though I have grasped the basic concepts of classes, instatiation, etc.

Thanks


[/FONT]
 

Excel Facts

Test for Multiple Conditions in IF?
Use AND(test, test, test, test) or OR(test, test, test, ...) as the logical_test argument of IF.
Code:
Function MyFunc(somearg As Burger) As McDonalds
and then I start to panic as I believe this has been written by someone who has a formal training in programming because Burger and McDonalds (in my humble opinion) are classes.

Not necessarely just Classes. They could be any data structure such as Classes, Interfaces, UDTs and Enums.
 
Last edited:
Upvote 0
You're already familiar with classes and hierarchies from the Excel object model - eg Workbooks and Worksheets.
 
Upvote 0
You're already familiar with classes and hierarchies from the Excel object model - eg Workbooks and Worksheets.

Thanks but somehow I seem to have a mental block when reading other's code.

As I said, I have written basic classes myself, including situations when only a class will do, eg ensuring a query has completed (when extracting info from a sharepoint website) before the next step begins.

If someone wrote a dictionary of dictionaries in vba, is that advanced coding or convoluted?
 
Last edited:
Upvote 0
Depends on the situation; could be overkill, or entirely reasonable!
 
Upvote 0

Forum statistics

Threads
1,224,817
Messages
6,181,149
Members
453,021
Latest member
Justyna P

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top