I need to know what the appropriate way to test for nothing in several different types of data types is. Here are some examples
For string I use this
If Not abc.text Is Nothing AndAlso Not abc.text = "" The
' Some Cod
End I
For datetime's I'm currently using something like this
If Not abc.ToShortDate String = "01/01/0001" The
' Some Cod
End I
For Integers, I use this
If not abc = 0 The
' Some Cod
End I
For object, I'm asuming that it'd be against nothing like this
If Not abc Is Nothing The
' Some Cod
End I
What about other data types? I know Boolean wouldn't matter, because when it's not initialized, it's False. What about things like Decimal, Single, Double, Long, Byte, Char, etc.? Also, are the ways I'm testing above the correct way to test? 4 3083
Hi Nathon, For string I use this. If Not abc.text Is Nothing AndAlso Not abc.text = "" Then ' Some Code End If
A string is a strange thing, both are correct however there is a difference.
The first test a string which has not really a reference to something, the
second is an empty string, however you can always use the = "" which is by
the most regulars in the language.vb group the advices method.
For datetime's I'm currently using something like this. If Not abc.ToShortDate String = "01/01/0001" Then ' Some Code End If
Date is in VB.net a value and therefore is
If abc = nothing very allowed.
For Integers, I use this. If not abc = 0 Then ' Some Code End If
A value type can only tested for 0, = nothing is the same
For object, I'm asuming that it'd be against nothing like this. If Not abc Is Nothing Then ' Some Code End If
There are basicly only two types Objects and Values.
From the values are the date and the string a little bit strange for the
rest you can always do the same as with the integer.
Cor
Hi Nathon, For string I use this. If Not abc.text Is Nothing AndAlso Not abc.text = "" Then ' Some Code End If
A string is a strange thing, both are correct however there is a difference.
The first test a string which has not really a reference to something, the
second is an empty string, however you can always use the = "" which is by
the most regulars in the language.vb group the advices method.
For datetime's I'm currently using something like this. If Not abc.ToShortDate String = "01/01/0001" Then ' Some Code End If
Date is in VB.net a value and therefore is
If abc = nothing very allowed.
For Integers, I use this. If not abc = 0 Then ' Some Code End If
A value type can only tested for 0, = nothing is the same
For object, I'm asuming that it'd be against nothing like this. If Not abc Is Nothing Then ' Some Code End If
There are basicly only two types Objects and Values.
From the values are the date and the string a little bit strange for the
rest you can always do the same as with the integer.
Cor
If it's a reference type, you can test for nothing (vb.net) or null (c#).
Most of the types you mention are value types so they won't be null but they
do have default values and you can test against those. Bool defaults to
false for instance. Decimal defaults to 0. Char defaults to string.Empty
(as an aside, it's better to test for string.Empty with strings as well
instead of testing for something = "")
For datetime you can test against MinValue (01/01/0001 12:00:00 AM)
Most everything else is going to be a reference type, so it's pretty easy to
learn the value types and test against them.
HTH,
Bill
"Nathon Dalton" <an*******@disc ussions.microso ft.com> wrote in message
news:A1******** *************** ***********@mic rosoft.com... I need to know what the appropriate way to test for nothing in several
different types of data types is. Here are some examples. For string I use this. If Not abc.text Is Nothing AndAlso Not abc.text = "" Then ' Some Code End If
For datetime's I'm currently using something like this. If Not abc.ToShortDate String = "01/01/0001" Then ' Some Code End If
For Integers, I use this. If not abc = 0 Then ' Some Code End If
For object, I'm asuming that it'd be against nothing like this. If Not abc Is Nothing Then ' Some Code End If
What about other data types? I know Boolean wouldn't matter, because when
it's not initialized, it's False. What about things like Decimal, Single,
Double, Long, Byte, Char, etc.? Also, are the ways I'm testing above the
correct way to test?
If it's a reference type, you can test for nothing (vb.net) or null (c#).
Most of the types you mention are value types so they won't be null but they
do have default values and you can test against those. Bool defaults to
false for instance. Decimal defaults to 0. Char defaults to string.Empty
(as an aside, it's better to test for string.Empty with strings as well
instead of testing for something = "")
For datetime you can test against MinValue (01/01/0001 12:00:00 AM)
Most everything else is going to be a reference type, so it's pretty easy to
learn the value types and test against them.
HTH,
Bill
"Nathon Dalton" <an*******@disc ussions.microso ft.com> wrote in message
news:A1******** *************** ***********@mic rosoft.com... I need to know what the appropriate way to test for nothing in several
different types of data types is. Here are some examples. For string I use this. If Not abc.text Is Nothing AndAlso Not abc.text = "" Then ' Some Code End If
For datetime's I'm currently using something like this. If Not abc.ToShortDate String = "01/01/0001" Then ' Some Code End If
For Integers, I use this. If not abc = 0 Then ' Some Code End If
For object, I'm asuming that it'd be against nothing like this. If Not abc Is Nothing Then ' Some Code End If
What about other data types? I know Boolean wouldn't matter, because when
it's not initialized, it's False. What about things like Decimal, Single,
Double, Long, Byte, Char, etc.? Also, are the ways I'm testing above the
correct way to test? This thread has been closed and replies have been disabled. Please start a new discussion. Similar topics |
by: Nathon Dalton |
last post by:
I need to know what the appropriate way to test for nothing in several different types of data types is. Here are some examples
For string I use this
If Not abc.text Is Nothing AndAlso Not abc.text = "" The
' Some Cod
End I
For datetime's I'm currently using something like this
If Not abc.ToShortDateString = "01/01/0001" The
' Some Cod
|
by: clintonG |
last post by:
I'm using an .aspx tool I found at but as nice as the interface is I
think I need to consider using others. Some can generate C# I understand.
Your preferences please...
<%= Clinton Gallagher
http://forta.com/books/0672325667/
|
by: Nathon Dalton |
last post by:
I need to know what the appropriate way to test for nothing in several different types of data types is. Here are some examples
For string I use this
If Not abc.text Is Nothing AndAlso Not abc.text = "" The
' Some Cod
End I
For datetime's I'm currently using something like this
If Not abc.ToShortDateString = "01/01/0001" The
' Some Cod
|
by: John A. Bailo |
last post by:
Dr. Dobbs has a /glowing/ article on Ruby on Rails this month.
What do you guys think?
Can it replace .net, php and java?
And be the Open Source OOP web solution that is not bound to Sun or MS?
http://media.rubyonrails.org/presentations/pursuitofbeauty.pdf
|
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, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look !
Part I. Meaning of...
| |
by: Hystou |
last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it.
First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
|
by: Hystou |
last post by:
Overview:
Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
|
by: tracyyun |
last post by:
Dear forum friends,
With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
|
by: isladogs |
last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM).
In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules.
He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms.
Adolph will...
|
by: conductexam |
last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one.
At the time of converting from word file to html my equations which are in the word document file was convert into image.
Globals.ThisAddIn.Application.ActiveDocument.Select();...
|
by: 6302768590 |
last post by:
Hai team
i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
| |
by: muto222 |
last post by:
How can i add a mobile payment intergratation into php mysql website.
|
by: bsmnconsultancy |
last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...
| |