Results 1 to 6 of 6

Thread: Goto line in text box

  1. #1

    Thread Starter
    New Member
    Join Date
    Jan 2006
    Posts
    7

    Goto line in text box

    In a text box, how do you get it to have the selecting thing (no clue what its called) to start at the beginning of a line if you input a line number into a textbox?

    Or easier to say, how would I go about doing goto like in Notepad?

  2. #2
    I'm about to be a PowerPoster! Hack's Avatar
    Join Date
    Aug 2001
    Location
    Searching for mendhak
    Posts
    58,333

    Re: Goto line in text box

    See Post #2 in this thread. Is this what you mean?

  3. #3
    I'm about to be a PowerPoster! Joacim Andersson's Avatar
    Join Date
    Jan 1999
    Location
    Sweden
    Posts
    14,649

    Re: Goto line in text box

    VB Code:
    1. Private Declare Function SendMessage _
    2.  Lib "user32.dll" Alias "SendMessageA" ( _
    3.     ByVal hWnd As Long, _
    4.     ByVal wMsg As Long, _
    5.     ByVal wParam As Long, _
    6.     ByRef lParam As Any _
    7. ) As Long
    8.  
    9. Private Const EM_LINEINDEX As Long = &HBB
    10.  
    11. Public Sub GotoLine(txtBox As TextBox, ByVal nLineNumber As Long)
    12.     If nLineNumber > 0 Then
    13.         txtBox.SelStart = SendMessage(txtBox.hWnd, EM_LINEINDEX, nLineNumber - 1, ByVal 0)
    14.     End If
    15. End Sub
    Simply call this sub like this:
    VB Code:
    1. Call GotoLine(Text1, 3) 'jump to line 3 in the textbox named Text1

  4. #4
    Junior Member
    Join Date
    Mar 2006
    Posts
    26

    Re: Goto line in text box

    I'm no expert but this is my solution.

    Dim ss As Integer = 0
    Dim gotoLineNumber As Integer ' put line number to goto in here
    Dim LineIndex As Integer = 0
    Dim i As Integer
    While LineIndex <> gotoLineNumber - 1
    For i = 0 To MainForm.TextBox1.Lines(LineIndex).Length + 1
    ss += 1
    Next
    LineIndex += 1
    End While
    MainForm.TextBox1.SelectionStart = ss

  5. #5
    I'm about to be a PowerPoster! Joacim Andersson's Avatar
    Join Date
    Jan 1999
    Location
    Sweden
    Posts
    14,649

    Re: Goto line in text box

    @akagn: What you have supplied is VB.Net code, but this is the Classic VB Forum and the TextBox in Classic VB doesn't have a Lines property.

  6. #6
    Junior Member
    Join Date
    Mar 2006
    Posts
    26

    Re: Goto line in text box

    Ok sorry

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