Results 1 to 6 of 6
  1. #1
    Gold Lounger
    Join Date
    Dec 2000
    Location
    Hollywood (sorta), California, USA
    Posts
    2,759
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Old Bug?? (Word 97 (Ok, Sammy?))

    Yes, 97. Have not tested in later versions:

    Why does this not generate an error:

    Select Case UCase(Left$(sWord, 2))
    Case "XX"
    bla bla
    Case "YY"
    bla bla bla
    End Select

    when sWord = "&" --->length = 1

    THERE IS NO "On Error Resume" or Goto in the Sub in which
    this code appears.
    Kevin <IMG SRC=http://www.wopr.com/w3tuserpics/Kevin_sig.gif alt="Keep the change, ya filthy animal...">
    <img src=/w3timages/blackline.gif width=33% height=2><img src=/w3timages/redline.gif width=33% height=2><img src=/w3timages/blackline.gif width=33% height=2>

  2. #2
    Plutonium Lounger
    Join Date
    Mar 2002
    Posts
    84,353
    Thanks
    0
    Thanked 29 Times in 29 Posts

    Re: Old Bug?? (Word 97 (Ok, Sammy?))

    The string functions are rather forgiving, which can be a blessing or a curse depending on your context.

    Left, Mid, Right and InStr don't complain if you ask them to return more characters than are available. They sigh just outside your hearing, then return the available characters. If it's really important to you, you'll have to check string lengths yourself before using Left, Mid or Right.

    (By the way, this is not specific to Word 97, these are general VB functions. They still behave the same in Office XP VBA, which is based on VB6)

  3. #3
    Gold Lounger
    Join Date
    Dec 2000
    Location
    New Hampshire, USA
    Posts
    3,386
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: Old Bug?? (Word 97 (Ok, Sammy?))

    <pre>If Len(sWord) > 1 then
    Select Case UCase(Left$(sWord, 2))
    Case "XX"
    bla bla
    Case "YY"
    bla bla bla
    Case Else
    MsgBox "Unexpected stuff!"
    End Select
    Else
    Whatever
    End If
    </pre>


  4. #4
    Gold Lounger
    Join Date
    Dec 2000
    Location
    Hollywood (sorta), California, USA
    Posts
    2,759
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: Old Bug?? (Word 97 (Ok, Sammy?))

    Probably part of the VB "mentality" -- therefore, not a bug. I discovered this error after converting
    code to C# which is not the least bit forgiving in matters like this. Which is fine.
    Kevin <IMG SRC=http://www.wopr.com/w3tuserpics/Kevin_sig.gif alt="Keep the change, ya filthy animal...">
    <img src=/w3timages/blackline.gif width=33% height=2><img src=/w3timages/redline.gif width=33% height=2><img src=/w3timages/blackline.gif width=33% height=2>

  5. #5
    Gold Lounger
    Join Date
    Dec 2000
    Location
    Hollywood (sorta), California, USA
    Posts
    2,759
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: Old Bug?? (Word 97 (Ok, Sammy?))

    Looks like a suitable workaround. Thank you.
    Kevin <IMG SRC=http://www.wopr.com/w3tuserpics/Kevin_sig.gif alt="Keep the change, ya filthy animal...">
    <img src=/w3timages/blackline.gif width=33% height=2><img src=/w3timages/redline.gif width=33% height=2><img src=/w3timages/blackline.gif width=33% height=2>

  6. #6
    Gold Lounger
    Join Date
    Dec 2000
    Location
    New Hampshire, USA
    Posts
    3,386
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: Old Bug?? (Word 97 (Ok, Sammy?))

    Ayup, it's not a bug.

Posting Permissions

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