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
InStrwith something, e.g.If InStr(sBadChar, Mid(MyStr, i, 1) > 0. But it might also be complaining aboutMid(MyStr, i, 1) = "", I don't recall whether that's valid in VB6, but I suspect not. You probably wantMyStr = Left(MyStr, i - 1) & Mid(MyStr, i)Note that you'll also have to handle the fact thatiis now too far ahead (because the string got shorter). You could fix that by looping backward rather than forward (For i = Len(MyStr) To 1 Step -1).