0

So I'm trying to use the iterator OutDirectoryPath from a "For Each" block as a parameter to this function:

Function GetFilePathArrayFromDirectory(directoryPath As String) As String()
    'some code here
End Function

Here is how I pass it:

Dim OutDirectoryPath
For Each OutDirectoryPath In OutFolderPaths
        
        Dim FilePathArray() As String
        
        FilePathArray = GetFilePathArrayFromDirectory(OutDirectoryPath)
    
Next OutDirectoryPath

The problem is that I get a Compile Error because every iterator from a "For Each" block is declared automatically as a "Variant", and it is assigned as a String only at runtime. My question is how can I use iterators as parameters if they will always have the "Variant" type, without changing the function's arguments to "Variant"?

2
  • Dim OutDirectoryPath As String? Commented Sep 4, 2023 at 8:50
  • 1
    @Lord-JulianXLII A String cannot be an iteration variable in a For Each. Commented Sep 4, 2023 at 9:31

1 Answer 1

1

You can convert a variant to a string by using CStr:

FilePathArray = GetFilePathArrayFromDirectory(CStr(OutDirectoryPath))

Sign up to request clarification or add additional context in comments.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.