S
Steve D
Hi, All. I'd like to pass an empty Variant Array to a function by reference.
The function opens and reads a text file, and returns the populated Variant
Array. See code below. I find I have to define two variant arrays as shown
in Sub Test(), pass one to the function, then assign it to the second
Variant Array.
Question: Why can't I just call ImportAll(vWords) as shown below and have
vWords get populated ByRef?
TIA, Steve
Sub Test()
Dim vWords As Variant
Dim nWords As Variant
nWords = ImportAll(vWords) <-- This Works
'ImportAll (vWords) <--Doesn't Work
End Sub
Function ImportAll(ByRef vWords As Variant) As Variant
On Error GoTo E_Handle
Dim strImport As String
Dim lngChars As Long
Dim intFile As Integer
Dim i As Integer
intFile = FreeFile
Open "C:\Documents and Settings\username\Desktop\Capitalization
Exceptions List.txt" _
For Input As intFile
lngChars = LOF(intFile)
strImport = Input(lngChars, intFile)
vWords = Split(strImport, vbCrLf)
ImportAll = vWords
End Function
The function opens and reads a text file, and returns the populated Variant
Array. See code below. I find I have to define two variant arrays as shown
in Sub Test(), pass one to the function, then assign it to the second
Variant Array.
Question: Why can't I just call ImportAll(vWords) as shown below and have
vWords get populated ByRef?
TIA, Steve
Sub Test()
Dim vWords As Variant
Dim nWords As Variant
nWords = ImportAll(vWords) <-- This Works
'ImportAll (vWords) <--Doesn't Work
End Sub
Function ImportAll(ByRef vWords As Variant) As Variant
On Error GoTo E_Handle
Dim strImport As String
Dim lngChars As Long
Dim intFile As Integer
Dim i As Integer
intFile = FreeFile
Open "C:\Documents and Settings\username\Desktop\Capitalization
Exceptions List.txt" _
For Input As intFile
lngChars = LOF(intFile)
strImport = Input(lngChars, intFile)
vWords = Split(strImport, vbCrLf)
ImportAll = vWords
End Function