?
Solved

Validation Checkking VS 2008 C#

Posted on 2011-03-10
8
Medium Priority
?
290 Views
Last Modified: 2012-05-11
I am looking for tips on how to perform better validation checking than what I did in this code snippet. What was happening, rarely, but it did happen was the value of DocumentStatus was null which is an invalid state but bad data happens. What is the cleanest and most efficient way to rewrite this and account for nulls? My entire form just crashed and locked up because of this. Is the only answer to add DocumentStatus != null to all the if statements? Does C# have an equivalent to the SQL coalesce function?
if (PmTransactionScroll.DocumentStatus == 3)
                {
                    if (ViewPayablesDistributionZoomFormHIST == null || ViewPayablesDistributionZoomFormHIST.Created == false)
                    {
                     ViewPayablesDistributionZoomFormHIST = new frmViewJobLinkerHIST();
                     ViewPayablesDistributionZoomFormHIST.Show();
                        ViewPayablesDistributionZoomFormHIST.Activate();
                    ViewPayablesDistributionZoomFormHIST.Focus();
                    }
                }

Open in new window

0
Comment
Question by:rwheeler23
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 3
  • 3
  • 2
8 Comments
 
LVL 23

Expert Comment

by:wdosanjos
ID: 35105885
What's the DocumentStatus data type?
0
 
LVL 52

Assisted Solution

by:Carl Tawn
Carl Tawn earned 1332 total points
ID: 35107754
Either that or, if PmTransactionScroll is a custom object of your own, then you could alter it to return a default value if it is null.
0
 

Author Comment

by:rwheeler23
ID: 35108791
I have no control over the DocumentStatus object. It is defined as an integer.
0
Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
LVL 52

Expert Comment

by:Carl Tawn
ID: 35108905
If it is an integer then it cannot hold a null value. So it must either be a Nullable<int>, in which case null would be a valid value, or it is complaining about something else.
0
 
LVL 23

Accepted Solution

by:
wdosanjos earned 668 total points
ID: 35108960
That's interesting, because integer types do not take null, unless they are defined as int? or long? (nullable integer types).  Is it possible that the problem is with PmTransactionScroll instead?  Or, is DocumentStatus a property that throws an exception in certain cases?  
0
 

Author Comment

by:rwheeler23
ID: 35108994
The problem is with the scrolling object. This object is on a form. What I have discovered is that occasionally the form is empty so probably what I should be checking is for an empty form not a null value of the integer.
0
 
LVL 52

Assisted Solution

by:Carl Tawn
Carl Tawn earned 1332 total points
ID: 35109224
Yes. If PmTransactionScroll could possibly be null then you need to check for that.
0
 

Author Comment

by:rwheeler23
ID: 35112390
I am relaetively new to VS C# and .Net Programming and one thing I have noticed is that if you have any kind of conditional statement but neglect to account for a condition, when the program runs into that condition only heaven knows what it will do. It appears to just fall off the cliff. I tried putting breakpoints in the code but since this condition was not accounting for none of them would get hit. I guess that is a clue in itself. Thanks for your help.
0

Featured Post

On Demand Webinar: Networking for the Cloud Era

Did you know SD-WANs can improve network connectivity? Check out this webinar to learn how an SD-WAN simplified, one-click tool can help you migrate and manage data in the cloud.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Calculating holidays and working days is a function that is often needed yet it is not one found within the Framework. This article presents one approach to building a working-day calculator for use in .NET.
Real-time is more about the business, not the technology. In day-to-day life, to make real-time decisions like buying or investing, business needs the latest information(e.g. Gold Rate/Stock Rate). Unlike traditional days, you need not wait for a fe…
In this video we outline the Physical Segments view of NetCrunch network monitor. By following this brief how-to video, you will be able to learn how NetCrunch visualizes your network, how granular is the information collected, as well as where to f…
Add bar graphs to Access queries using Unicode block characters. Graphs appear on every record in the color you want. Give life to numbers. Hopes this gives you ideas on visualizing your data in new ways ~ Create a calculated field in a query: …
Suggested Courses

801 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question