2013-11-21 22 views
0

在記事本中,在編輯菜單下有一個Goto按鈕來移動到特定行。我試圖在VB 6.0中對此進行編碼,但它不起作用。代碼如下所示在vb 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 

回答

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 
+0

不,它不起作用它給第一行編譯錯誤,因爲常量固定長度字符串和聲明語句不允許作爲對象模塊的公共成員。我把它作爲私人,但它再次給出錯誤類型不匹配在私人sub goto_click – user2971979

+0

什麼是錯誤? –

+0

您可能需要將這兩個「Public」更改爲「Private」。 –

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