[Gambas-user] Dumb question - testing for an empty text box

Doriano Blengino doriano.blengino at ...1909...
Thu Mar 4 10:19:39 CET 2010


richard terry ha scritto:
> On Thursday 04 March 2010 18:07:57 Ricardo Díaz Martín wrote:
>   
>> I always use for this:
>>
>> If Len(TextBox1.Text) = 0 Then
>>     
>
> But the user could have put ascii 32's in the textbox, so need to to Trim.
>
>   
In effect, a space is different from an empty string... your original 
question was:
> simplest syntax for testing for no text in a textbox.
>   
and a space (ascii 32) *is* text (and in some program, like an editor, 
it's legitimate to "search for a blank".

Apart from that, I would prefer the test  -- textbox1.text <> "" -- 
because it is faster (no call to len()) and clearer, and easier to type 
and read (no parentheses).

Giving that the logic of the application should treat blanks as empty 
strings, it would be better to clear such fields in the GUI (I know, 
kind of boring work):

    if trim(textbox1.text)="" then textbox1.text = ""

This operation should be made as soon as possible, just after the user 
leaves the edited field, to let him know that a field with only a space 
inside is considered as empty. Probably this is too much care... and 
sometimes, programs written this way tend to be pedantic. In the end, I 
think that your original way should be the more correct, but it's 
personal taste.

I love to speak about philosophic things... :-)

Regards,
Doriano




More information about the User mailing list