Solved

Validation Checkking VS 2008 C#

Posted on 2011-03-10
8
284 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 333 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
Salesforce Has Never Been Easier

Improve and reinforce salesforce training & adoption using WalkMe's digital adoption platform. Start saving on costly employee training by creating fast intuitive Walk-Thrus for Salesforce. Claim your Free Account Now

 
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 167 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 333 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

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!

Question has a verified solution.

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

Introduction This article series is supposed to shed some light on the use of IDisposable and objects that inherit from it. In essence, a more apt title for this article would be: using (IDisposable) {}. I’m just not sure how many people would ge…
This article is for Object-Oriented Programming (OOP) beginners. An Interface contains declarations of events, indexers, methods and/or properties. Any class which implements the Interface should provide the concrete implementation for each Inter…
In this video, viewers are given an introduction to using the Windows 10 Snipping Tool, how to quickly locate it when it's needed and also how make it always available with a single click of a mouse button, by pinning it to the Desktop Task Bar. Int…
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: …

717 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