自定义函数中的语法错误
我在下面的代码的第一行中得到一个语法错误 。 我正在使用MSDN中显示的数组函数参数 。 从String()中删除括号后,错误消失,但我需要一个string数组。 我的代码到目前为止:
Private Function Contains(name As String, names As String()) As Boolean Contains = False Dim Index As Integer For Index = 0 To names.GetUpperBound(0) If names(Index) = name Then Contains = True Exit For End If Next End Function
数组的括号应该在variables名之后,而不是在types之后:
names() as String
代替
names as String()
顺便说一句: name
和names
是不好的variables名称使用! 最好是更有一点descirptive。
尝试这个。
Private Function Contains(name As String, names() As String) As Boolean
要么
Private Function Contains(name As String, ByRef names() As String) As Boolean
取决于你需要什么。