从函数VBA

时间:2016-07-15 08:57:41

标签: vba vb6 access-vba

看起来很奇怪,虽然代码看似正确但我总是得到一个False布尔值:

  • AgencyNameResult = CheckLenght(AgencyName,2)
  • AgencyWebsiteResult = CheckLenght(AgencyWebsite,5)。

你能辨别出错误吗?

Public Function CheckLenght(value As String, CharLimit As Integer) As Boolean

 Dim StringLength As Integer

 StringLength = Len(value)

 If StringLength > CharLimit Then
  CheckLength = True
 Else
  CheckLength = False
 End If

End Function

Private Sub btAddAgency_Click()

Dim AgencyName As String
Dim AgencyWebsite As String,
Dim AgencyNameResult As Boolean
Dim AgencyWebsiteResult As Boolean

Me.tbAgencyName.SetFocus
AgencyName = Me.tbAgencyName.Text
Me.tbAgencyWebsite.SetFocus
AgencyWebsite = Me.tbAgencyWebsite.Text

AgencyNameResult = CheckLenght(AgencyName, 2)
AgencyWebsiteResult = CheckLenght(AgencyWebsite, 5)

....

1 个答案:

答案 0 :(得分:1)

您的功能称为

Public Function CheckLenght

然而,您尝试将返回值分配给

  CheckLength = False

解决方案:

将您的功能重命名为

Public Function CheckLength