我正在尝试使用split()函数根据Microsoft Access中给定名称字符串中的空格拆分名称。在尝试编译我在下面编写的代码时,我得到一个编译错误:“无法分配给数组”。
谁能告诉我我做错了什么?
Public Function cleanName(position As Integer, inName As String) As String
Dim nameArray() As String
Dim outName As Variant
nameArray = Split(inName, " ")
Select Case position
Case 1 'Titles
outName = nameArray(0)
Case 2 'First Name
outName = nameArray(1)
Case 3 'Middle Name
outName = nameArray(2)
Case 4 'Last Name
outName = nameArray(3)
Case 5 'Suffix
outName = nameArray(4)
Case Else
End Select
cleanName = outName
End Function
答案 0 :(得分:1)
尝试以这种方式修改代码:
nameArray() = Split(inname, " ")