在vb 6.0中如何在后向搜索字符串

时间:2013-11-14 13:23:55

标签: vb6

当你打开记事本并输入10行&然后点击查找它打开一个对话框 当我们选择单选按钮时。它找到了向上方向的字符串。我希望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

1 个答案:

答案 0 :(得分:2)

你想要InstrRev函数:

返回Long,指定一个字符串在另一个字符串中的位置。搜索从最后一个字符位置或start参数指定的位置开始,然后向后朝向字符串的开头(当找到string2或者到达string1的开头时停止)。

Have a look at this的语法

相关问题