2013-11-14 19 views
-1

當你打開記事本並輸入10行後&然後點擊找到它打開對話框 當我們選擇單選按鈕時。它在上方找到字符串。我想在VB 6.0代碼做同樣的搜索過程 我曾嘗試這個代碼,但它正向查找字符串在vb 6.0中如何向後搜索一個字符串

Private Sub btnfind_Click() 

    str = InputBox("Enter string to search", "Find") 
    pos = RichTextBox1.Find(str) 
    If pos <> -1 Then 
     RichTextBox1.SetFocus 
    Else 
     MsgBox "not found" 
    End If 

    btnfindnext.Enabled = True 
    btnprevious.Enabled = True 

End Sub 

Private Sub btnfindnext_Click() 

    pos = RichTextBox1.Find(str, pos + 1) 
    If pos <> -1 Then 
     RichTextBox1.SetFocus 
    Else 
     pos = RichTextBox1.Find(str, 0) 
     RichTextBox1.SetFocus 
    End If 

End Sub 
+2

什麼樣的代碼你試過嗎? – BenR

回答

2

你想要的InstrRev功能:

返回一個Long,指定一個位置另一個字符串。搜索從最後一個字符位置開始,或者在start參數指定的位置開始,然後返回到字符串的開頭(當找到string2或到達string1的開頭時停止搜索)。

Have a look at this的語法

+0

感謝您的幫助,我通過使用instrrev完成了它 – user2971979

相關問題