2013-11-14 17 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

相关问题