My expertise is not VB, but I am having to work on a big chunk of VB at the moment.
Just about every block of code that looks at the input data uses this format:
Existing:
If textbox1.Text <> vbNullString AndAlso textbox1.Text.Trim <> vbNullString Then
textbox1.Focus()
End If
That code just irritates me.
The way I would typically write a piece of code like this would be:
ReWrite:
Dim text as String = textbox1.Text.Trim()
If String.IsNullOrEmpty(text) Then
textbox1.Focus()
End If
That is coming from my C# experience, where a TextBox Control's Text property is never NULL - even if I set it to NULL, it still reads back as an empty string.
Sure, I could test this, but I'm likely to not encounter some nuance of VB in my quick verification code.
Is my ReWrite still valid in this context?
Yes, I am using .NET 4, so I could (should?) replace String.IsNullOrEmpty with String.IsNullOrWhiteSpace - unless someone points out some reason not to.