Public Function _
CreateTextArrayFromSourceTexts(ParamArray SourceTexts() As Variant) As String()
ReDim TargetTextArray(0 To UBound(SourceTexts)) As String
For SourceTextsCellNumber = 0 To UBound(SourceTexts)
TargetTextArray(SourceTextsCellNumber) = SourceTexts(SourceTextsCellNumber)
Next SourceTextsCellNumber
CreateTextArrayFromSourceTexts = TargetTextArray
End Function
例如:
Dim TT() As String
TT = CreateTextArrayFromSourceTexts("hi", "bye", "hi", "bcd", "bYe")
Sub UseStringArray()
Dim sample() As String
sample = StringArray("dog", "cat", "horse")
End Sub
Function StringArray(ParamArray ArgList())
ReDim tempArray(UBound(ArgList)) As String
For i = 0 To UBound(ArgList)
tempArray(i) = ArgList(i)
Next
StringArray = tempArray
End Function
Public Function StringArray(ParamArray values() As Variant) As String()
Dim temp() As String
ReDim temp(LBound(values) To UBound(values))
Dim index As Long
For index = LBound(temp) To UBound(temp)
temp(index) = values(index)
Next
StringArray = temp
End Function
Public Function LongArray(ParamArray values() As Variant) As Long()
Dim temp() As Long
ReDim temp(LBound(values) To UBound(values))
Dim index As Long
For index = LBound(temp) To UBound(temp)
temp(index) = values(index)
Next
LongArray = temp
End Function
其他数据类型的例子包括:
单身
双倍
日期
当一个值不是正确的数据类型且无法转换时,将抛出一个错误,您将收到一个 Run-time error '13': Type mismatch错误。