我自己的功能有什么问题?请帮帮我. [英] What's wrong with this my own function? Help me, please.
本文介绍了我自己的功能有什么问题?请帮帮我.的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
Public Function IsEmptyText(frm As Form) As Boolean
Dim c As Control
For Each c In frm.Controls
If TypeOf c Is TextBox Then
If c.Text = Empty Or c.Text = String(Len(c.Text), " ") Then
IsEmptyText = True
Else
IsEmptyText = False
End If
End If
Next
End Function
实施:
我把上面的代码放在模块中.当我调用代码时,即使TextBoxes为空,它也会返回False.请帮助解决该问题?
Implementation:
I put the code above in Module. When I call the code it returns False even the TextBoxes are empty. Please help how to solve that problem??
推荐答案
首先:您错过了魔术字:RETURN.
无论上述情况如何,例如:
TextBox1.Text为空,
TextBox2.Text为空,
TextBox3.Text不为空.
您的函数将返回什么:false.为什么?最后一个文本框不为空.
正确的代码是:
First of all: you miss magic word: RETURN.
No matter of above, example:
TextBox1.Text is empty,
TextBox2.Text is empty,
TextBox3.Text is not empty.
What your function will return: false. Why? The last textbox is not empty.
The correct code is:
Public Function IsEmptyText(frm As Form) As Boolean
Dim c As Control
Dim bRetVal as Boolean
bRetVal = True 'default value
For Each c In frm.Controls
If TypeOf c Is TextBox Then
If Trim(c.Text) <> Empty Then 'Trim() function removes all leading and trailing white-space characters from string
bRetVal = False
Exit For 'because you find first not empty textbox
End If
End If
Next
IsEmptyText = bRetVal
End Function
这篇关于我自己的功能有什么问题?请帮帮我.的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文