Length of text in textbox

Barbados

Registered User.
Local time
Today, 03:55
Joined
May 22, 2013
Messages
27
Hi all,

I saw someone using the following code in a keypress event:

Code:
Dim C As Control
Set C = Screen.ActiveControl
 
' Fetch length of current contents + 1 for the character typed.
Dim CLen As Integer: CLen = Len(C.Text & "") + 1

Who knows why the & "" is being used?

Thanks.
 
Len is a String manipulation function.. Which does not like the Argument that is passed to be a Null Value.. If you try Len(Null) an Error would be raised, so to avoid the error we use an Empty String.. So it would return a value 0..

However the other concern, what if the active control is Checkbox/Option/Label? Will that not be a problem? as they do not have .Text property..
 

Users who are viewing this thread

Back
Top Bottom