+ Reply to Thread
Results 1 to 2 of 2

highlight text in userform textbox

  1. #1
    RB Smissaert
    Guest

    highlight text in userform textbox

    How would I highlight a certain character in a plain multiline textbox on a
    userform
    given the line number and the character number in that line?

    So for example given this text:

    This is a test.
    Trying to highlight.

    and given line number 2 and character number 15
    the character l in the second line would be highlighted.

    RBS


  2. #2
    RB Smissaert
    Guest

    Re: highlight text in userform textbox

    Not the most elegant method perhaps, but it does work:


    Option Explicit

    Private Sub UserForm_Initialize()

    TextBox1.Text = "0 - Option Explicit" & vbCrLf & _
    "1 - Option Compare Binary" & vbCrLf & _
    "2 - Public IDWhereSQL As String" & vbCrLf & _
    "3 - Public DoAddress As Boolean" & vbCrLf & _
    "4 - Public DoPhone As Boolean" & vbCrLf & _
    "5 - Private IDSelectSQL As String" & vbCrLf & _
    "6 - Private IDFromClause As String" & vbCrLf & _
    "7 - Private DoIDFromClause As Boolean"

    TextBox2.Text = "2"
    TextBox3.Text = "0"

    End Sub


    Private Sub CommandButton1_Click()

    Dim i As Long
    Dim lCurXStart As Long
    Dim lChar As Long
    Dim lLineToReach As Long
    Dim lCharToReach As Long

    lLineToReach = Val(TextBox2.Text)
    lCharToReach = Val(TextBox3.Text)

    With TextBox1

    .SetFocus
    .SelStart = 0

    'this is the position at the
    'very left margin of the textbox
    '---------------------------------------
    lCurXStart = .CurX

    Do Until (.CurLine = lLineToReach And _
    lChar = lCharToReach) Or i = Len(.Text)

    .SelStart = i
    lChar = lChar + 1
    i = i + 1

    'reset the lChar at the left margin
    '----------------------------------
    If .CurX = lCurXStart Then
    lChar = 0
    End If

    DoEvents
    Loop

    .SelLength = 1

    End With

    End Sub


    RBS


    "RB Smissaert" <[email protected]> wrote in message
    news:[email protected]...
    > How would I highlight a certain character in a plain multiline textbox on
    > a userform
    > given the line number and the character number in that line?
    >
    > So for example given this text:
    >
    > This is a test.
    > Trying to highlight.
    >
    > and given line number 2 and character number 15
    > the character l in the second line would be highlighted.
    >
    > 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