Dim myName As String
Dim firstName As String
Dim lastName As String
Dim space As Integer
Dim nameLen As Integer
myName = txtName.Text
firstName = txtFirstName.Text
lastName = txtLastName.Text
nameLen = Len(myName)
space = InStr(myName, " ")
Do Until space > 0
firstName = Microsoft.VisualBasic.Left(myName, space - 1)
lastName = Microsoft.VisualBasic.Right(myName, nameLen - space)
Loop
txtFirstName.Text = firstName
txtLastName.Text = lastName
正如我编写的代码,我尝试使用len函数,InStr函数,左右函数来使程序在单独的文本框中显示名字和姓氏。但是,当我输入任何全名时,单击解析名称按钮。名字和姓氏不会出现在两个文本框中。有人可以帮我纠正吗?我将不胜感激!
答案 0 :(得分:1)
Dim myName As String
Dim firstName As String
Dim lastName As String
Dim space As Integer
Dim nameLen As Integer
myName = txtName.Text
firstName = txtFirstName.Text
lastName = txtLastName.Text
nameLen = Len(myName)
space = InStr(myName, " ")
firstName = VBA.Strings.Left(myName, space - 1)
lastName = Right(myName, nameLen - space)
txtFirstName.Text = firstName
txtLastName.Text = lastName