+ Reply to Thread
Results 1 to 6 of 6

Newbie-ish Class Module Sub Question

  1. #1
    Registered User
    Join Date
    09-12-2013
    Location
    United States
    MS-Off Ver
    Excel 2013
    Posts
    9

    Newbie-ish Class Module Sub Question

    Hello again.

    I'm playing with custom classes, and I've created a method in one that looks like this:

    Please Login or Register  to view this content.
    I have a different class, where the Populate method does NOT have the optional argument, that works just fine. (as does this one, if I remove the optional argument)

    When I try to use it as such:
    Please Login or Register  to view this content.
    I get a a compile error, Expected: =

    I'm not setting or assigning anything, and the sub doesn't return a value, so where (more importantly, why) does the VBE want an =?

    Edit: Because I have another class with a Public Sub Populate, I changed the one in question to PopulateIP, in case the duplicate name would be an issue. It did not fix the problem. (Bonus question: Since these are public subs in class modules, DO they need to be different names? Or can I have multiple classes with custom methods of the same name?)

    Edit: When trying to call the method without the optional argument, VBE does not complain.
    Last edited by zaimor; 11-07-2013 at 10:40 AM. Reason: Solved.

  2. #2
    Forum Guru Norie's Avatar
    Join Date
    02-02-2005
    Location
    Stirling, Scotland
    MS-Off Ver
    Microsoft Office 365
    Posts
    19,646

    Re: Newbie-ish Class Module Sub Question

    Try removing the ().
    If posting code please use code tags, see here.

  3. #3
    Forum Expert OllieB's Avatar
    Join Date
    12-20-2012
    Location
    Netherlands
    MS-Off Ver
    Excel 2007 (home) & 2010 (office)
    Posts
    1,542

    Re: Newbie-ish Class Module Sub Question

    I think it is because of the brackets surrounding the parameters passed. Two options

    Please Login or Register  to view this content.
    If you like my contribution click the star icon!

  4. #4
    Registered User
    Join Date
    09-12-2013
    Location
    United States
    MS-Off Ver
    Excel 2013
    Posts
    9

    Re: Newbie-ish Class Module Sub Question

    That was it. Why does clsName.Populate(arg) work but clsName.Populate(arg1,arg2) not?

  5. #5
    Forum Guru JosephP's Avatar
    Join Date
    03-27-2012
    Location
    Ut
    MS-Off Ver
    2003/10
    Posts
    7,328

    Re: Newbie-ish Class Module Sub Question

    unless you are returning a value from a function or using the Call statement (or explicitly trying to dereference a variable) you should not use parentheses. when you write
    Please Login or Register  to view this content.
    everything in the parentheses is treated as one argument
    Josie

    if at first you don't succeed try doing it the way your wife told you to

  6. #6
    Registered User
    Join Date
    09-12-2013
    Location
    United States
    MS-Off Ver
    Excel 2013
    Posts
    9

    Re: Newbie-ish Class Module Sub Question

    Good information, just started learning VBA last month. Thanks for the tip!

+ 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. Replies: 1
    Last Post: 08-30-2011, 02:23 AM
  2. Class module question
    By JackL in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 09-18-2008, 06:27 AM
  3. Class Module question
    By WhytheQ in forum Excel Programming / VBA / Macros
    Replies: 0
    Last Post: 06-01-2006, 03:50 PM
  4. Class Module Question
    By Andrew Yates in forum Excel Programming / VBA / Macros
    Replies: 8
    Last Post: 03-05-2006, 11:55 AM
  5. Class module question
    By David in forum Excel Programming / VBA / Macros
    Replies: 4
    Last Post: 09-08-2005, 12:05 PM

Tags for this Thread

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