返回表达式中的 VB6 函数问题“预期语句结束”

Jea*_*rgo 0 vb6

我是 vb6 的新手,当尝试返回变量时,我的函数中出现编译器错误。

\n
\n

“语句结束预期错误vb6”

\n
\n

我的功能如下:

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

我收到错误return,关于为什么会发生这种情况有什么想法吗?\n提前谢谢您

\n

小智 5

应该:

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