使用Len()时出错

时间:2016-01-12 17:36:22

标签: vb.net string-length

我有以下代码块:

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

我收到错误:

  

表达式不是数组或方法,也不能有参数列表

我是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

2 个答案:

答案 0 :(得分:1)

由于您使用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

答案 1 :(得分:0)

这最终对我有用:

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