473,324 Members | 2,400 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,324 software developers and data experts.

testing null for integer type variable

js
I need to test if an integer variable is null or not. I tried to do

int myVairable;
myVariable = Int32.Parse(txtControl1.Text.Trim());
if (myVariable != null) {// do something}

C# does not allow this statement. How do I test an integer to see if it
is null or not? Thanks.

Nov 19 '05 #1
1 2623
The Parse method will throw an ArgumentNullException if the value being
passed is nothing. You can use a Try/Catch to catch the
ArgumentNullException. I'm not a C# programmer, but in VB it would look like:

dim myVariable as integer
Try
myVariable = Int32.Parse(txtControl1.Text.Trim())
'If I get here then all is well. Do something with the number.
myVariable = myVariable * 5

Catch exane as ArgumentNullException
'Value is null; do something else:
lblError.Text = exane.Message

Catch ex as Exception
'To catch all other errors
lblError.Text = ex.Message
End try

Hope this helps.
if (myVariable != null) {// do something}

"js" wrote:
I need to test if an integer variable is null or not. I tried to do

int myVairable;
myVariable = Int32.Parse(txtControl1.Text.Trim());
if (myVariable != null) {// do something}

C# does not allow this statement. How do I test an integer to see if it
is null or not? Thanks.

Nov 19 '05 #2

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

Similar topics

8
by: Lyn | last post by:
I am trying to get my head around the concept of default, special or empty values that appear in Access VBA, depending on data type. The Access Help is not much (help), and the manual that I have...
102
by: junky_fellow | last post by:
Can 0x0 be a valid virtual address in the address space of an application ? If it is valid, then the location pointed by a NULL pointer is also valid and application should not receive "SIGSEGV"...
29
by: Jason Curl | last post by:
I've been reading this newsgroup for some time and now I am thoroughly confused over what NULL means. I've read a NULL pointer is zero (or zero typecast as a void pointer), others say it's...
5
by: John Smith | last post by:
Hey folks, I know this is an old topic, but I can't find a definitive answer on google. How do I tell if an int has been initialized or not? I had been testing it like: if(myInt ==...
2
by: js | last post by:
I need to test if an integer variable is null or not. I tried to do int myVairable; myVariable = Int32.Parse(txtControl1.Text.Trim()); if (myVariable != null) {// do something} C# does not...
15
by: TC | last post by:
What does it mean for an integer to have a null value? I am trying to use the DataView.Find method. That method has an integer return type which contains the "index of the row in the DataView...
64
by: yossi.kreinin | last post by:
Hi! There is a system where 0x0 is a valid address, but 0xffffffff isn't. How can null pointers be treated by a compiler (besides the typical "solution" of still using 0x0 for "null")? -...
35
by: fcvcnet | last post by:
Hi, This is c code , but the question is same to c++ £¨new/delete£©. char* p = malloc(10); strcpy(p, "hello"); printf("%s\n", p); free(p); // free just add p to the free list of memory, and...
27
by: Terry | last post by:
I am getting the following warning for the below function. I understand what it means but how do I handle a null reference? Then how do I pass the resulting value? Regards Warning 1...
42
by: polas | last post by:
Afternoon all, I have some code (which I thought was OK, but now appreciate is probably not by the standard) which contains int a; ...... if (a==NULL) { ....
0
by: DolphinDB | last post by:
Tired of spending countless mintues downsampling your data? Look no further! In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
0
by: ryjfgjl | last post by:
ExcelToDatabase: batch import excel into database automatically...
0
by: Vimpel783 | last post by:
Hello! Guys, I found this code on the Internet, but I need to modify it a little. It works well, the problem is this: Data is sent from only one cell, in this case B5, but it is necessary that data...
0
by: jfyes | last post by:
As a hardware engineer, after seeing that CEIWEI recently released a new tool for Modbus RTU Over TCP/UDP filtering and monitoring, I actively went to its official website to take a look. It turned...
0
by: ArrayDB | last post by:
The error message I've encountered is; ERROR:root:Error generating model response: exception: access violation writing 0x0000000000005140, which seems to be indicative of an access violation...
1
by: PapaRatzi | last post by:
Hello, I am teaching myself MS Access forms design and Visual Basic. I've created a table to capture a list of Top 30 singles and forms to capture new entries. The final step is a form (unbound)...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
1
by: Defcon1945 | last post by:
I'm trying to learn Python using Pycharm but import shutil doesn't work
1
by: Shællîpôpï 09 | last post by:
If u are using a keypad phone, how do u turn on JavaScript, to access features like WhatsApp, Facebook, Instagram....

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.