使用 Len() 时出错

Error when using Len()

我有以下代码块:

Public Function GetDate(ByVal adate AS String) AS String
    Dim len AS Integer = Len(adate) /*problem line*/
    Dim strSubstr AS String = Mid(adate, 0, len-2)
    Dim compStr AS String = strSubstr + "00"

    return compStr
End Function

我遇到一个错误:

Expression is not an array or method, and cannot have an argument list

我是 VB 的新手,但我觉得我这样做是正确的,我在这里错过了什么?

编辑:

这就是最终对我有用的方法:

Public Function GetDate(ByVal adate AS String) AS String
    Dim mylen AS Integer = adate.Length
    Dim strSubstr AS String = adate.Substring(0, mylen-2)
    Dim compStr AS String = strSubstr & "00"

    return compStr
End Function

它似乎给了你一个错误,因为你正在使用 vb 关键字 (len) 作为变量。

试试这个:

 Public Function GetDate(ByVal adate As String) As String
        Dim myLen As Integer = Len(adate)
        Dim strSubstr As String = Mid(adate, 0, myLen - 2)
        Dim compStr As String = strSubstr + "00"

        Return compStr
    End Function

这就是最终对我有用的方法:

Public Function GetDate(ByVal adate AS String) AS String
    Dim mylen AS Integer = adate.Length
    Dim strSubstr AS String = adate.Substring(0, mylen-2)
    Dim compStr AS String = strSubstr & "00"

    return compStr
End Function