急求用VB编一个小程序
设计一个查找程序,运行时在文本框text1中输入要查找的内容,单击"开始查找"按钮(command1)开始在文本框text2中查找,找到时,将找到的内容选中,"开始查找"...
设计一个查找程序,运行时在文本框text1 中输入要查找的内容,单击"开始查找"按钮(command1)开始在文本框text2中查找,找到时,将找到的内容选中,"开始查找"按钮变为"查找下一个",单击"查找下一个"按钮继续查找.当Text2中查找结束后,弹出信息对话框,显示找到的个数.
展开
4个回答
展开全部
简单的,用text控件的sel属性,
Dim n As Long, num As Long
Private Sub Command1_Click()
L = Len(Text2)
n = InStr(n, Text2, Text1)
Text2.SetFocus
If n <= L And n > 0 Then
Text2.SelStart = n - 1
Text2.SelLength = Len(Text1)
Command1.Caption = "查找下一个"
n = n + Len(Text1)
num = num + 1
Else
MsgBox "查找完毕!总共找到 " & num & " 处。"
Command1.Caption = "开始查找"
n = 1
num=0
End If
End Sub
Private Sub Form_Load()
n = 1
End Sub
Dim n As Long, num As Long
Private Sub Command1_Click()
L = Len(Text2)
n = InStr(n, Text2, Text1)
Text2.SetFocus
If n <= L And n > 0 Then
Text2.SelStart = n - 1
Text2.SelLength = Len(Text1)
Command1.Caption = "查找下一个"
n = n + Len(Text1)
num = num + 1
Else
MsgBox "查找完毕!总共找到 " & num & " 处。"
Command1.Caption = "开始查找"
n = 1
num=0
End If
End Sub
Private Sub Form_Load()
n = 1
End Sub
展开全部
新建工程,2个文本框,text1和text2, 还有1个按钮.command1
全部代码如下:
Dim i%, j%, m%
Private Sub Command1_Click()
If Command1.Caption = "开始查找" Then
j = (Len(Text2) - Len(Replace(Text2, Text1, ""))) / Len(Text1)
End If
If i = j Then GoTo ppp
If j > 0 Then
m = InStr(m, Text2, Text1)
Else
GoTo ppp
End If
Command1.Caption = "查找下一个"
Text2.SelStart = m - 1
Text2.SelLength = Len(Text1)
Text2.SetFocus
m = InStr(m + 1, Text2, Text1)
i = i + 1
Exit Sub
ppp:
MsgBox "在Text2共找到了" & j & "个Text1..."
i = 0: m = 1
Command1.Caption = "开始查找"
End Sub
Private Sub Form_Load()
i = 0: m = 1
Text1 = "i"
Text2 = "feiiskowiskiaiskdi"
Command1.Caption = "开始查找"
End Sub
全部代码如下:
Dim i%, j%, m%
Private Sub Command1_Click()
If Command1.Caption = "开始查找" Then
j = (Len(Text2) - Len(Replace(Text2, Text1, ""))) / Len(Text1)
End If
If i = j Then GoTo ppp
If j > 0 Then
m = InStr(m, Text2, Text1)
Else
GoTo ppp
End If
Command1.Caption = "查找下一个"
Text2.SelStart = m - 1
Text2.SelLength = Len(Text1)
Text2.SetFocus
m = InStr(m + 1, Text2, Text1)
i = i + 1
Exit Sub
ppp:
MsgBox "在Text2共找到了" & j & "个Text1..."
i = 0: m = 1
Command1.Caption = "开始查找"
End Sub
Private Sub Form_Load()
i = 0: m = 1
Text1 = "i"
Text2 = "feiiskowiskiaiskdi"
Command1.Caption = "开始查找"
End Sub
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
展开全部
你说的查找是在什么地方查找?查找什么?
没有这些条件,如何编程?
没有这些条件,如何编程?
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
展开全部
是呀,是数据库、文件,还是字符串。总得说清楚吧
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询