Determinate whether a 'Char' is null

  • Thread starter Thread starter Guest
  • Start date Start date
G

Guest

How do you determinate whether a varible of data type 'Char' is null or not?

I used the following code, but it seemed that it didn't work:

Dim ans As Char
If ans = "" Then
MsgBox("Ans contains no value")
Else
MsgBox("Ans contains a value")
End If

Thanks.
 
Xero said:
How do you determinate whether a varible of data type 'Char' is null or not?

I used the following code, but it seemed that it didn't work:

Dim ans As Char
If ans = "" Then
MsgBox("Ans contains no value")
Else
MsgBox("Ans contains a value")
End If

Thanks.
--

if you put it in quotes, then its a string - not char.
try
if ans = toChar("") then
....etc...
 
Try: If ans = CType ("", Char) Then

How do you determinate whether a varible of data type 'Char' is null or not?

I used the following code, but it seemed that it didn't work:

Dim ans As Char
If ans = "" Then
MsgBox("Ans contains no value")
Else
MsgBox("Ans contains a value")
End If

Thanks.
 
How do you determinate whether a varible of data type 'Char' is null or not?

A Char variable can't be "null" since Char is a value type. The
default value of a Char variable is zero, and you can test it with

If ans = ChrW(0) Then

or

If ans = ControlChars.NullChar Then



Mattias
 
Jeff,

AFAIK can you test every value type for its initial value with

If x = nothing

I hope this helps?

Cor
 
Shiva said:
Try: If ans = CType ("", Char) Then

A nullchar is different from a string of length 0.

Use 'ControlChars.NullChar'/'vbNullChar'/'ChrW(0)' instead.
 
Back
Top