Is VBA an Anarchist. – An anarchistic OOP Language?

User avatar
Doc.AElstein
BronzeLounger
Posts: 1499
Joined: 28 Feb 2015, 13:11
Location: Hof, Bayern, Germany

Is VBA an Anarchist. – An anarchistic OOP Language?

Post by Doc.AElstein »

Hi

Please be gentle with me as I confess I am not too sure what I am talking about. ( I have no formal Computer training. I am not a programmer. I have just been using VBA to speed up a personal project for a couple of years now )

I keep being told ( mostly when I delve a bit further into VBA than I am probably equipped to !! ) by Computer Experts, that VBA is not an Object Orientated Programming language. Never the less when learning , one is frequently told that it is an Object Orientated Programming language. A reason given to me is that it rejects sometimes the Object Orientated Programming language hierarchy, which we are continually told it ( should? ) adhere to.

So is VBA an Anarchist? :smile: :xsmile:

Alan

Edit 24th December..
_.. seems this Thread has been moved from Scuttlebutt.. Just thought I would mention that to explain the seasonal jovialities :) :smile:
Last edited by Doc.AElstein on 24 Dec 2016, 12:52, edited 1 time in total.
I am having difficulty logging in with this account just now.
You can find me at DocAElstein also

User avatar
HansV
Administrator
Posts: 78474
Joined: 16 Jan 2010, 00:14
Status: Microsoft MVP
Location: Wageningen, The Netherlands

Re: Is VBA an Anarchist. – An anarchistic OOP Language?

Post by HansV »

VBA uses objects, properties, methods and events, so in that sense it is an object oriented language. You can create your own classes etc.
But it does not implement all aspects of a fully object oriented language.
Best wishes,
Hans

User avatar
AlanMiller
BronzeLounger
Posts: 1545
Joined: 26 Jan 2010, 11:36
Location: Melbourne, Australia

Re: Is VBA an Anarchist. – An anarchistic OOP Language?

Post by AlanMiller »

I'd probably describe it as an object-based language. Inheritance, encapsulation, abstraction, and polymorphism are four fundamental concepts of object-oriented programming - VBA supports very little of these features. OTOH, recognized OO languages usually don't adhere to them "perfectly" because stricter adherence makes for less flexibility. Some languages approach "paradigm perfection" more than others. For instance:

"Smalltalk is a 'pure' OO language, meaning that, unlike Java and C++, there is no difference between values which are objects and values which are primitive types. In Smalltalk, primitive values such as integers, booleans and characters are also objects, in the sense that they are instances of corresponding classes, and operations on them are invoked by sending messages. A programmer can change the classes that implement primitive values, so that new behavior can be defined for their instances--for example, to implement new control structures--or even so that their existing behavior will be changed. This fact is summarised in the commonly heard phrase "In Smalltalk everything is an object" (which would more accurately be expressed as "all values are objects", as variables aren't)."

You can follow lots of people arguing about it here for example.

Alan

User avatar
Doc.AElstein
BronzeLounger
Posts: 1499
Joined: 28 Feb 2015, 13:11
Location: Hof, Bayern, Germany

Anarchy in the VB Ay ? ........................

Post by Doc.AElstein »

Thanks Han’s , thanks Alan for the detailed reply. :xsmile:
Seems OOP has been around a lot longer than I thought then..i had a good google at Smalltalk stuff last night”_…

_..Sadly I can’t really understand too much in detail – it is a bit over my head. I tried to think of a “fun” answer to satisfy my lust to understand rather than delving in too deep for me…. To save anyone the grief of me asking fully .. Lol… :) ;) :xsmile: :xgrin:

The thing actually cropped up again in my head recently with this sort of Code …

Code: Select all

Sub ApplicationRangeObject() '
' String referrence build
Dim strRef As String: Let strRef = "='" & ThisWorkbook.Path & "\" & "[" & ActiveWorkbook.Name & "]" & ActiveSheet.Name & "'!A1:A2"
 Debug.Print strRef ' Immediate Window (Ctrl+G form VB Editor) gives   ='H:\Excel0202015Jan2016\OffenFragensForums\eileenslounge\[VIXData050824Start17Dec.xls]Tabelle1'!A1:A2
 Let strRef = "='[" & ActiveWorkbook.Name & "]" & ActiveSheet.Name & "'!A1:A2"
 Debug.Print strRef ' gives   VIXData050824Start17Dec.xls]Tabelle1!A1:A2
' Range Object Direct Referrence ?
 Let Application.Range(strRef).Value = "AyOneAyTwo"
End Sub
Two things I keep reading.
_OOP has a Hierarchy, progressing “along” or ”down” the chain
_A Range Object is “got at” through Properties , ( Cells Property, Range Property) . ( Sometimes people say methods instead )

That code Snippet “works” as I want getting to the first couple of cells in Tabell1 Worksheet
It works in any Class module.

It seems to be telling me
_1) I can go back up the Hierarchy
_ 2) I have a fundamental way to reference a ( Range ) Object directly through a string reference
(_ regarding the latter, 2) , I think I am using a Range Object***. Or possibly a Range(” “) Method were the strRef is the argument. I was guessing that, as always, if we do not write that full reference, ( as is more usual ) , then Excel adds it , giving a different version depending on exactly where the code is and / or what is active et…. )

( ***I do get the point and understand that a Worksheet has a Cells Property and Range Property. I do also understand that a Range Object has a Cells Property and Range Property – I do not get confused anymore with the unfortunate use of the same Range word for a Range Object and a Range Property )

I appreciate your efforts to inform me in better detail. I like to understand..
I thought a post here with a “fun”” Layman’s solution / explanation might be better than for me to bore or distract from the Xmas spirit by asking it more directly :) ;)

MAyBea it is better for me just to think of VBA as being a bit anarchistic in what is doing there!!
_.. then go and finally write my Xmas cards instead .. Lol..

Anarchy in the VB Ay ?_...

_..”.. it’s coming some time.. & mAy Bea ..” _.. There is a nub of a song in there somewhere…

Merry Members Xmases :xsmile: :xgrin: :xsmile:
I am having difficulty logging in with this account just now.
You can find me at DocAElstein also