+ Reply to Thread
Results 1 to 4 of 4

compile error: compile error expected

  1. #1
    Registered User
    Join Date
    06-08-2007
    Posts
    15

    Thumbs up compile error: compile error expected

    Two issues here I can't explain.

    Issues 1
    -----------
    I have a class defined in say in module "myclass"
    One of the methods is say method1, which has been declared as

    Public sub method1(byref parm1 as long, byref parm2 as string)

    Also in a test module I test the method1 as follows:-

    Please Login or Register  to view this content.
    ***********************************
    I get a "compile error expected ="
    Which seems to mean I have to assign a var to capture the return value from method1....but I haven't defined the sub to return a value (that's called a function)??

    If I do assign a var to = the return value (i.e. var = method1...), the syntax error disappears but I get a runtime error - "Expecting a function or variable" as there is no return value from the method (i.e. not a function). Only way around this is to declare the method as a function and give it a return value.

    Also, the EXACT SAME setup above but with just 1 parm (i.e. defined method1 to take JUST parm1 ) everything works as it should using a sub and not a function.

    In summary, it would appear I can only declare a sub method if it takes only 1 parm, otherwise I have to declare a function - what am I missing or why is vba behavin g this way? Perhaps try it in case it's something to do with my setup only.



    Issue 2
    ---------
    Stumps me even more involving collections and number to string conversions
    Here we go.....code is:-


    Please Login or Register  to view this content.
    later I try to access an nclass object from the collection via the key ...

    mycol(data(1,1)) - gives me a subscription range error.

    Ah ha this means data(1,1) must return the number stored as a number, not a string. So to get around this I use CStr(data(1,1))....although it doesn't seem to return a string either or at least I get another range error.

    I've also tried Str which doesn't resolve issue either.

    If I use mycol("<actual number>") this works.

    So why isn't the CStr or Str doing its' conversion work or how else can I get around this?


    Any help much appreciated.....

    Thanks,
    Last edited by odeno; 06-14-2007 at 05:00 AM.

  2. #2
    Registered User
    Join Date
    06-08-2007
    Posts
    15
    Well the second issue seems to have resolved itself.

    I didn't do anything different or special (as I recall), just implemented the following:-

    Please Login or Register  to view this content.
    instead of

    Please Login or Register  to view this content.
    which is what I tried before as I recall.

    Issue 1 is still outstanding. Any thoughts anyone?

  3. #3
    Registered User
    Join Date
    06-08-2007
    Posts
    15

    issue 1 now resolved

    All I had to do was remove the parenthesis when calling the proc.

    Please Login or Register  to view this content.
    and NOT
    Please Login or Register  to view this content.
    So 1 arg and parenthesis is OK, 2 + and they are not. Still weird behaviour if you ask me

  4. #4
    Registered User
    Join Date
    01-10-2008
    Posts
    11
    My understanding of VBA is:

    Please Login or Register  to view this content.
    creates a message box with the word "Boo!" in it. Whereas

    Please Login or Register  to view this content.
    is actually a function (vs. procedure/sub) call and returns something.

    What you are experiencing may be the same thing.

+ Reply to Thread

Thread Information

Users Browsing this Thread

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

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