本文介绍了将变量数组转换为字符串的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我试图获取一个变量变量并将其转换为字符串,以便可以对数据运行split函数.但是,每当我尝试重新定义变量时,都会出现类型不匹配错误.我已经使用了CStr(),Str()和ToString函数.没有工作.
I am trying to take a variant variable and convert it into a string so that I can run a split function on the data. However, whenever I try to redefine the variant I get a type mismatch error. I have used the CStr(), Str(), and ToString functions. None work.
我想念什么吗?
Function FlatLine(ByVal lines As Variant)
Dim flat() As String
ReDim Preserve flat(i)
For i = 0 To UBound(lines)
flat(UBound(flat)) = lines(i)
ReDim Preserve flat(LBound(flat) To UBound(flat) + 1)
Next i
Dim flat2 as String
flat2 = Cstr(flat)
^ errors there.
推荐答案
据我所知,for没用.更好的ReDim Flat并生成如下Flat2
The for is useless, as far as I can see. Better ReDim flat and generate flat2 as below
ReDim flat(UBound(lines))
flat2 = Join(flat,"|")
实际上,考虑到行以ByVal的形式出现,您可能会
in fact, given that lines is coming in as ByVal you could probably
flat2 = Join(lines,"|")
这篇关于将变量数组转换为字符串的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!