473,320 Members | 1,691 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,320 software developers and data experts.

C++ NULL value

I'm kind of new to C++, so excuse me if this is a little obvious...
I'm having trouble having my program recognize a null value, my code looks like this:

Expand|Select|Wrap|Line Numbers
  1. float a = System::Convert::ToSingle(aBox->Text);
  2. if (a == NULL)
  3. {
  4. float b = System::Convert::ToSingle(bBox->Text);
  5. float a = b * 10;
  6. }
I've tried several different ways, but this is the most straightforward.
There are no errors, but it fails to recognize the if statement; it stops debugging because of the null value not being corrected.
Oct 16 '07 #1
4 2368
I almost forgot...
I did include this line of code at the top of the page:

Expand|Select|Wrap|Line Numbers
  1. #include <cstring>
Oct 16 '07 #2
Banfa
9,065 Expert Mod 8TB
I'm kind of new to C++, so excuse me if this is a little obvious...
I'm having trouble having my program recognize a null value, my code looks like this:

Expand|Select|Wrap|Line Numbers
  1. float a = System::Convert::ToSingle(aBox->Text);
  2. if (a == NULL)
  3. {
  4. float b = System::Convert::ToSingle(bBox->Text);
  5. float a = b * 10;
  6. }
I've tried several different ways, but this is the most straightforward.
There are no errors, but it fails to recognize the if statement; it stops debugging because of the null value not being corrected.
NULL is a term normally applied to pointers, A NULL pointer is one with the value defined by the system as not pointing to anything, the C/C++ compiler is responsible for converting the value 0 used in a pointer context to the "null" value for the platform that it is compiling for. This is sometimes, but not necessarily the actual value 0.

However you are not using pointers, you have a float and what is more it looks like you are converting from a string of characters to a float. In this context == NULL is equivilent to == 0, testing a float for equivilence is unlikely to work very well because floats (and doubles) only hold approximations to the value. Has it happens in most float representations 0 tends to be an exception, that is there is a exact representation of 0 for a float however the likely hood of achieving that exact representation from a string of characters is unlikely.

The question is are you trying to detect no text in the text box or are you trying to detect a zero (or close to zero) input value.

In the first case you need to test the text directly before converting to a float, get the number of entered characters and check it is non-zero.

In the second you will have to decide what you consider too small and perform a relational comparison, i.e. a < 0.0001
Oct 16 '07 #3
Banfa
9,065 Expert Mod 8TB
Oh and by the way code should be in code tags (See How to Ask a Question) not bold.
Oct 16 '07 #4
Thank you, I'll try that.
(I was trying to determine if there was a blank text box, not zero)
Oct 16 '07 #5

Sign in to post your reply or Sign up for a free account.

Similar topics

3
by: John Morgan | last post by:
In an SQL statement which concatenates several fields I get a null value returned if any one of the fields are null. Is this to be expected? For example : SELECT tblMember.memberAddress + '...
3
by: iStrain | last post by:
Hiya. I'm _sure_ this is an FAQ, but Googling hasn't produced the answer in a way I can make sense out of. I know I should get this, but so far no way... I'm creating tables and doing queries in...
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"...
99
by: Mikhail Teterin | last post by:
Hello! Consider the following simple accessor function: typedef struct { int i; char name; } MY_TYPE; const char *
13
by: Federico Balbi | last post by:
Hi, I was wondering if PGSQL has a function similar to binary_checksum() of MS SQL Server 2000. It is pretty handy when it comes to compare rows of data instead of having to write long boolean...
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")? -...
17
by: Mark A | last post by:
DB2 8.2 for Linux, FP 10 (also performs the same on DB2 8.2 for Windoes, FP 11). Using the SAMPLE database, tables EMP and EMLOYEE. In the followng stored procedure, 2 NULL columns (COMM) are...
15
by: khan | last post by:
Hi, I read that pointer representation can non-zero bit pattern, machine specific.Compiler when comes accross value '0' in pointer context, converts it to machine specific null pointer...
3
ADezii
by: ADezii | last post by:
Null as it relates to database development is one of life's little mysteries and a topic of total confusion for novices who venture out into the database world. A Null Value is not zero (0), a zero...
1
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
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...
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: 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....
0
by: af34tf | last post by:
Hi Guys, I have a domain whose name is BytesLimited.com, and I want to sell it. Does anyone know about platforms that allow me to list my domain in auction for free. Thank you
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 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 former...

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.