+ Reply to Thread
Results 1 to 5 of 5

Excel VBA Classes - Property LET compile error

  1. #1
    Forum Contributor
    Join Date
    08-22-2017
    Location
    USA
    MS-Off Ver
    2016 WINDOWS and MAC
    Posts
    294

    Excel VBA Classes - Property LET compile error

    Hi,

    This is a basic post and I apologize but I am struggling with setting my LET property in my class module I am building.

    Assume the context is a User class where i can read and write the status of user's (online or offline).

    If user is online, property = true, else false

    Problem is, I need to pass a string variable to this property during runtime to obviously tell the class WHICH user I want to let/get.

    Property GET works fine...

    Please Login or Register  to view this content.

    However, LET does not work. I need to pass the username from module code to the property...

    Please Login or Register  to view this content.

    And obviously I want to use these properties as such....

    Please Login or Register  to view this content.








    P.S. I dont want to use a function/sub (Method) for this.


    I am missing code in the LET property but nothing works. GET properties actually make sense--how the code is written with the variables and the property itself.... LET properties are just confusing.

    Thanks for your patience and time.

    Regards,

  2. #2
    Forum Guru Andy Pope's Avatar
    Join Date
    05-10-2004
    Location
    Essex, UK
    MS-Off Ver
    O365
    Posts
    20,434

    Re: Excel VBA Classes - Property LET compile error

    To fix the problem the property needs to include the boolean

    Please Login or Register  to view this content.
    You property usage is confusing. You would normal use it to store the username or the online state. You seem to be testing online state and username is just and argument. If this is a userclass object why do you need to pass username?

    I would have expected something more like this.

    Please Login or Register  to view this content.
    with the class code
    Please Login or Register  to view this content.
    Cheers
    Andy
    www.andypope.info

  3. #3
    Forum Contributor
    Join Date
    08-22-2017
    Location
    USA
    MS-Off Ver
    2016 WINDOWS and MAC
    Posts
    294

    Re: Excel VBA Classes - Property LET compile error

    Andy,

    Thanks for your reply and great points about how I am using this code.

    I guess, I am using the class as a container for code, solely for the purpose of cleaner module procedures. So, in a way, I guess I am improperly using a class and one might say I am not really even creating a true object.
    It is true the way I am using this class is by passing an argument to every property, which again, is not really proper.

    To me, when writing module code it is more readable to do this..

    Please Login or Register  to view this content.
    Rather than the proper way....



    Please Login or Register  to view this content.
    I guess its a matter of one line versus two. Lets say I set the property .Username way above in the procedure and forget what user i set it too, if I need to set the user's state to online, then I don't have to go and hunt to verify that the .User property is the right user to set his state too. I can just pass the user right where i'm at. It is less versatile by setting two properties, in my opinion.

    So yeah, I am using properties as public functions. Perhaps I will consider the true way of designing a class. To me right now, its just a very clean way of storing and re-using code. A good learning experience, nonetheless.


    I will attempt with your examples and see what best fits my needs. I will report back with any troubles.

    Thank you very much!

  4. #4
    Forum Contributor
    Join Date
    08-22-2017
    Location
    USA
    MS-Off Ver
    2016 WINDOWS and MAC
    Posts
    294

    Re: Excel VBA Classes - Property LET compile error

    Andy,

    Hello. I have thought on it... I guess I don't see any advantage to using 'LET' if you can't execute code the way I desire.

    For instance....


    CLASS:
    Please Login or Register  to view this content.


    SUB:

    Please Login or Register  to view this content.

    So, if I wanted to LET Online Property to TRUE (i.e. do some meaningful work in a database or sheet) then its reasonable to assume, my only option here is to design a method...

    Example:


    CLASS:
    Please Login or Register  to view this content.

    OK So now when I write my procedure in my module to use this class, it will look as such...


    SUB:

    Please Login or Register  to view this content.

    An example of my problem is a Textbox object. You can get the value like this...

    Please Login or Register  to view this content.
    You can LET the value like this....

    Please Login or Register  to view this content.
    However, maybe I am ignorant, but I would bet when you LET that value, behind the scenes there is much more code being executed (find the specific textbox object, enter the value, etc)
    (i don't know how MS writes their software nor do I have any knowledge of "true" program objects) But I am just making the point that there has
    to be a valid case for when a property is LET with a value, code executes. And i'm sure thats possible, I just don't know how right now lol.



    But going back to my philosophy and way I am using this class, I realize that it boils down to....

    -Properties hold variables to use later
    -Methods use those properties


    So, I am all over the place lol. Just trying to make practical sense of it all and leverage these tools.

    Thanks, welcome your comments and criticism.
    Last edited by ironfelix717; 01-26-2019 at 02:52 PM.

  5. #5
    Forum Guru Andy Pope's Avatar
    Join Date
    05-10-2004
    Location
    Essex, UK
    MS-Off Ver
    O365
    Posts
    20,434

    Re: Excel VBA Classes - Property LET compile error

    In you textbox example the actual object is referencing the textbox control so it does not have to find it.
    It would be the same as creating your class for 'Richard'.

    If you want to use the Online property, and include a name I showed the syntax required in my first reply.
    It's okay to do that, it's just the class name of userclass and the public variable username all suggested you would be having multiple user objects. Where as you appear to only need one and you pass in the username.
    In this sense the username is just an argument as you are not retaining it in the class object only using it to determine something within the class.

+ 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] Can't Assign to Read-Only Property; Compile Error on Assigning Property to Class.
    By Dal123 in forum Excel Programming / VBA / Macros
    Replies: 9
    Last Post: 03-15-2018, 08:09 AM
  2. [SOLVED] Compile Error: Wrong number of arguments or invalid property assignment Error
    By JJFletcher in forum Excel Programming / VBA / Macros
    Replies: 5
    Last Post: 04-22-2016, 05:29 PM
  3. [SOLVED] Compile Error: Invailid Use of Property Excel 2010
    By KrystynGriffin in forum Excel Programming / VBA / Macros
    Replies: 7
    Last Post: 01-05-2014, 09:13 PM
  4. Excel - VBA - Compile error: invalid use of property
    By Ladynerd in forum Excel Programming / VBA / Macros
    Replies: 3
    Last Post: 12-20-2012, 11:22 AM
  5. Bug/compile error when referring to custom worksheet property. Excel 2002.
    By macaulay in forum Excel Programming / VBA / Macros
    Replies: 0
    Last Post: 09-24-2008, 12:16 PM
  6. Replies: 1
    Last Post: 02-17-2006, 12:10 PM
  7. Compile Error: Expected End Property
    By George J in forum Excel Programming / VBA / Macros
    Replies: 4
    Last Post: 08-03-2005, 11:05 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