Learn how to a build a cloud-first strategyRegister Now

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 296
  • Last Modified:

Validation Checkking VS 2008 C#

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
rwheeler23
Asked:
rwheeler23
  • 3
  • 3
  • 2
3 Solutions
 
wdosanjosCommented:
What's the DocumentStatus data type?
0
 
Carl TawnSystems and Integration DeveloperCommented:
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
 
rwheeler23Author Commented:
I have no control over the DocumentStatus object. It is defined as an integer.
0
Technology Partners: 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!

 
Carl TawnSystems and Integration DeveloperCommented:
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
 
wdosanjosCommented:
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
 
rwheeler23Author Commented:
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
 
Carl TawnSystems and Integration DeveloperCommented:
Yes. If PmTransactionScroll could possibly be null then you need to check for that.
0
 
rwheeler23Author Commented:
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

VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

  • 3
  • 3
  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now