CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 15 of 15
  1. #1
    Join Date
    May 2001
    Posts
    18

    How to get Mid(),Left(),Right()...to Work?

    Hi,

    I always have problem with Mid(),Left(),Right(),Format()..
    When I run on one PC, they all worked. But when I run on my PC, the runtime intepreter complains "object not found".

    I suppose I need to include something in the components for the VB to recognise these methods? Pls advice.



  2. #2
    Join Date
    Sep 2001
    Location
    IL, USA
    Posts
    1,090

    Re: How to get Mid(),Left(),Right()...to Work?

    Mid(),Left(),Right() take as a first argument a string. So if you're getting the error you mentioned, that means you could be using objects instead of strings. Show some sample and hpefully you'll get a better answer.


    Help us improve our answers by rating them.


  3. #3
    Join Date
    Feb 2000
    Location
    Ireland
    Posts
    808

    Re: How to get Mid(),Left(),Right()...to Work?

    Another reason that they mightn't work is due to a missing reference.
    Have a look at the references in your project on the machine that they don't work on. Does one of them say MISSING beside it? If so you will need to install whatever dlls etc you need


  4. #4
    Join Date
    Sep 2001
    Location
    IL, USA
    Posts
    1,090

    Re: How to get Mid(),Left(),Right()...to Work?

    Good Point.


  5. #5
    Join Date
    Feb 2002
    Location
    Makati City, Philippines
    Posts
    1,054

    Re: How to get Mid(),Left(),Right()...to Work?

    I have experienced this with Excel VBA. The only solution I made was set the references to the minimum before programming. I can't understand why, but it worked.

    Marketing our skills - please participate in the survey and share your insights
    -

  6. #6
    Join Date
    May 2001
    Posts
    18

    Re: How to get Mid(),Left(),Right()...to Work?


    If (Left(NRIC_Text,8) = "") then
    MsgBox "No NRIC Enter.", vbExclamation
    NRIC_Text.SetFocus
    Exit Sub
    End If




    The Left() is not recognised here. However, if I write "Strings.Left()", it is ok.

    I tell u, this thing is very perculiar. When I start a new project and start writing "Left()" or "Right()" etc, everything is fine. But if I open a project written by my friend, the problem surfaces.
    When I compare all references and components with my own project, they all appear the same


  7. #7
    Join Date
    Sep 2001
    Location
    IL, USA
    Posts
    1,090

    Re: How to get Mid(),Left(),Right()...to Work?

    Debug the code bellow and tell me which line gives the error. It seems that on the form there is a textbox called NRIC_Text. Is this correct?
    private Sub Command2_Click()
    Debug.print NRIC_Text
    If (Left(NRIC_Text, 8) = "") then
    MsgBox "No NRIC Enter.", vbExclamation
    NRIC_Text.SetFocus
    Exit Sub
    End If
    End Sub


    Help us improve our answers by rating them.


  8. #8
    Join Date
    May 2001
    Posts
    18

    Re: How to get Mid(),Left(),Right()...to Work?

    The error occurs at "Left()" when it complains "Compile error. Can't find project or library"


    private Sub Command2_Click()
    Debug.print NRIC_Text
    If (Left(NRIC_Text, 8) = "") then
    MsgBox "No NRIC Enter.", vbExclamation
    NRIC_Text.SetFocus
    Exit Sub
    End If
    End Sub






  9. #9
    Join Date
    Sep 2001
    Location
    IL, USA
    Posts
    1,090

    Re: How to get Mid(),Left(),Right()...to Work?

    It seems the error has changed. Any way I think the next step is to check Refrences. So select from the main menu, menu item Project then select References. Now list in order the checked references. Also click on each reference, without unchecking it, and record its location. You can read the location at the bottom of the references dialog. Check if in any of these references you have the word Missing. Post all this information.



    Help us improve our answers by rating them.


  10. #10
    Join Date
    Mar 2002
    Posts
    3

    Re: How to get Mid(),Left(),Right()...to Work?

    might be ur arguments are not correct


  11. #11
    Join Date
    Jul 2000
    Location
    Milano, Italy
    Posts
    7,726

    Re: How to get Mid(),Left(),Right()...to Work?

    It seems as if you (or someone else, somewhere) have subclassed the Left, Mid, Right functions
    Try adding the prefix Vba
    ie:
    ... Vba.Left( ...


    Special thanks to Lothar "the Great" Haensler, Tom Archer, Chris Eastwood, TCartwright, Bruno Paris, Dr_Michael
    and all the other wonderful people who made and make Codeguru a great place.
    Come back soon, you Gurus.

    The Rater
    ...at present time, using mainly Net 4.0, Vs 2010



    Special thanks to Lothar "the Great" Haensler, Chris Eastwood , dr_Michael, ClearCode, Iouri and
    all the other wonderful people who made and make Codeguru a great place.
    Come back soon, you Gurus.

  12. #12
    Join Date
    Feb 2002
    Location
    Makati City, Philippines
    Posts
    1,054

    Re: How to get Mid(),Left(),Right()...to Work?

    Try this:

    1. Open your code on machines where it doesn’t work
    2. Check the references. You will see some references tagged as MISSING. Identify them.
    3. Open your code again on machines where it works.
    4. Deselect references tagged MISSING in other machine where it doesn’t work.
    5. Save (without those references) and test it again on other machines.

    If it will work this time, then, you have experienced what I have experienced before.

    Some installation options automatically attach some references to your code even if you won’t need them. To avoid this, set your references to the minimum when you start your next VB project.

    I can't understand why Left(), Mid() etc, will not work if you have referenced, for example, 'mscal.ocx' in your original machine, and is missing in other machines. It seems to me (and you'll probably agree) they are not related. But that's how things worked. Microsoft probably goofed here.

    Marketing our skills - please participate in the survey and share your insights
    -

  13. #13
    Join Date
    May 2001
    Posts
    18

    Re: How to get Mid(),Left(),Right()...to Work?

    I guess u are right. I uncheck the MISSING Reference, and the thing works! Really it's Microsoft bug, again.
    However, only the 'Left()' still doesn't work. When I write 'strings.Left()' it's ok. Why, now?


  14. #14
    Join Date
    Feb 2002
    Location
    Makati City, Philippines
    Posts
    1,054

    Re: How to get Mid(),Left(),Right()...to Work?

    That still sound stranged to me. You are probably still referencing some MISSING components. That problem can only be corrected on machines with exactly the same installation options of machine where the program was originally written -- another stranged behavior.

    Anyway, just an idea -- Everytime, I start a new project, I would deselect everything except Visual Basic for Applications and Microsoft Excel 9.0 Object Library. Usually, next in line are OLE Automation and Microsoft Office 9.0 Object Library. Then, add only 1 reference at a time if my program requires it.

    Sorry, except for the things explained above, I don't have other comprehensive explanation as to 'Why'.

    By the way, I am just curious. Try copy the 'mscal.ocx' to machine where you still have problem.

    Marketing our skills - please participate in the survey and share your insights
    -

  15. #15
    Join Date
    Apr 2000
    Location
    South Carolina,USA
    Posts
    2,210

    Re: How to get Mid(),Left(),Right()...to Work?

    Another possibility I have not seen mentioned is the ORDEr of the References. I have seen it where two or more refereences use the same property, function or method with the first one in the order interferring with the second. Changing the order via the Priority up,down arrows in the References solved the problem. Another soultion is to prefix the function with the parent like you have done.

    '
    '
    Please rate it if it answers the question
    or is useful.
    '
    John G

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

Featured