帮忙做一道VB填空题!谢谢~~~

来源:百度知道 编辑:UC知道 时间:2024/05/16 18:11:24
在Text1和Text2中分别输入一串字符,单击命令按钮时,在Text1中删除掉Text2中的内容。例如Text1中输入“ABCDEFG”,Text2中输入“CD”,则单击Command1时,Text1中显示“ABEFG”。
填空完成程序。
Sub DeleStr(S1$, S2$)
Dim n%
Do
n = InStr(S1, S2)
If n = 0 Then __[1]____
S1 = Left(S1, n - 1) + __[2]__
Loop
End Sub
Private Sub Command1_Click()
Dim x$, y$
x = Text1.Text
y = Text2.Text
Call __[3]___
Text1.Text = x
End Sub
最好能在每一个关键句子后面写点注释给我看看。。谢谢各位大虾啦!
您的程序运行起来没反应啊~~

Sub DeleStr(S1$, S2$)
Dim n%
Do
n = InStr(S1, S2) '查找S1中的S2的位置
If n = 0 Then exit sub
S1 = Left(S1, n - 1) + right(S1,len(S1)-n-len(s2)+1)'这里也改一下
Loop
End Sub
Private Sub Command1_Click()
Dim x$, y$
x = Text1.Text
y = Text2.Text
Call DeleStr(x, y)'不小心这句打错了。
Text1.Text = x
End Sub

Private Sub CommandButton1_Click()

Dim x$, y$
x = UserForm1.TextBox1
y = UserForm1.TextBox2
Call DeleStr(x, y)
TextBox1 = x
End Sub

Sub DeleStr(S1$, S2$)
Dim n%
Do
n = InStr(S1, S2)'理解这个函数要注意,它表示S2在S1中的位置,例如适用的情况instr(abcdef,cd)返回值是3,不适用的情况 instr(abcdef,cf)则返回0
If n = 0 Then
Exit Do
End If
S1 = Left(S1, n - 1) + Right(S1, Len(S1) - Len(S2) - (n - 1))'主要是这一句,它的意思是,去掉相同的部分,把不相同的部分连接起来.假如 n=3则left(s1,2)=相同部分的前面,"+"号连起来的是相同部分的后面
Loop ' 我认为单在这些语句中这个DO 循环没什么用处
End Sub