在Visual Basic 6.0中,如何移动到特定行?

时间:2013-11-21 07:19:30

标签: vb6

在记事本中,在编辑菜单下,有转到按钮移动到特定行。我试图在Visual Basic 6.0中对此进行编码,但它不起作用。代码如下所示

Private sub goto_click()
    Dim s As String
    s = InputBox("Enter line number")
    If IsNumeric(s) = True Then
        RichTextBox1.SelStart = RichTextBox1.GetLineFromChar(s - 1)
        RichTextBox1.Move (s)
        RichTextBox1.SetFocus
    End If
End Sub

2 个答案:

答案 0 :(得分:0)

已经很久了,我的系统上没有VB6了。我从网上的各个位置拼凑了这个。希望它确实有效...我无法测试它:

Private Const EM_LINEINDEX = &HBB 

Private Declare Function SendMessage Lib "user32" Alias "SendMessageA" _
    (ByVal hWnd As Long, ByVal wMsg As Long, _
    ByVal wParam As Any, ByVal LParam As Any) As Long

Private Sub goto_click()
    Dim s As String
    s = InputBox("Enter Line Number")
    If IsNumeric(s) Then
        Dim index As Long 
        index = SendMessage(RichTextBox1.hWnd, EM_LINEINDEX, CLng(s) - 1, 0)
        RichTextBox1.SelStart = index
        RichTextBox1.SetFocus
    End If        
End Sub

答案 1 :(得分:0)

我测试了这段代码并且工作正常。

Private Const EM_LINEINDEX = &HBB

Private Declare Function SendMessage Lib "user32" Alias "SendMessageA" (
    ByVal hWnd As Long, ByVal wMsg As Long, ByVal wParam As Long, LParam As Any) As Long

Private Sub goto_Click()
    Dim s As String
    s = InputBox("Enter Line Number")
    If IsNumeric(s) Then
        Dim index As Long
        index = SendMessage(RichTextBox1.hWnd, EM_LINEINDEX, CLng(s) - 1, 0)
        RichTextBox1.SelStart = index
        RichTextBox1.SetFocus
    End If
End Sub