江口拓也雪乃:VB函数问题,在一字符串中找某一个字符

来源:百度文库 编辑:高校问答 时间:2024/04/19 09:08:28
题目是这样的:字符串k="abcdef",其中abcdef每次只能出现一次,做个函数用来检查,每一次字符串k中是哪个字符。

这样就可以了

Private Sub Command2_Click()
Dim i As Integer
Dim j As Integer
Dim str As String
For i = 1 To Len(k)
str = Mid(k, i, 1)

For j = 1 To Len(k)
If i <> j Then
If str = Mid(k, j, 1) Then
bState = True
GoTo MsgTag
Else
bState = False
End If
End If
Next j
Next i

If bState = False Then
MsgBox "不存在"
End If
Exit Sub
MsgTag:
MsgBox "存在"
End Sub