+ Reply to Thread
Results 1 to 2 of 2

Problem SelStart and SelLength

  1. #1
    RB Smissaert
    Guest

    Problem SelStart and SelLength

    Have a plain multiline textbox on a userform and trying to
    highlight a particular bit of text according to an Interbase
    SQL statement error.

    This is the code:

    Sub HightlightSQLError(strError As String)

    Dim arr
    Dim strStringToFind As String
    Dim lColumnUnknown As Long
    Dim lTableUnknown As Long
    Dim lTokenUnknown As Long

    lColumnUnknown = InStr(1, strError, "Column unknown", vbTextCompare)
    lTableUnknown = InStr(1, strError, "Table unknown", vbTextCompare)
    lTokenUnknown = InStr(1, strError, "Token unknown", vbTextCompare)

    If lColumnUnknown > 0 Then
    arr = Split(Mid$(strError, lColumnUnknown), ",")
    strStringToFind = Trim(arr(1))
    With MainForm.SQLtxtStatement
    .SetFocus
    .SelLength = 0
    .SelStart = _
    InStr(1, .Text, strStringToFind, vbBinaryCompare) - 1
    .SelLength = Len(strStringToFind) + 1
    End With
    Else
    End If

    End Sub

    It works fine first time, but after that the right bit of text is not
    highlighted anymore, although the values
    for SelStart and SelLength are found fine.
    Strangely when I right-click the textbox the right bit of text does show
    highlighted.
    I can't use the right-click though as it has a popup menu.

    Maybe it is better if I change this textbox to a rich-text box.

    Thanks for any advice in this.


    RBS






  2. #2
    RB Smissaert
    Guest

    Re: Problem SelStart and SelLength

    I figured this out now.
    The trick is to move out of that textbox and back in again, so my relevant
    bit of code is now like this:

    With MainForm.SQLtxtStatement
    .SetFocus
    .SelStart = _
    InStr(1, .Text, strStringToFind, vbTextCompare) - 1
    .SelLength = Len(strStringToFind)
    MainForm.SQLtxtTitle.SetFocus 'this is the essential bit
    .SetFocus
    End With

    All working fine now.

    RBS


    "RB Smissaert" <[email protected]> wrote in message
    news:[email protected]...
    > Have a plain multiline textbox on a userform and trying to
    > highlight a particular bit of text according to an Interbase
    > SQL statement error.
    >
    > This is the code:
    >
    > Sub HightlightSQLError(strError As String)
    >
    > Dim arr
    > Dim strStringToFind As String
    > Dim lColumnUnknown As Long
    > Dim lTableUnknown As Long
    > Dim lTokenUnknown As Long
    >
    > lColumnUnknown = InStr(1, strError, "Column unknown", vbTextCompare)
    > lTableUnknown = InStr(1, strError, "Table unknown", vbTextCompare)
    > lTokenUnknown = InStr(1, strError, "Token unknown", vbTextCompare)
    >
    > If lColumnUnknown > 0 Then
    > arr = Split(Mid$(strError, lColumnUnknown), ",")
    > strStringToFind = Trim(arr(1))
    > With MainForm.SQLtxtStatement
    > .SetFocus
    > .SelLength = 0
    > .SelStart = _
    > InStr(1, .Text, strStringToFind, vbBinaryCompare) - 1
    > .SelLength = Len(strStringToFind) + 1
    > End With
    > Else
    > End If
    >
    > End Sub
    >
    > It works fine first time, but after that the right bit of text is not
    > highlighted anymore, although the values
    > for SelStart and SelLength are found fine.
    > Strangely when I right-click the textbox the right bit of text does show
    > highlighted.
    > I can't use the right-click though as it has a popup menu.
    >
    > Maybe it is better if I change this textbox to a rich-text box.
    >
    > Thanks for any advice in this.
    >
    >
    > RBS
    >
    >
    >
    >
    >



+ 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