11,491,459 members (71,338 online)

# Graphical Analysis of Process Control Program

, 11 Feb 2007 CPOL 17.7K 282 10
 Rate this:
Please Sign up or sign in to vote.
This mathematical program uses explicit conversion and graphical display

## Introduction

Mathematical programs can be made more interesting when they use graphics to display their results. I use the graphics in C# to draw a representative diagram of the calculation. This calculation is used for Process Control. An instrumentation transmitter is calibrated to output 4 - 20 Milliamps when measuring a typical column of water. Let's say this column of water is a 0" - 120" span of H2O. The calculation will tell us what delta Milliamps should be output for the given percentage process span, or what delta process span is needed to give us the output delta Milliamps. This will allow us to calibrate our instrument. We generally check calibration at 0 %, 25 %, 50 %, 75 %, and 100 % levels of the process span.

## Explicit Conversion

A numerical value must be a `string` value to be displayed. When that value is used in a calculation, it must be Converted Explicitly. I use a `double` variable type as it allows decimal places that will be produced by division.

```delta1 = Double.Parse(txtDelta1.Text);
delta3 = span2 * ( delta1/ span1);```

## Data Validation

Interestingly enough, those same lines of code will take care of most of our Data Validation for us. If `Double.Parse` throws an exception, the code in our `catch` block will run.

```catch(Exception w)
{
MessageBox.Show(w.ToString(), "Important", MessageBoxButtons.OK,
MessageBoxIcon.Stop);
}```

The next part of our Data Validation is to ensure that our delta falls within the limits of our span. Otherwise, division by zero, or even memory overflow could occur. Actually, at one time, people considered both of these errors to be one and the same thing.

```if ( double.Parse( txtDelta1.Text ) >= 0 )
{
if ( double.Parse( txtDelta1.Text ) <= span1 )
{
blue = false;
delta1 = Double.Parse(txtDelta1.Text);
delta3 = span2 * ( delta1/ span1);
span4 = Double.Parse(txtSpan2a.Text);
txtDelta2.Text = delta3.ToString();
Answere2 = delta3 + span4;
lblAnswere2.Text = txtDelta2.Text.ToString()  +
" + " +   txtSpan2a.Text.ToString() +
" = " + Answere2.ToString();
lblAnswere2Unit.Visible = true;
}
else
{
MessageBox.Show("Delta must be within Span limits",
"Important", MessageBoxButtons.OK, MessageBoxIcon.Stop);
}
}
else
{
MessageBox.Show("Delta must be within Span limits",
"Important", MessageBoxButtons.OK, MessageBoxIcon.Stop);
}```

## Graphics

Graphics can be manipulated by calculation as well. Here, we convert explicitly to `Int32` type variable. We do this because this conversion process will round a `double` type variable to an integer value.

```// Graphics
Graphics graph = this.CreateGraphics();
Pen pen = new Pen(Color.Red);

//Red Line
if( blue == true)
{
//Red Line
int line2 = Convert.ToInt32(delta2/ span2 * 200) + 350;
graph.DrawLine( pen, line2, 435, line2, 615);
}
else
{
int line = Convert.ToInt32(delta1/ span1 * 200) + 350;
graph.DrawLine( pen, line, 435, line, 615);
}```

## Conclusion

There is a lot left to do with this program, but I hope this helps you through "conversion hell". Feel free to develop software as you desire. This code is your code.

## History

• 11th February, 2007: Initial post

## License

This article, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

## About the Author

Web Developer
United States
I started programming in High School writing Fortran IV on punch cards using a keypunch machine. When I moved to Las Vegas I studied IBM AS-400, and RPG. This was when Windows was really taking over, so I switched to VB-6, then VB.Net, and C#.Net.

I have really enjoyed the .Net Platform, and it still amazes me every time I am inspired to the point of writing a new program.

Thanks All ! for giving me the time and patience.

## Comments and Discussions

 First Prev Next
 error input string not in correct format winheart22-Apr-07 22:19 winheart 22-Apr-07 22:19
 if i enter a values like this 0.00...., its giveing me error, how to avoid this error. please help me
 ???? V. Thieme11-Feb-07 22:59 V. Thieme 11-Feb-07 22:59
 Last Visit: 31-Dec-99 19:00     Last Update: 27-May-15 21:21 Refresh 1

General    News    Suggestion    Question    Bug    Answer    Joke    Rant    Admin

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.

| Advertise | Privacy | Terms of Use | Mobile
Web02 | 2.8.150520.1 | Last Updated 11 Feb 2007
Article Copyright 2007 by David A Brighton
Everything else Copyright © CodeProject, 1999-2015
Layout: fixed | fluid