I wrote a function to do some basic string parsing but for reasons currently unknown to me, my compiler keeps flagging my code for a type mismatch error. The function takes a string, replaces some characters with a space and then uses a split to turn the output into an array. The function is then set to the output array. When run, the function complete's its process but the compiler then throws the type mismatch error in the calling module. Code is below, thank you in advance for your assistance.
Sub Tester()
Dim TestArr()
Dim TestVar As String
Application.Calculation = xlCalculationManual
Application.DisplayAlerts = False
Application.ScreenUpdating = False
TestVar = "Text-with/characters I need to\remove"
Debug.Print InputParser(TestVar)
Application.Calculation = xlCalculationAutomatic
Application.DisplayAlerts = True
Application.ScreenUpdating = True
End Sub
'-----------------------------------------------------------------------------------------------------------------------------------
Function InputParser(InputStr As String)
Dim OutputArr() As String
If InStr(1, InputStr, "/", vbBinaryCompare) >= 1 Or _
InStr(1, InputStr, "\", vbBinaryCompare) >= 1 Or _
InStr(1, InputStr, "-", vbBinaryCompare) >= 1 Or _
Left(InputStr, 1) = "'" Then.
InputStr = Replace(InputStr, "/", " ", 1, , vbBinaryCompare)
InputStr = Replace(InputStr, "\", " ", 1, , vbBinaryCompare)
InputStr = Replace(InputStr, "-", " ", 1, , vbBinaryCompare)
InputStr = Replace(InputStr, "'", vbNullString, 1, 1, vbBinaryCompare)
OutputArr = Split(InputStr, " ", Compare:=vbBinaryCompare)
Debug.Print Join(OutputArr, vbCrLf)
Debug.Print TypeName(OutputArr)
End If
InputParser = OutputArr
Debug.Print TypeName(InputParser)
End Function