當前位置:編程學習大全網 - 源碼下載 - 如何VB中實現記事本中查找功能

如何VB中實現記事本中查找功能

Dim n As Long, chazhao As String

Private Sub Command1_Click()'這段代碼為查找

Dim s As String

s = Text1.Text

chazhao = InputBox("")

If chazhao = "" Then

MsgBox "空字符串不能查找"

Exit Sub

End If

n = InStr(s, chazhao)

If n > 0 Then

Text1.SelStart = n - 1

Text1.SelLength = Len(chazhao)

Text1.SetFocus

Else

MsgBox "不包含所查找的字符串"

End If

End Sub

Private Sub Command2_Click()'這段代碼為查找下壹個

Dim s As String, linshi As Long

If chazhao = "" Then

chazhao = InputBox("")

If chazhao = "" Then

MsgBox "空字符串不能查找"

Exit Sub

End If

End If

If n = 0 Then

s = Text1.Text

Else

s = Mid(Text1.Text, n + Len(chazhao), Len(Text1.Text) - n - Len(chazhao))

End If

linshi = n

n = InStr(s, chazhao)

If n > 0 Then

n = n + linshi

Text1.SelStart = n - 1

Text1.SelLength = Len(chazhao)

Text1.SetFocus

Else

If linshi <> 0 Then

MsgBox "沒有相似的了"

End If

End If

End Sub

  • 上一篇:華僑城濕地公園導遊華僑城濕地公園門票價格
  • 下一篇:LiteOS通信模塊教程03-AT指令播放NB-IoT通信
  • copyright 2024編程學習大全網