IsNull in VB6 and VB.net

I have a code -

strTest=" " IsNull(Trim(strTest)) 

It returns False in VB6.

I am writing this code on VB.net but

IsNull (trim (strTest))

returns true .
So, IsNull (Trim ("")) in VB6 = at VB.net

Thanks.

+7
migration vb6 isnull
source share
1 answer

There is no IsNull function in VB.Net. Instead, it has other functions, such as String.IsNullOrEmpty function and String.Empty property, etc. To determine if a string is empty or not.

IsNull in VB6 / VBA means that the expression does not contain valid data. You get False in vb6 because you initialized strTest . It contains an empty string. You can also see THIS

Vb6

 IsNull(Trim(strTest)) 

In VB.Net, IsNullOrEmpty Indicates whether the specified string is Nothing or the string Empty .

Vb.net

 If String.IsNullOrEmpty(strTest.Trim) Then DoWhatever If strTest.Trim = String.Empty Then DoWhatever If strTest.Trim = "" Then DoWhatever '<~~ Same in VB6 as well If String.IsNullOrWhiteSpace(strTest) Then DoWhatever '<~~ VB2010 onwards only 

All this will return True in VB.Net, because the string IS EMPTY. You might want to see THIS

If your string value is all spaces, either use strTest.Trim() before using the first three parameters, or use the 4th option, which checks if it is nothing, or an empty string or all spaces.

+9
source share

All Articles