VB.net Automatically convert a Nothing value into something else

Hi

In VB.net is there a way to automatically convert a "Nothing" value into something else?
For example if I have
Dim oString = X
where X is nothing
How do I automatically assign a blank string "" to that
In Access VBA it would be oString = nz(X,"")

Thanks
Murray BrownMicrosoft Cloud Azure/Excel Solution DeveloperAsked:
Who is Participating?
 
Peter HutchisonSenior Network Systems SpecialistCommented:
If you want to assign an empty string as a default value, rather than nothing use

Dim oString As String = ""
0
 
Shaun VermaakTechnical Specialist/DeveloperCommented:
What about this
If String.IsNullOrEmpty(oString) Then
    oString = "Something"
End If

Open in new window

1
 
John TsioumprisSoftware & Systems EngineerCommented:
You can also use the Null Design Pattern...
0
 
Juan OcasioApplication DeveloperCommented:
Try this:

Dim oString As String = IIf (String.IsNullOrEmpty(X),"", X)
0
 
Murray BrownMicrosoft Cloud Azure/Excel Solution DeveloperAuthor Commented:
Thanks very much
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.