Solved

Validation Checkking VS 2008 C#

Posted on 2011-03-10
8
276 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
  • 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
 
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
How to run any project with ease

Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
- Combine task lists, docs, spreadsheets, and chat in one
- View and edit from mobile/offline
- Cut down on emails

 
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

How to improve team productivity

Quip adds documents, spreadsheets, and tasklists to your Slack experience
- Elevate ideas to Quip docs
- Share Quip docs in Slack
- Get notified of changes to your docs
- Available on iOS/Android/Desktop/Web
- Online/Offline

Join & Write a Comment

Suggested Solutions

Title # Comments Views Activity
Email Body 4 46
Query datatable in LINQ 6 39
C# remove trailing commas from csv file 10 48
Duplicate a row 2 31
Introduction Hi all and welcome to my first article on Experts Exchange. A while ago, someone asked me if i could do some tutorials on object oriented programming. I decided to do them on C#. Now you may ask me, why's that? Well, one of the re…
Exception Handling is in the core of any application that is able to dignify its name. In this article, I'll guide you through the process of writing a DRY (Don't Repeat Yourself) Exception Handling mechanism, using Aspect Oriented Programming.
This video gives you a great overview about bandwidth monitoring with SNMP and WMI with our network monitoring solution PRTG Network Monitor (https://www.paessler.com/prtg). If you're looking for how to monitor bandwidth using netflow or packet s…
When you create an app prototype with Adobe XD, you can insert system screens -- sharing or Control Center, for example -- with just a few clicks. This video shows you how. You can take the full course on Experts Exchange at http://bit.ly/XDcourse.

706 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

Need Help in Real-Time?

Connect with top rated Experts

19 Experts available now in Live!

Get 1:1 Help Now