Thursday, 14 November 2013

Introduction to Data Flow Diagrams


Data flow diagrams are very important to structured programming. So I decided to do a little article about DFD’s. Data flow diagrams are also known as bubble charts. It is a visual representation of a system via input data to a system, the number of processes carried out to these data and the final output from the system. Data flow diagrams are so popular because of the simplicity and the clearness of the diagrams. Otherwise you can say they are very formal and easy to understand. Data flow diagrams use specific number of easy symbols to depict the functions and processes with the inputs and outputs of the system. Data flow diagrams are a hierarchical diagram type where representing from the set of most high level functions of the system to the sub level function. Any hierarchical model is easy to understand by the humans because hierarchical models starts very simple with abstract model of a system and different details of the system are introduced slowly. There are simple set of rules when drawing data flow diagrams followed by conceptual techniques. Below are the different symbols that represent and used to construct data flow diagrams. Just have a look and see how simple they are.



I’m going to explain each one of these symbols briefly. Try and understand what each of these means and how to use them in a data flow diagram correctly.

External Entity

External entities are represented by a rectangle and the better examples for external entities are librarian, library member, etc. These external entities represent those physical entities in the real world that interacts with the system. As you can see these external entities are outside to the software system and interacting with the system by inputting data by consuming the data created by the software system.

Process

Functions are represented by a circle. These symbols are called as process or bubbles. This term is derived from the bubble chart terminology. Bubbles are connected with the corresponding functions. 

Data Flow Symbol (Arrow)

An arrow is used to represent the connectors or a data flow symbol. This arrow can be a straight directed arrow as well as a curve arrow according to the structure of the diagram. There are three things that a data flow symbol can represent.

1. Data flow between two processes
2. Between external entity and a process
3. Process in a direction of the data flow arrow

Data flow symbols are usually represented with corresponding data names.

Data Store Symbol

Data stores are where data is basically stores and it is represented by an open box. There for an open box can represent a logical file, data structure or a physical file on disk. Each data source is connected with a process obviously with an arrow or a data flow symbol. The direction of the arrow can represent whether the data is read or write from the disk or into a data source. An arrow flowing in or out of a data store implicitly represents the entire data of the data store and hence arrows connecting to a data source need not be annotated with the name of the corresponding data item. 

Above symbols are created with Creately Org Chart Software.

Monday, 28 October 2013

How to Code Efficiently - for Software Programmers



Writing a computer program is a stressful job for programmers out there. Normally when writing a program, a proper documentation is done. Programmers plan the flow of their program using diagrams. There are several methods for the proper planning a computer program. There are many diagram types that can help you plan your diagrams. Few examples are work flow diagrams, ER diagram (database), mind maps and all UML (unified modeling language) diagrams. 

Mind mapping is the virtual brainstorm session of programing. Mind maps are the blue print of any powerful system. It is important to keep these small beginnings clarified, so you won’t get in to trouble of scrambling up the code. Flowcharts can be taken as one of the primary steps when doing a software project. If you are the team lead of a particular software project, you should encourage other users to refer these diagrams to build up a complete system where there will be no errors. When you follow a proper code of conduct your code will be bugs free and you will ultimately include all the effort to your code.


Let’s take a little example of a guessing game. In the specific scenario I use a flowchart diagram (below fig: 1.1). When designing a software program it is always good to pre-design it like in the fig 1.1 since it allows you to visualize what you are doing which will give you an better idea about the outcomes. It also helps you to clearly identify the input, processes and output to the system. And the flow of the diagram will be described virtually with arrows. The program shown here as a flowchart and below in actual computer instructions is a classic example of a computer program.

Fig 1.1




This flowchart is drawn from a Visio alternative called Creately. With Creately it is not hard to draw Flowcharts & it isn’t hard to see what the computer will do when this program runs. Let’s look in to how this flowchart is going to work.
  
  1. As soon as the program starts, computer prints "Guess a number" on the screen. 
  2.  You must input a number from keyboard and then press the return. The program reads the number as soon as you enter it.
  3. The program check for the condition where the number you have guessed is larger than the computers number. If so it will print “Too Big” on the screen.
  4. And if it's smaller, the computer prints "Too Small"
  5. If you did not get the correct answer, the computer reverts to input stage to get another number from the keyboard.
  6. The computer will do the same thing until you get the right answer or until you terminate the program.
  7. After you guess correctly, the computer stops the loop and will let you know by printing "Correct!" and then asks if you would like to "Try Again?"
  8. The program again waits for the keyboard input. If you type “y” and press return the program starts over, picking a new number for you to guess.
  9. Type any other key, press the Enter key, and the program terminates itself.

As you can see, the whole process is crystal clear when you draw it in a flowchart. How does it look when the diagram converted to a program? I used C language to write this program as it’s a language known by everybody. Compile using a C++ compiler.
 
  1. #include <iostream>
    #include <cstdlib>    \\ Deaclaring this library for random numbers
    using namespace std;

    int main() {
                   
                    int iSecret, number; \\ Declaring Variables
                    iSecret = rand() % 10 + 1; \\ Creating a Random Number
                    char a;
                   
                    cout<<"Guessing Game!\n";
                    cout<<"Guess a Number Between 1- 10:\n";
                   
        cin >> number; \\ Getting the number from the user
       
        if (number < iSecret ) \\comparing the number with the guessed
        {
                    cout<<"Too Low\n";
        }
        else if (number > iSecret)
        {
                    cout<<"Too High\n";
        }
        else if (number == iSecret)
        {
                    cout<<"Correct!\n";
        }
       
        cout<<"The Number was =\n"<<iSecret;
       
        cout<<"Try Again?\n";
        cin >> a;
       
        if (a == "y")
        {
                    goto 7;
        }
       
                    return 0;
    }
     

Thursday, 15 August 2013

How to get the selected value of a databound winforms ComboBox control (C #)

I have discussed early about loading data to a dictionary and data binding it to a winforms combobox control.
Now its time to get that selected value from that combo box

There are many ways to get the values from the combobox but I have 2 favorite ways.

* Using the combobox's "selection change committed" or
* "Selected index changed"

Now if you are using the selected "Selected index changed" event handler, you must understand that this will trigger in the initial form load and it might lead up to some nasty errors. Its better to use a lock and update the lock once the page load is complete( well don't really have to go in a extreme worry).
Heres an example
(lets edit code from a previous example)

using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;

namespace WindowsFormsApplication3
{
    public partial class Form1 : Form
    {
        bool loadComplete = false;
        public Form1()
        {
            InitializeComponent();
            loadComboElements();

            loadComplete = true;//notice that load comlete will be true
                                // only when items are loaded to combobox...

            getSelectedValue();//now with this method then inicial selected value is displayed
        }

        private void loadComboElements()
        {
            Dictionary<int, string> keyValueDic = new Dictionary<int, string>();
            keyValueDic.Add(-1, "Please select an item");
            keyValueDic.Add(1, "sample item 1");
            keyValueDic.Add(2, "Sample item 2");

            comboBox1.DataSource = keyValueDic.ToList();
            comboBox1.DisplayMember = "VALUE";
            comboBox1.ValueMember = "Key";
            comboBox1.SelectedValue = -1;//seddinng the initial selected value
        }

       //double click the combo box and the method skeleton will be built
        private void comboBox1_SelectedIndexChanged(object sender, EventArgs e)
        {
            getSelectedValue();
        }

        private void getSelectedValue()
        {
            if (loadComplete == true)
            {
                int selectedValueFromComobox;
                bool isValidInt = int.TryParse(Convert.ToString(comboBox1.SelectedValue), out selectedValueFromComobox);
                if (isValidInt)
                {
                    label1.Text = Convert.ToString(selectedValueFromComobox);
                }
            }
        }
    }
}

Wednesday, 14 August 2013

Data binding a WinForms ComboBox control with a dictionary

Sometime when working with winforms we have to load items to a combo box and the starting value can be some information display.



here is how to do that,
all you have to do is just drop a combo box in to ms form and then code like the following

namespace WindowsFormsApplication3
{
    public partial class Form1 : Form
    {
        public Form1()
        {
            InitializeComponent();
            loadComboElements();
        }

        private void loadComboElements()
        {
            Dictionary<int, string> keyValueDic = new Dictionary<int, string>();
            keyValueDic.Add(-1, "Please select an item");
            keyValueDic.Add(1, "sample item 1");
            keyValueDic.Add(2, "Sample item 2");

            comboBox1.DataSource = keyValueDic.ToList();
            comboBox1.DisplayMember = "VALUE";
            comboBox1.ValueMember = "Key";
        }
    }
}


  • Remember you have to use "ToList()" on dictionary  and also, use "Key" and "Value" to identify the display member and value member.