+ Reply to Thread
Results 1 to 9 of 9

VBA Object and Property . Convention in written text to distinguish between the two?

  1. #1
    Forum Expert Doc.AElstein's Avatar
    Join Date
    05-23-2014
    Location
    '_- Germany >Outside Building things.... Mostly
    MS-Off Ver
    Office 2003 2007 2010 PC but Not mac. XP and Vista mostly, sometimes Win 7
    Posts
    3,618

    VBA Object and Property . Convention in written text to distinguish between the two?

    Hi
    I still get confused ( and certainly people I try to explain these things to get confused ) by Microsoft’s annoying habit of sometimes using the same word for an Object and a Property which belongs to it.

    I am trying to get in the habit of always using some simple sort of different text to distinguish between the two.

    Does anyone have any suggestions on a convention. For example does any particular color ( colour ) of text “evoke” a thought in the direction of an Object rather than a Property or vice versa.

    ( I guess I might have a better idea if I was more familiar with those weird symbols in intelligence and the Object Browser and knew where they originated from. But I am not too familiar there.. .. )

    Thanks
    Alan
    Last edited by Doc.AElstein; 01-19-2017 at 11:49 AM.
    '_- Google first, like this _ site:ExcelForum.com Gamut
    Use Code Tags: Highlight code; click on the # icon above,
    Post screenshots COPYABLE to a Spredsheet; NOT IMAGES PLEASE
    http://www.excelforum.com/the-water-...ml#post4109080
    https://app.box.com/s/gjpa8mk8ko4vkwcke3ig2w8z2wkfvrtv
    http://excelmatters.com/excel-forums/ ( Scrolll down to bottom )

  2. #2
    Forum Expert
    Join Date
    03-28-2012
    Location
    TBA
    MS-Off Ver
    Office 365
    Posts
    12,454

    Re: VBA Object and Property . Convention in written text to distinguish between the two?

    Alan,
    You are right!
    Most, if not all,OOP languages use the dot operator to access a property of an object. You can easily separate a property and method (function). Both use the dot operator, but methods are functions, thus the brackets. In VBA, copy is a method while select is a property, but both appear the same-can not tell by looking at the dot operator. Despite not all object appear in intellisense, VBA has clearly defined symbols for properties and methods. I think methods have a box type symbol when you see them in a drop down.

  3. #3
    Forum Expert Doc.AElstein's Avatar
    Join Date
    05-23-2014
    Location
    '_- Germany >Outside Building things.... Mostly
    MS-Off Ver
    Office 2003 2007 2010 PC but Not mac. XP and Vista mostly, sometimes Win 7
    Posts
    3,618

    Re: VBA Object and Property . Convention in written text to distinguish between the two?

    Thanks AB33,
    Actually I was just thinking of a convention to use myself when writing explanations to OP’s, _..

    _.. like I would say to an OP .... “....We have a Range Object that has a Range property.....” etc..

    Then in codes etc, I would use the same color convention just to make sure it was clear in very confusing cases such as, for example, a Range object has a Name Object which in turn has a Name Property.. etc...

    MyRangename = Range.Name.Name



    Where grey is an Object and purple the property

    That is the sort of thing I do currently.
    I wondered if anyone else has preferred conventions or ideas on that.

    Thanks for the reply
    Alan


    P.s. Method or Properties is often unclear. Some people think, for example, that a .Value should be a method as it can have arguments in brackets.. et..
    https://msdn.microsoft.com/en-us/lib.../ff837565.aspx
    http://www.excelforum.com/showthread...=8#post4519378
    https://www.mrexcel.com/forum/excel-...ml#post4089732
    https://msdn.microsoft.com/en-us/lib.../ff195193.aspx

    very debateable, apparently

  4. #4
    Forum Guru Kyle123's Avatar
    Join Date
    03-10-2010
    Location
    Leeds
    MS-Off Ver
    365 Win 11
    Posts
    7,238

    Re: VBA Object and Property . Convention in written text to distinguish between the two?

    The problem with that logic (and your example) is that range is both a property and an object. Why do you need to distinguish?

  5. #5
    Forum Expert Doc.AElstein's Avatar
    Join Date
    05-23-2014
    Location
    '_- Germany >Outside Building things.... Mostly
    MS-Off Ver
    Office 2003 2007 2010 PC but Not mac. XP and Vista mostly, sometimes Win 7
    Posts
    3,618

    Poll. What is your preferrance. What color is yours. What color is it when you put it up

    Hi Kyle
    Quote Originally Posted by Kyle123 View Post
    The problem with that logic ...
    I guess you are saying a simple VLookUp or whatever to automate the process would be difficult?? For me it would be impossible, lol.. But I have no idea if some very clever process in code analysis could distinguish between the two.
    I was not really thinking that far.. But of course if there was a way, then so much the better... I know you said once before it was a bit difficult.... http://www.excelforum.com/showthread...t=#post4172566

    Quote Originally Posted by Kyle123 View Post
    .... .. range is both a property and an object. ..
    Exactly
    ...
    Quote Originally Posted by Kyle123 View Post
    .... .. Why do you need to distinguish?
    ..
    I know the difference..
    I am just trying to think of a convention to help distinguish when I write anything ( Manually – I know the difference so I would write it appropriately in a different color or whatever to help make it clearer. ) . It is just to help me and anyone I try to explain things to to distinguish between things , like a Property and an Object . One reason for me doing that is because things like Range are used for Property and an Object

    Any simple thing will do, like the color I used.
    I just wanted to see if anyone else had a preferred preference or color convention or whatever
    _ like for example what you do in your pretty colored code windows..
    http://www.excelforum.com/showthread...=6#post4420232
    http://www.excelforum.com/showthread...447&highlight=



    _ or like those weird symbols you get with intellisense. Maybe someone knows the history of what / where those symbols originated.

    _ It seems that , for example, Text whether in ‘comments or text strings in codes is almost universally written in green.
    _ maybe there is some other convention for other things.

    _ Not a big deal, just thought if there was anywhere a convention / set of conventions, then I would adopt them instead of confusing more by making up my own pet color convention or whatever
    _.. Maybe , for example, I should use cyan for Properties– you use that for Methods – and whether something is a Method or a Property confuses or is debated by bigger Excel minds than me

    Thanks for the reply
    Alan

  6. #6
    Forum Guru Kyle123's Avatar
    Join Date
    03-10-2010
    Location
    Leeds
    MS-Off Ver
    365 Win 11
    Posts
    7,238

    Re: VBA Object and Property . Convention in written text to distinguish between the two?

    I think what you're trying to do is both impossible and pointless, as an example, consider the below:
    Please Login or Register  to view this content.
    This is perfectly valid code and every thing in it (Except Address and (arguably) Application) is both a property and an Object - what colour do you propose should be for which part? By the same token should address be a different colour since it is both a property and a string? - why should objects get preferential treatment, rather than strings say?

    I could understand trying to identify methods vs properties, but not properties and objects since they can be the same thing

  7. #7
    Forum Guru Kyle123's Avatar
    Join Date
    03-10-2010
    Location
    Leeds
    MS-Off Ver
    365 Win 11
    Posts
    7,238

    Re: Poll. What is your preferrance. What color is yours. What color is it when you put it

    My pretty code windows are somewhat more stupid than you are perhaps giving them credit for

    Looking at the above again, they now look like methods
    Please Login or Register  to view this content.
    This is because my code uses a dumb regex to identify anything that has an open parentheses after and assumes it's a method - it's why it also thinks arrays are methods

  8. #8
    Forum Expert Doc.AElstein's Avatar
    Join Date
    05-23-2014
    Location
    '_- Germany >Outside Building things.... Mostly
    MS-Off Ver
    Office 2003 2007 2010 PC but Not mac. XP and Vista mostly, sometimes Win 7
    Posts
    3,618

    Reginold’s expressions are weird with me. He likes cyan, so maybe I will use it a lot , :)

    Quote Originally Posted by Kyle123 View Post
    .....This is because my code uses a dumb regex to identify anything that has an open parentheses after and assumes it's a method - it's why it also thinks arrays are methods
    Reginold Expressions is a funky guy with me ... he gives me cyan function colors a lot.. ..
    Please Login or Register  to view this content.

  9. #9
    Forum Expert Doc.AElstein's Avatar
    Join Date
    05-23-2014
    Location
    '_- Germany >Outside Building things.... Mostly
    MS-Off Ver
    Office 2003 2007 2010 PC but Not mac. XP and Vista mostly, sometimes Win 7
    Posts
    3,618

    Object and Properties color in code explanations. Explicitly Pedanticised, Circumcised OOP

    Hi Kyle
    Thanks for the replies....
    To some extent I may have explained myself badly. You may be reading more into what I was doing then there is.
    Part of what I was talking about was just some color convention to help get the point across when explaining things..

    _.. But when I think about it I do see what you are saying.. it makes sense . You are correct:_Your comments have helped me get it a bit straighter....

    _.. like if I try to get the string name into a variable, strName, from a Range that is a named range, I have written it in the past like this ( maybe with different colours ):

    Let strName= Ws.Range( "A1").Name.Name
    or
    Let strName= Rng.Name.Name

    I see what you are saying that in those two lines Ws and Rng are the only things that (arguably) could very loosely be referred to as Objects.
    ( I say loosely**** because...)

    What we are both saying , I think, is that in those code lines it works like this:

    Range( "A1") is the Range(" ") type property of a Worksheet which returns the Range object given by the cells column letter and row number notation convention Address of "A1", going from the top left, to row 1 and column 1 of the worksheet associated with the variable Ws. That final returned range object I have in the second line associated with the variable Rng.

    To that returned Range object, then Name property of a Range object is applied which returns an Object which holds various info about the named range.

    One of the things held in that named range Object is the actual string name of that named range. I get that through the property of Name of the named range object, Name


    You have actually helped me get straight ( at least in my head , lol.. ) what I was trying to say.
    Thanks for that kyle.

    I was not being clear enough. In fact I have often been talking of an object when I meant the property that returns an object, and similarly I have been referring to a property when I meant a property that returns that property.


    The whole point of the color convention was just to help try and explain things. I was almost there, for example here in this particular example, http://www.excelforum.com/excel-prog...ml#post4531555 I had my Name Property of a Range Object shown multicoloured in a code line to show that it was a property returning an Object. When then in the explaining text referring to the returned Object, then I would use Name
    For the Name property of a named range object, or the Name property of Name , I would use Name both in the explanation and in the code. Arguably I could have used Name in the code to indicate that it is returning a string

    _....
    I am answering my own question partly, now... This would be now my code line and explanation using colors. The only things here referring just to an object are again the Ws and Rng

    StrName=Ws.Range("A1").Name.Name
    StrName=Rng.Name.Name


    In the code lines I am attempting to get the string name of a named range associated with the first cell in a worksheet.
    The Range object variable, Rng, associated with the first cell in a worksheet object variable, Ws can be filled by using the Range(" ") type property of a Worksheet which returns the Range object given by the cells column letter and row number notation convention Address of "A1", going from the top left, to row 1 and column 1 of the worksheet associated with the variable Ws. That final returned range object I have in the second line associated with the variable Rng.

    To the object Rng, I apply the Name property of that object which returns a further object which contains lots of info about that named range. ( For example it contains the string name of the named range) . So, to that Name object I apply the Name property of that Name object which returns me that string name


    So broadly speaking
    Black is to do with a Range Object. It is an indication of that object or a property returning that object
    Brown is to do with a named range object
    Cyan is to do with properties in general in a code ( and may only appear in part of the code word which is a property)
    Purple was the particular property in this case to return the string name

    At the end of the day, here, I was trying just to distinguish between the two “things” of the Name object and the Name property

    ( I just had another go and corrected my note to Bill, but he has not get the original point yet, so I may be wasting my time.... http://www.excelfox.com/forum/showth...0017#post10017 Lol.... )

    Alan

    P.s. A last point not really worth getting into.... I might refer to something like this
    Range("='[MyFile.xlsm]Sheet1'!A1") as a direct reference using Application Range back up circumventing / circumcising OOP hierarchy, maybe a Under object sort of thing.
    http://www.excelforum.com/showthread...09#post4551509
    https://powerspreadsheets.com/excel-...ent-3094383350
    _...But maybe not.. ..


    _.................



    Please Login or Register  to view this content.

    ( I say loosely**** ... as I have learnt from people like you and Rory that actually they are just address locations to a “pointer” thing. That “pointer” thing has all the actual memory locations ( addresses) of the various property values , and it holds all the instructions what / how to change them , should that be wanted later. That helped explain what occurs when passing an Object to a Called Fucntion or Sub RoutineBy Value. In such an occurance, VBA actually passes a copy of the pointer. So that has the effect of when you change things like properties on the local variable , then the changes are reflected in changes in the original object. ( The copy pointer instructs how to change those values, at the actual address held in that pointer). That would normally be the sort of thing you would expect from passing By Reference. But as that copy pointer “dies” after the called routine ends, then any changes to the Addresses of the Object Properties in the local variable will not be reflected in the original pointer. So you cannot actually change the pointer. )





    http://www.excelforum.com/showthread...101544&page=10
    ' http://www.excelforum.com/showthread...12#post4404807
    ' https://www.thespreadsheetguru.com/b...ent-3090335767
    ' http://www.excelforum.com/showthread...t=#post4440438
    ' http://www.excelfox.com/forum/showth...0017#post10017

    http://www.excelforum.com/showthread...55#post4531555
    Last edited by Doc.AElstein; 01-30-2017 at 06:24 AM. Reason: Add last link

+ Reply to Thread

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Similar Threads

  1. [SOLVED] How to distinguish text or value in a textbox with percentage?
    By alee001 in forum Excel Programming / VBA / Macros
    Replies: 4
    Last Post: 03-09-2014, 03:36 AM
  2. [SOLVED] Need to Mod Code on red text, I have VBA to distinguish Paid(Black Text) Unpaid(Red Text)
    By Garbology in forum Excel Programming / VBA / Macros
    Replies: 5
    Last Post: 02-11-2014, 07:55 PM
  3. [SOLVED] I need a VBA to distinguish Paid(Black Text) Unpaid(Red Text)
    By Garbology in forum Excel Programming / VBA / Macros
    Replies: 9
    Last Post: 12-22-2013, 09:49 AM
  4. Distinguish between numbers and text
    By jgcramer in forum Excel General
    Replies: 2
    Last Post: 05-14-2013, 04:26 AM
  5. Replies: 4
    Last Post: 09-12-2011, 09:53 AM
  6. [SOLVED] how to distinguish between text cells?
    By phaidon in forum Excel - New Users/Basics
    Replies: 2
    Last Post: 04-12-2006, 04:50 AM
  7. Create .NET object written in C# in Excel Macro
    By Tom Chau in forum Excel General
    Replies: 0
    Last Post: 04-11-2006, 02:45 AM

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts

Search Engine Friendly URLs by vBSEO 3.6.0 RC 1