+ Reply to Thread
Results 1 to 5 of 5

left()

  1. #1
    Registered User
    Join Date
    02-22-2006
    Posts
    6

    left()

    Why the command

    b=Left(poz, InStr(poz, "!") + 1)

    is working and

    b=Left(poz, InStr(poz, "!") - 1)

    doesn't work? It say: Invalid procedure call or argument...

  2. #2
    Norman Jones
    Guest

    Re: left()

    Hi M,

    If the exclamation character (!) is found, both expressions work for me.

    If however, the character is not found, then the exptrssion:

    InStr(poz, "!") - 1

    equates to -1 which is an invalid in the Left function,


    ---
    Regards,
    Norman



    "mpele" <[email protected]> wrote in
    message news:[email protected]...
    >
    > Why the command
    >
    > b=Left(poz, InStr(poz, "!") + 1)
    >
    > is working and
    >
    > b=Left(poz, InStr(poz, "!") - 1)
    >
    > doesn't work? It say: Invalid procedure call or argument...
    >
    >
    > --
    > mpele
    > ------------------------------------------------------------------------
    > mpele's Profile:
    > http://www.excelforum.com/member.php...o&userid=31808
    > View this thread: http://www.excelforum.com/showthread...hreadid=520041
    >




  3. #3
    Bob Phillips
    Guest

    Re: left()

    If it doesn't find ! in the string poz, then the Instr returns 0. Subtract 1
    from that, and you are then trying to get the leftmost -1 characters. Hence,
    it is invalid.

    You should test it

    if InStr(poz, "!")> 0 Then
    b=Left(poz, InStr(poz, "!") - 1)
    Else
    b = poz
    End If


    --
    HTH

    Bob Phillips

    (remove nothere from email address if mailing direct)

    "mpele" <[email protected]> wrote in
    message news:[email protected]...
    >
    > Why the command
    >
    > b=Left(poz, InStr(poz, "!") + 1)
    >
    > is working and
    >
    > b=Left(poz, InStr(poz, "!") - 1)
    >
    > doesn't work? It say: Invalid procedure call or argument...
    >
    >
    > --
    > mpele
    > ------------------------------------------------------------------------
    > mpele's Profile:

    http://www.excelforum.com/member.php...o&userid=31808
    > View this thread: http://www.excelforum.com/showthread...hreadid=520041
    >




  4. #4
    Registered User
    Join Date
    02-22-2006
    Posts
    6
    [QUOTE=Norman Jones]Hi M,

    If the exclamation character (!) is found, both expressions work for me.

    InStr gives result 6 but I need value 5 for function left.
    What am I doing wrong? or what can I do wrong?!?

  5. #5
    Norman Jones
    Guest

    Re: left()

    Hi M,

    Your error is consistent with the exclamation character not being found.

    If the expression:

    InStr(poz, "!")

    returns 6, as you suggest, I would not expect either of your original
    expressions:

    > b=Left(poz, InStr(poz, "!") + 1)

    or
    > b=Left(poz, InStr(poz, "!") - 1)


    to produce your encountered error.


    ---
    Regards,
    Norman



    "mpele" <[email protected]> wrote in message
    news:[email protected]...
    >
    > Norman Jones Wrote:
    >> Hi M,
    >>
    >> If the exclamation character (!) is found, both expressions work for
    >> me.
    >>
    >> InStr gives result 6 but I need value 5 for function left.
    >> What am I doing wrong? or what can I do wrong?!?

    >
    >
    > --
    > mpele
    > ------------------------------------------------------------------------
    > mpele's Profile:
    > http://www.excelforum.com/member.php...o&userid=31808
    > View this thread: http://www.excelforum.com/showthread...hreadid=520041
    >




+ 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