473,385 Members | 2,269 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,385 software developers and data experts.

Determinate whether a 'Char' is null

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

http://www.chezjeff.net
My personal web portal
Nov 21 '05 #1
6 1573

"Xero" <jeff_@_chezjeff_._net(remove_underscores_and_this )> wrote in message
news:19**********************************@microsof t.com...
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...

---
Outgoing mail is certified Virus Free.
Checked by AVG anti-virus system (http://www.grisoft.com).
Version: 6.0.807 / Virus Database: 549 - Release Date: 12/8/2004
Nov 21 '05 #2
Try: If ans = CType ("", Char) Then

"Xero" <jeff_@_chezjeff_._net(remove_underscores_and_this )> wrote in message
news:19**********************************@microsof t.com...
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

http://www.chezjeff.net
My personal web portal
Nov 21 '05 #3
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

--
Mattias Sjögren [MVP] mattias @ mvps.org
http://www.msjogren.net/dotnet/ | http://www.dotnetinterop.com
Please reply only to the newsgroup.
Nov 21 '05 #4
Thanks very much :)

Xero
"Shiva" wrote:
Try: If ans = CType ("", Char) Then

"Xero" <jeff_@_chezjeff_._net(remove_underscores_and_this )> wrote in message
news:19**********************************@microsof t.com...
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

http://www.chezjeff.net
My personal web portal

Nov 21 '05 #5
Jeff,

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

If x = nothing

I hope this helps?

Cor

"Xero" <jeff_@_chezjeff_._net(remove_underscores_and_this )>
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

http://www.chezjeff.net
My personal web portal

Nov 21 '05 #6
"Shiva" <sh******@online.excite.com> schrieb:
Try: If ans = CType ("", Char) Then


A nullchar is different from a string of length 0.

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

--
M S Herfried K. Wagner
M V P <URL:http://dotnet.mvps.org/>
V B <URL:http://dotnet.mvps.org/dotnet/faqs/>
Nov 21 '05 #7

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

5
by: twkelsey | last post by:
Hi, My company has a scenario where we would like to change the data type of an existing primary key from an integer to a char, but we are concerned about the performance implications of doing...
14
by: Kayle | last post by:
How should we check if the '\0' characters exists in the string as I am confused that some books mentioned that we have to check whether we need to make sure that we pass the...
2
by: ad | last post by:
The user of my asp.net program use Sql2005 or Sql2005 express as database, both are possible. I have try both version of data base, I found: If I use Sql2005 express, the Data Source in...
1
by: ad | last post by:
Hi, It will fail to call a web service when the connection to internet is not OK. I wnant to check the connection to internet before call a web service. How to determinate if the connection...
1
by: ad | last post by:
I want to write a MemoryStream to a buffer. I use the codes below; The code is from the msdn help, They always declare the size of buffer as the (length of memorystream)+1; The code run ok, but...
2
by: ad | last post by:
How can I determinate if a string is a Valid date. For example "2002/06/23", and "2002/6/23" all are valid date string, but "2002/23/06" is not.
1
by: ad | last post by:
I want to determinate if a value in a Text is digital or character. How can I determinate it with Javascript
13
by: ad | last post by:
I want to determinate if there no symbol in a string? for example "12ab34", "123a5bc", "a123c4" is ok, but "23#45", 2a,35" is not ok.
16
by: s0suk3 | last post by:
This code #include <stdio.h> int main(void) { int hello = {'h', 'e', 'l', 'l', 'o'}; char *p = (void *) hello; for (size_t i = 0; i < sizeof(hello); ++i) {
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.