Docsity

Introduction to visual programming language, Thesis of Computer Programming

Partial preview of the text

Download Introduction to visual programming language and more Thesis Computer Programming in PDF only on Docsity!

MINISTRY OF EDUCATION

DIPLOMA IN

INFORMATION COMMUNICATION

TECHNOLOGY

KENYA INSTITUTE OF CURRICULUM DEVELOPMENT

STUDY NOTES

Visual Programming

MODULE II: SUBJECT NO 4

Contents

  • CHAPTER 1: INTRODUCTION TO VISUAL PROGRAMMING LANGUAGES
    • Introduction to Visual Programming
    • System Requirements: Software and Hardware Requirements
    • Visual programming languages
  • CHAPTER 2: VISUAL ENVIRONMENT
    • Visual programming environment
    • Integrated development environment (IDE)
    • Using the Visual Basic Development Environment
    • Objects and Classes..........................................................................................................................
  • CHAPTER 3: PROGRAM STRUCTURE
    • Format of a visual program
    • Data Types, Modules and Operators
      • Modules......................................................................................................................................
      • Data types...................................................................................................................................
      • Operators
    • Variable
    • Variable Declaration
  • CHAPTER 4: PROGRAM WRITING
    • Define design time, run time, and break time.
    • Steps to Develop a Program
      • Specifying the Problem:
      • Designing an Algorithm:............................................................................................................
      • Coding:
      • Debugging:
      • Testing and Validating:
      • Documentation and Maintenance:
    • Debug, Compile and Execution Terms
  • CHAPTER 5: CONTROL STRUCTURES
    • Introduction to Control Structures
    • Types of Control Structures
      • Sequence structure
      • Selection/Decision/Branching structure.....................................................................................
      • Decision Structures Implementation
      • Loop Structure
      • Loop Structure Implementation
  • CHAPTER 6: ERROR HANDLING & DEBUGGING
    • Introduction to Error Handling
    • Types of Program Errors
    • Error handling techniques
      • Return code
      • Error (success) indicator parameter
      • Global variable
      • Exceptions
      • Design by Contract
    • Debugging & Debugging tools
  • CHAPTER 7: SUB-PROGRAMS
    • Introduction to Sub-Program and Functions/Procedures
    • Types of subprograms
      • Private
      • Public
    • Scope of variables
  • CHAPTER 8: DATA STRUCTURES
    • Description of data structures
    • Introduction to Arrays
    • Types/Dimension of an Array data structure
      • Declaring Array
      • Declaring one dimensional Array
      • Declaring two dimensional Array
      • Dynamic Array...........................................................................................................................
    • Searching and Sorting Arrays
      • Searching Arrays
      • Sorting Arrays
  • CHAPTER 9: LINKING TO DATABASES
    • Database controls
      • Data control and data-bound control..........................................................................................
      • Using the ADO Data Control
      • Active Data Object(ADO) Connection
    • Database Reports
  • CHAPTER 10: EMERGING TRENDS IN VISUAL PROGRAMMING
    • Emerging trends in visual programming........................................................................................
    • Challenges of emerging trends in Visual programming
    • Coping with challenges of emerging trends in visual programming

Visual programming languages

These let users specify programs in a two-(or more)-dimensional way, instead of as one- dimensional text strings, via graphic layouts of various types.

  1. CODE ( computationally oriented display environment ) is a visual programming language and system for parallel programming, which lets users compose sequential programs into parallel programs.

  2. DRAKON is an algorithmic visual programming language developed within the Buran space project.

  3. Scratch is a free desktop and online multimedia authoring tool that can be used by students, scholars,

teachers, and parents to easily create games and provide a stepping stone to the more advanced world of computer programming or even be used for a range of educational and entertainment constructivist purposes from math and science projects, including simulations and visualizations of experiments, recording lectures with animated presentations, to social sciences animated stories, and interactive art and music. Viewing the existing projects available on the Scratch website, or modifying and testing any modification without saving it requires no online registration.

  1. Simulink , developed by MathWorks, is a data flow graphical programming language tool for modeling,

simulating and analyzing multidomain dynamic systems. Its primary interface is a graphical block diagramming tool and a customizable set of block libraries. It offers tight integration with the rest of the MATLAB environment and can either drive MATLAB or be scripted from it.

  1. A spreadsheet is an interactive computer application program for organization, analysis and storage of data in tabular form. Spreadsheets developed as computerized simulations of paper accounting worksheets. The program operates on data represented as cells of an array, organized in rows and columns. Each cell of the array is a model–view–controller element that may contain either numeric or text data, or the results of formulas that automatically calculate and display a value based on the contents of other cells. Spreadsheet users may adjust any stored value and observe the effects on calculated values. This makes the spreadsheet useful for "what- if" analysis since many cases can be rapidly investigated without manual recalculation. Modern spreadsheet software can have multiple interacting sheets, and can display data either as text and numerals, or in graphical form.
  2. Agilent VEE is a graphical dataflow programming software development environment from Agilent Technologies for automated test, measurement, data analysis and reporting.
  3. VisSim is a visual block diagram language for simulation of dynamical systems and model based design of embedded systems. It is developed by Visual Solutions of Westford, Massachusetts. It uses a graphical data flow paradigm to implement dynamic systems based on differential equations.

CHAPTER 2: VISUAL ENVIRONMENT

Visual programming environment

Software which allows the use of visual expressions (such as graphics, drawings, animation or icons) in the process of programming. These visual expressions may be used as graphical interfaces for textual programming languages. They may be used to form the syntax of new visual programming languages leading to new paradigms such as programming by demonstration or they may be used in graphical presentations of the behavior or structure of a program.

Integrated development environment (IDE)

An integrated development environment (IDE) is a programming environment that has been packaged as an application program, typically consisting of a code editor, a compiler, a debugger, and a graphical user interface (GUI) builder.

( I ntegrated D evelopment E nvironment) A set of programming tools for writing applications (source code editor, compiler, debugger, etc.), all activated from a common user interface and menus. IDEs are

necessary standard procedure for program development.

Using the Visual Basic Development Environment

In addition to the core user interface features that Visual Studio provides, the Visual Basic integrated

development environment (IDE) adds some to help with productivity and ease of use.

Note: Visual Basic makes it easy to create event-driven programs. An event-driven program is one

which responds to users' actions especially mouse clicks and mouse movement.

some user events associated with a command button

the current form. You can also pass your mouse over each tool to see its name appear in a pop-up window.  The main Visual Basic window holds the menu bar (at the very top), the toolbar (just under the menu bar), and form location and size info.  The form location and size information appears at the right end of the toolbar and can be useful for design reasons.  The Help menu is a very useful and often overlooked repository of information. Use the online Help to learn about Visual Basic!

Note:

The Immediate window is a special window in which you can directly type Visual Basic commands and view and change variables and control values during a program's execution. It‘s used to debug and evaluate expressions, execute statements, print variable values, and so forth. It allows you to enter expressions to be evaluated or executed by the development language during debugging.

Code window is on which you write, display, and edit Visual Basic code. You can open as many Code windows as you have modules, so you can easily view the code in different forms or modules, and copy and paste between them.

Steps for writing a Visual Basic project.

You must always plan a program before you actually write it to be a successful programmer. Many students and professionals overlook this crucial necessity.

o Design the user interface: You should storyboard the program by actually drawing pictures of the screen that the user will interact with during the program's execution. Show the forms and controls carefully and accurately. Do NOT assume that you will be able to "figure it out" when you sit down to type the code into the computer. It is highly recommended to name the forms and controls that you plan to use beforehand rather than to write them into the code as you type it as well. o Plan the properties: Since it is possible to highly customize the look and feel of a VB program (unlike older procedural programs), it is very important to write down your ideas and plans before typing the code into the computer. Your program will not have a commercial and professional appearance, otherwise. o Plan the code: Write out pseudocode that explains the procedural tasks that must be accomplished within your program before typing or even writing out actual Basic code. Pseudocode is English phrases that roughly explains how you plan to do things within your program. Do not use Basic keywords or perfect syntax during this planning phase.

CHAPTER 3: PROGRAM STRUCTURE

Format of a visual program

1. Object: An object is a combination of code and data that can be treated as a unit. An object can be a piece of an application, like a control or a form. An entire application can also be an object. Objects are things that you can program with, things that make programming easier. They contain a set of methods and properties that allow you to make the object do certain things without actually having to look at the objects code.

Objects let you declare variables and procedures once and then reuse them whenever needed.

Each object in Visual Basic is defined by a class. A class describes the variables, properties, procedures, and events of an object. Objects are instances of classes; you can create as many objects you need once you have defined a class.

To understand the relationship between an object and its class, think of cookie cutters and cookies. The cookie cutter is the class. It defines the characteristics of each cookie, for example size and shape. The class is used to create objects. The objects are the cookies.

Two examples in Visual Basic might help illustrate the relationship between classes and objects.

  • The controls on the Toolbox in Visual Basic represent classes. When you drag a control from the Toolbox onto a form, you are creating an object — an instance of a class.
  • The form you work with at design time is a class. At run time, Visual Basic creates an instance of the form's class — that is, an object. 2. Code: A key part of developing applications using Visual Basic is ensuring that the code is carefully structured. This involves segmenting the code into projects , modules and procedures so that it is easy to understand and maintain.

A complete Visual Basic application is typically contained in a single project. Within a project , code is placed in separate code files called modules , and within each module , the Visual Basic code is further separated into self-contained and re-usable procedures

Visual Basic procedures provide a way to break up code into logical and re-usable sections that can be called from other sections of Visual Basic code. For example, you might have a section of Visual Basic code that calculates the interest due on a loan. It is also possible that you need to perform this calculation from a number of different places in your application code. Rather than duplicating the code to perform this task at each code location where it is needed, it is more efficient to place the calculation code in a procedure, and then call that procedure each time it is needed.

Modules Code in Visual Basic is stored in the form of modules. The three kind of modules are Form Modules, Standard Modules and Class Modules. A simple application may contain a single Form, and the code resides in that Form module itself. As the application grows, additional Forms are added and there may be a common code to be executed in several Forms. To avoid the duplication of code, a separate module containing a procedure is created that implements the common code. This is a standard Module.

Class module (.CLS filename extension) are the foundation of the object oriented programming in Visual Basic. New objects can be created by writing code in class modules. Each module can contain:

Declarations : May include constant, type, variable and DLL procedure declarations.

Procedures : A sub function, or property procedure that contain pieces of code that can be executed as a unit.

These are the rules to follow when naming elements in VB - variables, constants, controls, procedures, and so on:

 A name must begin with a letter.  May be as much as 255 characters long (but don't forget that somebody has to type the stuff!).  Must not contain a space or an embedded period or type-declaration characters used to specify a data type; these are! # % $ & @  Must not be a reserved word (that is part of the code, like Option, for example)  The dash, although legal, should be avoided because it may be confused with the minus sign. Instead of First-name use First_name or FirstName.

Data types By default Visual Basic variables are of variant data types. The variant data type can store numeric, date/time or string data. When a variable is declared, a data type is supplied for it that determines the kind of data they can store. The fundamental data types in Visual Basic including variant are integer, long, single, double, string, currency, byte and boolean. Visual Basic supports a vast array of data types. Each data type has limits to the kind of information and the minimum and maximum values it can hold. In addition, some types can interchange with some other types. A list of Visual Basic's simple data types are given below.

1. Numeric

Byte Store integer values in the range of 0 - 255

Integer Store integer values in the range of (-32,768) - (+ 32,767)

Long Store integer values in the range of (- 2,147,483,468) - (+ 2,147,483,468)

Single Store floating point value in the range of (-3.4x10-38) - (+ 3.4x1038)

Double Store large floating value which exceeding the single data type value

Currency store monetary values. It supports 4 digits to the right of decimal point and 15 digits to the left

2. String

Use to store alphanumeric values. A variable length string can store approximately 4 billion characters

3. Date

Use to store date and time values. A variable declared as date type can store both date and time values and it can store date values 01/01/0100 up to 12/31/

4. Boolean

Boolean data types hold either a true or false value. These are not stored as numeric values and cannot be used as such. Values are internally stored as -1 (True) and 0 (False) and any non-zero value is considered as true.

5. Variant

Stores any type of data and is the default Visual Basic data type. In Visual Basic if we declare a variable without any data type by default the data type is assigned as default.

Operators

Arithmetical Operators

Operators Description Example Result

  • Add 5+5 10
  • Substract 10-5 5 / Divide 25/5 5 \ Integer Division 20\3 6
  • Multiply 5*4 20 ^ Exponent (power of) 3^3 27 Mod Remainder of division 20 Mod 6 2

Variable Declaration

In Visual Basic, it is a good practice to declare the variables before using them by assigning names and data types. They are normally declared in the general section of the codes' windows using the Dim statement. You can use any variable to hold any data , but different types of variables are designed to work efficiently with different data types. The syantax is as follows:

Dim VariableName As DataType

If you want to declare more variables, you can declare them in separate lines or you may also combine more in one line , separating each variable with a comma, as follows:

Dim VariableName1 As DataType 1, VariableName2 As DataType 2, VariableName3 As DataType 3

Example Dim password As String Dim firstnum As Integer Dim secondnum As Integer Dim total As Integer Dim doDate As Date Dim password As String, yourName As String, firstnum As Integer

Unlike other programming languages, Visual Basic actually doesn't require you to specifically declare a variable before it's used. If a variable isn't declared, VB willautomatically declare the variable as a Variant. A variant is data type that can hold any type of data.

For string declaration, there are two possible types, one for the variable-length string and another for the fixed-length string. For the variable-length string, just use the same format as example 5. above. However, for the fixed-length string, you have to use the format as shown below:

Dim VariableName as String * n, where n defines the number of characters the string can hold.

Example

Dim yourName as String * 10

yourName can holds no more than 10 Characters.

Scope of Declaration Other than using the Dim keyword to declare the data, you can also use other keywords to declare the data. Three other keywords are private ,static and public. The forms are as shown below:

Private VariableName as Datatype Static VariableName as Datatype Public VariableName as Datatype

The above keywords indicate the scope of declaration. Private declares a local variable, or a variable that is local to a procedure or module. However, Private is rarely used, we normally use Dim to declare a local variable. The Static keyword declares a variable that is being used multiple times, even after a procedure has been terminated. Most variables created inside a procedure are discarded by Visual Basic when the procedure is finished, static keyword preserve the value of a variable even after the procedure is terminated. Public is the keyword that declares a global variable, which means it can be used by all the procedures and modules of the whole program.

Syntax means rules of writing the program.

Example: x=z*/b;

There is syntax error in this statement. The rules of binary operators state that there cannot be more than one operator between two operands.

 Runtime Errors: These Errors are determined at the execution time of the program.

Example: Divide by zero

Range out of bounds

Square root of a negative number

 Logical Errors: These Errors occur due to incorrect usage of the instruction in the program. These errors are neither displayed during compilation or execution nor cause any obstruction to the program execution. They only cause incorrect outputs. Logical Errors are determined by analyzing the outputs for different possible inputs that can be applied to the program. By this way the program is validated.

Testing and Validating: Testing and Validation is performed to check whether the program is producing correct results or not for different values of input.

Documentation and Maintenance: Documentation is the process of collecting, organizing and maintaining, in written the complete information of the program for future references. Maintenance is the process of upgrading the program according to the changing requirements.

For writing up the instructions as a program in the way that a computer can understand, we use programming languages.

Debug, Compile and Execution Terms

Debugging is the process of locating and fixing or bypassing bugs (errors) in computer program code. Programs sometimes have small errors, called "bugs," in them. These bugs can be minor, such as not recognizing user input, or more serious, such as a memory leak that crashes the program.

Compiling is the transformation from Source Code (human readable) into machine code (computer executable). A compiler is a program. A compiler takes the recipe (source code) for a new program (written in a high level language) and transforms this Code into a new language (Machine Language) that can be understood by the computer itself. This "machine language" is difficult to impossible for humans to read and understand (much less debug and maintain), thus the need for "high level languages" such as VB.

Compiler terminology

Compile Colloquially, to convert a source code file into an executable, but strictly speaking, compilation is an intermediate step

Link The act of taking compiled code and turning it into an executable

Build A build refers to the process of creating the end executable (what is often colloquially referred to as compilation). Tools exist to help reduce the complexity of the build process-- makefiles, for instance.

Compiler Generally, compiler refers to both a compiler and a "linker"

Linker The program that generates the executable by linking

IDE I ntegrated D evelopment E nvironment, a combination of a text editor and a compiler, such that you can compile and run your programs directly within the IDE. IDEs usually have facilities to help you quickly jump to compiler errors.

Execute a program is to run the program in the computer, and, by implication, to start it to run. Process by which a computer or a virtual machine performs the instructions of a computer program