Results 1 to 4 of 4

compile error: compile error expected

Threaded View

  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:-

    dim tst as mylass
    dim tstParm1 as long
    dim tstParm2 as string
    
    tstParm1 = "..some number..."
    tstparm2 = "any string"
    
    set tst = new myclass
    
    tst.method1(tstParm1, tstParm2)
    ***********************************
    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:-


    dim data as variant
    dim mycol as collection
    dim nclass as myclass
    
    
    set nclass = new myclass
    set mycol = new collection
    
    ' ThisWorkBook.Sheets("sheet name").Usedrange contains various data.
    ' Column 1 contains 10 digit numbers from csv file. Format is "general"
    
    data = ThisWorkBook.Sheets("some sheet name").Usedrange
    
    nclass.number = data(1,1)   ' for e.g.
    mycol.add item:=nclass key:=<string of nclass.number>  'note the index is the string of the number
    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.

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