使用分割功能为阵造成编译错误:无法分配给数组 [英] Using split function into array is causing Compile Error: Can't Assign to array

查看:194
本文介绍了使用分割功能为阵造成编译错误:无法分配给数组的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我试图使用拆分()函数打出的基础上,在给定的名称字符串空格的名称。当试图编译code我写了下面我得到一个编译错误:不能分配到阵列

我有pretty的多复制了微软的例子在这里:的https:/ /support.microsoft.com/en-us/kb/266289

谁能告诉我什么,我做错了什么?

 公共功能cleanName(位置为整数,inName作为字符串)作为字符串

昏暗nameArray()作为字符串
昏暗outName为Variant

nameArray =分割(inName,)

选择案例位置
    案例1标题
        outName = nameArray(0)
    案例2'名字
        outName = nameArray(1)
    案例3'中间名
        outName = nameArray(2)
    案例4姓
        outName = nameArray(3)
    案例五'后缀
        outName = nameArray(4)
    案例否则
最终选择

cleanName = outName

端功能
 

解决方案

我回来到这一点,因为我已经学会了的回答是,我的同事写了一个模块,称为分里面存放我的previous从工作,因为它code返回一组不同的参数。

I am attempting to use the split() function to split out a name based on spaces in the given name string. When attempting to compile the code I've written below I get a Compile error: "Can't Assign to array".

I've pretty much copied the microsoft's example from here: https://support.microsoft.com/en-us/kb/266289

Can anyone tell me what I am doing wrong?

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

解决方案

I'm coming back to this since I've learn the answer was that my co-worker had written a module called split which kept my previous code from working as it returned a different set of parameters.

这篇关于使用分割功能为阵造成编译错误:无法分配给数组的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆