VB.net Automatically convert a Nothing value into something else


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,"")

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 = ""
Shaun VermaakTechnical Specialist/DeveloperCommented:
What about this
If String.IsNullOrEmpty(oString) Then
    oString = "Something"
End If

Open in new window

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

Dim oString As String = IIf (String.IsNullOrEmpty(X),"", X)
Murray BrownMicrosoft Cloud Azure/Excel Solution DeveloperAuthor Commented:
Thanks very much
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.