vb选取字符问题

来源:百度知道 编辑:UC知道 时间:2024/06/02 17:16:07
比如在Text1中输入123456.exe,如何才能按一下按钮就能选中123456?无论前面有多少字符,.exe都不要选中。

Private Sub Command1_Click()
If LCase(Right(Text1.Text, 4)) = ".exe" Then
Text1.SelStart = 0
Text1.SelLength = Len(Text1.Text) - Len(".exe")
Text1.SetFocus
End If
End Sub

Private Sub Command1_Click()
Dim a As String

a = Text1.Text
If InStr(1, a, ".") > 0 Then
Text1.SelStart = 0
Text1.SelLength = InStr(1, a, ".exe") - 1
End If
End Sub