Search code examples
vb6

VB6 function issue in the return expression "end of statement expected"


I am new to vb6 and I get a compiler error in my function when trying to return my variable.

"end of statement expected error vb6"

my function goes as following:

Public Function StringFormat(ByVal MyStr As String) As String
   
   Dim i As Integer
   Dim sBadChar As String
   Dim NewString As String
   
   ' List all illegal/unwanted characters
   sBadChar = "/<>?\{}[]()=,!#*:'*¬-"

   ' Loop through all the characters of the string
   For i = 1 To Len(MyStr)
       If InStr(sBadChar, Mid(MyStr, i, 1)) Then
           Mid(MyStr, i, 1) = ""
       End If
   Next i
   
   Return MyStr
   
End Function

I get the error on the return, any ideas as of why this happens? thank you in advance


Solution

  • Should be:

    Public Function StringFormat(ByVal MyStr As String) As String
       
       Dim i As Integer
       Dim sBadChar As String
       Dim NewString As String
       
       ' List all illegal/unwanted characters
       sBadChar = "/<>?\{}[]()=,!#*:'*¬-"
    
       ' Loop through all the characters of the string
    
           For i = 1 To Len(MyStr)
               If InStr(sBadChar, Mid(MyStr, i, 1)) Then
                   Mid(MyStr, i, 1) = ""
               End If
           Next i
           
           StringFormat = MyStr 
          
        End Function