Results 1 to 10 of 10

Thread: Ambigious Error Detected / Left / Right Question

  1. #1

    Thread Starter
    Lively Member
    Join Date
    Apr 2010
    Location
    Southern California
    Posts
    88

    Ambigious Error Detected / Left / Right Question

    Im getting an duplicate declaration error on "left" strings, I know whats causing it is an activex control im using, but the thing is I need the left string, how can I make this work? is there any thing I can use to replace left / right strings? I tried using mid$ but that doesnt work. I dont get this because I need to use this activex control yet I need the left / right strings.

    For example, the LEFT is giving me a ambigious name detected in this code:
    GetFromINI$ = Left(strBuffer, GetPrivateProfileString(section$, ByVal Key$, "", strBuffer, Len(strBuffer), Directory$))

  2. #2

  3. #3
    Fanatic Member FireXtol's Avatar
    Join Date
    Apr 2010
    Posts
    874

    Re: Ambigious Error Detected / Left / Right Question

    You must fully qualify the reference. The object browser(F2) can tell you the class of which this is a member.

    Additionally, you should be using Left$, and not Left. Left$ returns a string and is generally more efficient than Left. Unless you're using a Variant type assignment... then Left may be desired.

    Try: VBA.Left$() or VBA.Strings.Left$()

  4. #4

    Thread Starter
    Lively Member
    Join Date
    Apr 2010
    Location
    Southern California
    Posts
    88

    Re: Ambigious Error Detected / Left / Right Question

    Quote Originally Posted by RhinoBull View Post
    You most likely have "Left" declared as public variable/property/function so find any occurence of those and change their respective names.
    Alternatively try using VBA.Left ...
    Thanks, tried that already however (by testing it all in a new project) but no luck. Thanks for the alternative, is that exact?

  5. #5

    Thread Starter
    Lively Member
    Join Date
    Apr 2010
    Location
    Southern California
    Posts
    88

    Re: Ambigious Error Detected / Left / Right Question

    Quote Originally Posted by FireXtol View Post
    You must fully qualify the reference. The object browser(F2) can tell you the class of which this is a member.
    I'm sorry, but how do you mean?

    Additionally, you should be using Left$, and not Left. Left$ returns a string and is generally more efficient than Left. Unless you're using a Variant type assignment... then Left may be desired.

    Try: VBA.Left$() or VBA.Strings.Left$()
    Would the variant assignment work with either or?

    Thanks for the alternatives, let me give those a shot. I have come to conclusions that an alternative is what I will require at this point.

  6. #6
    Fanatic Member FireXtol's Avatar
    Join Date
    Apr 2010
    Posts
    874

    Re: Ambigious Error Detected / Left / Right Question

    To open the object browser. You can either hit the F2(function 2, at the very top, left-side, of a keyboard, between F1 and F3) key. Or use the menu View | Object Browser.

    Type in what you're looking for(see screenshot if you're unsure where), and press enter(or click the button immediately to the right of the field).

    The fully qualify means to use the "Member of:" as a prefix: VBA.Strings.Left$. Strings.Left$ also works.

    Another example: place Command1 button on a form. Referencing Command1 works fine inside of the form(Command1.Caption = "Hello World", for instance). But you can also use Form1.Command1.Caption.

    It's the difference between explicitly(fully qualifying) stating 'where' something is, and allowing the compiler to implicitly figure it out. When there are multiple possibly references that the compiler could implicitly assume you'll end up with "ambiguous name detected" error. The solution is to either rename, or fully qualify.

    Excuse my 'hacked' color scheme(I realize the button icons appear oddly!).
    Attached Images Attached Images  

  7. #7
    Addicted Member
    Join Date
    Oct 2009
    Posts
    164

    Re: Ambigious Error Detected / Left / Right Question

    If you havnt found the solution yet, I want to propose a different option:
    many MANY times I have had a duplicate declaration of some kind (usually a function) and when trying to compile the error is thrown, highlighting a seemingly random and unrelated section of code. However I have noticed that about 80% of the time it is on a Left() or Right()

    My tip is just to not get tunnel vision and look only for problems with your Left()
    Do a quick look over the rest of the project for anything else that may be out of sorts.


    PS: Ive also had strange error locations if my API declarations were incorrect, specifically the argument types.

  8. #8

    Thread Starter
    Lively Member
    Join Date
    Apr 2010
    Location
    Southern California
    Posts
    88

    Re: Ambigious Error Detected / Left / Right Question

    Quote Originally Posted by FireXtol View Post
    To open the object browser. You can either hit the F2(function 2, at the very top, left-side, of a keyboard, between F1 and F3) key. Or use the menu View | Object Browser.

    Type in what you're looking for(see screenshot if you're unsure where), and press enter(or click the button immediately to the right of the field).

    The fully qualify means to use the "Member of:" as a prefix: VBA.Strings.Left$. Strings.Left$ also works.

    Another example: place Command1 button on a form. Referencing Command1 works fine inside of the form(Command1.Caption = "Hello World", for instance). But you can also use Form1.Command1.Caption.

    It's the difference between explicitly(fully qualifying) stating 'where' something is, and allowing the compiler to implicitly figure it out. When there are multiple possibly references that the compiler could implicitly assume you'll end up with "ambiguous name detected" error. The solution is to either rename, or fully qualify.

    Excuse my 'hacked' color scheme(I realize the button icons appear oddly!).
    Lmao, thanks that was very helpful information I can use for not just now but the future, I appreciate it. I understand more now thanks to this info., makes sense.

    Anyway, I tried doing it the way you showed me earlier and above, and it works actually better (vba.string.left$/right$).

  9. #9

    Thread Starter
    Lively Member
    Join Date
    Apr 2010
    Location
    Southern California
    Posts
    88

    Re: Ambigious Error Detected / Left / Right Question

    Quote Originally Posted by Golgo1 View Post
    If you havnt found the solution yet, I want to propose a different option:
    many MANY times I have had a duplicate declaration of some kind (usually a function) and when trying to compile the error is thrown, highlighting a seemingly random and unrelated section of code. However I have noticed that about 80% of the time it is on a Left() or Right()

    My tip is just to not get tunnel vision and look only for problems with your Left()
    Do a quick look over the rest of the project for anything else that may be out of sorts.


    PS: Ive also had strange error locations if my API declarations were incorrect, specifically the argument types.
    This really helps me a lot for future references, thanks for the tip. Your right some times it's other pieces of code causing an error you would least suspect when you're only looking at that single code for the error.

  10. #10
    PowerPoster
    Join Date
    Dec 2004
    Posts
    25,618

    Re: Ambigious Error Detected / Left / Right Question

    check project references for any missing references
    this will give the problem described, but also other problems you may not notice for some time
    i do my best to test code works before i post it, but sometimes am unable to do so for some reason, and usually say so if this is the case.
    Note code snippets posted are just that and do not include error handling that is required in real world applications, but avoid On Error Resume Next

    dim all variables as required as often i have done so elsewhere in my code but only posted the relevant part

    come back and mark your original post as resolved if your problem is fixed
    pete

Posting Permissions

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



Click Here to Expand Forum to Full Width