form1.frm
来自「Visual Basic程序设计视频教程」· FRM 代码 · 共 55 行
FRM
55 行
VERSION 5.00
Begin VB.Form Form1
Caption = "查找第一个空格"
ClientHeight = 1815
ClientLeft = 60
ClientTop = 360
ClientWidth = 4725
LinkTopic = "Form1"
ScaleHeight = 1815
ScaleWidth = 4725
StartUpPosition = 3 '窗口缺省
Begin VB.CommandButton Command1
Caption = "查找"
Height = 495
Left = 3360
TabIndex = 1
Top = 240
Width = 1095
End
Begin VB.TextBox Text1
Height = 495
Left = 360
TabIndex = 0
Text = "Text1"
Top = 240
Width = 2655
End
End
Attribute VB_Name = "Form1"
Attribute VB_GlobalNameSpace = False
Attribute VB_Creatable = False
Attribute VB_PredeclaredId = True
Attribute VB_Exposed = False
Private Sub Command1_Click()
'声明变量
Dim testStr As String
Dim s As String
Dim i As Integer
'赋初值
testStr = Text1.Text
i = 1
'使用循环查找
Do
s = Mid(testStr, i, 1)
If s = " " Then '找到空格
MsgBox "第一个空格位置为:" + Str(i)
Exit Do '跳出循环
End If
i = i + 1
Loop Until (i > Len(testStr)) '当到达字符串末尾时终止循环
If i = Len(testStr) + 1 Then
MsgBox "没有空格!"
End If
End Sub
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?