Monday, 8 July 2013

Introduction To Visual Basic - II

VISUAL BASIC AS OOPS ( Object Oriented Programming )

In this world , Every thing is an object and every object has a type known as a class. In object oriented programming
, the solution of a problem is divided in terms of objects rather than procedures / functions . Every object is associated with a class. And a class encapsulates both data and functions that operate on this data. The data of an object are called as data members and the functions are called as member functions in C++. 

Data Members of object are accessed through members functions of class to which member functions belong to 

Like C++ or JAVA , Visual Basic also provides the facility of defining a class and object of a class type. Actually Visual Basic is an event Driven Programming based on objects

VARIOUS OOPS CONCEPTS IN VISUAL BASIC.NET ARE -

* Namespaces
* Classes and Objects
* Inheritance
* Polymorphism
* Data Hiding or Security of Data

VISUAL BASIC -- A EVENT DRIVEN PROGRAMMING LANGUAGE

Visual Programming is also an Event-Driven Programming . By Event-Driven Programming , it means code remains idle until called upon to respond to some event . In Event-Driven Programming an application is built up as a series of responses to user events

Visual Basic is at typical event-driven programming language . Visual Basic is governed by an event processor . When a typical Visual Basic application runs, nothing happens until an event on which programming is done is supplied or detected , the code corresponding to that event is executed by the event processor 




Of Course, All Windows applications are event-driven applications .

Example :-

If you programmed some code to be performed when user click on 'Submit' Button then Nothing happens until user clicks on "Submit" button . So in this way code will be executed on occurrence of Button_Click Event 

MAIN EVENTS ARE :-

Events availaible in Visual basic or VB.NET environment depend on which control you have choosen. Main events are :-

* Click
* DblClcik
* Keypress
* Keyup
* KeyDown
* Text_Changed
* Mouseup
* MouseMove
* MouseEnter
* MouseHover
* MouseWheel
* load
* selectedindexchanged
* Resize

Friday, 5 July 2013

Introduction To Visual Programming

The Field of visual Programming has grown from a marriage of work in Computer Graphics, Programming languages and Human - Computer Interaction. As the fields of Visual Programming
Languages have matured, more and more interest has been focused on creating robust, Standardized classification for work in this area.

WHAT IS VISUAL BASIC PROGRAMMING LANGUAGE {VB}

Visual Programming Language refers to any programming language that allows the user to specify a program in two or more dimensional ways. Conventional textual languages are not considered two-dimensional since the compilers and interpreters process them as one dimensional stream of characters . A Visual Programming Language allows Programming with Visual Expressions.

Visual Programming language may be further classified, according to the type and extent of visual expression used, into icon-based languages, form-based languages and diagram languages. Visual programming environment provides graphical or iconic elements which can be manipulated by the user in an interactive way according to some specific spatial grammar for program construction.


Visual Basic , Visual C++ and Entire Microsoft Visual family are not considered as Visual programming Languages. They are Textual Languages that use a graphical GUI Builder to make programming interfaces easier. The user interface portion of programming environment is visual ,the language are not . Because of the confusion caused by multiple meanings of Visual Programming, Fred Lakin proposed the term "executable graphics" as alternative to VPL .


Example of Visual Programming Languages are :-


* Prograph

* Pict
* Tinkertory
* Fabrik
* CODE 2.0 
* HyperPascal

In Fact, a typical Visual Programming includes the concept of a conventional programming language or Structured programming- Such as C / Pascal , Object Oriented Languages like - C++, Java, Event-Driver Programming Languages like - Visual Basic or Visual C++.

VISUAL BASIC AS STRUCTURED PROGRAMMING

Visual Basic Provides Features of Structured Programming. When High Level Programming  Languages were introduced, statements were exected in the order in which they are written in the program. This is called as normal flow of execution of a program. But the programmer's need increased , other programming constructs , such as loops or decision making constructs were introduced. And finally to solve large and complex programs , they were divided into subprograms , also known as modules. If the subprograms are still difficult to manage , they are further divided into Subprograms .

Visual Basic , As Structured programming language involves four basic control Structures -

* Sequential
* Conditional
* Repetition
* Procedures

1 The Sequential Control Structures are composed of statements executed one after another

DATA FLOW DIAGRAM (DFD) of Sequential statements



2. The Conditional Structure Executes different set of statements depending upon certain condition . Examples of conditional structures in Visual Basic are If-Else-Endif and Select-Case Statements

DATA FLOW DIAGRAM (DFD) of Conditional statements



3. The Repetitive structures repeat set of statements while certain conditions are met. Examples of  repetitive statements are loop, do-while loop, do-until loop, while-wend loop.

4. The Procedures enables us to replace a set of statements with a single statement

DATA FLOW DIAGRAM (DFD) of Procedures



Thursday, 4 July 2013

USING TEXT FILES IN VB.NET (VISUAL STUDIO 2010)

    USING TEXT FILES IN VB.NET (VISUAL STUDIO 2010)


Files are good means of transfer of data during Runtime in An Application . 

FILES ARE BETTER IF WE HAVE LESS AMOUNT OF DATA TO SEND AND RECEIVE FROM TEXTFILES.

FOR SMALL APPLICATIONS FILES ARE BETTER AS COMPARED TO DATABASE BECAUSE DATABASE CONSUMES MORE TIME AS COMPARED TO TEXTFILES FOR FETCHING DATA FROM DATABASE

BUT FOR LARGE APPLICATIONS FILES ARE CONSIDERED TO BE UNABLE TO MANAGE LARGE DATA IN WELL-DEFINED ORGANISED WAY.

STREAMREADER is Used in Visual Basic . NET to Read Data from TextFiles . An Object is first created of type streamreader that is inbuilt class described under Namespace System.io.Streamreader

STREAMWRITER is Used In Visual Basic .Net to Write Data to TextFiles. An Object is first created of type streamwriter that is inbuilt class described under Namespace System.io.Streamwriter

peek() function is used to detect the end of file while reading the data from file

EXAMPLE TO SHOW USE OF FILES :-

READ DATA FROM TEXT FILE

Create Reader Object 

A File is read by creating a file Reader object is created by declaring a object of type system.io.streamreader Namespace as follows :-

Dim objreader As  System.IO.StreamReader = New System.IO.StreamReader( "path of text file" )

Here
           objreader is object of type streamreader in system.io Class That is used to read the Stream of Data From Text files . An object is similar like we create a variable of basic Data Types .
          
            System - It is a Main Namespace 
            IO - It is a Sub namespace included in system Namespace
            Streamreader - It is a Class of Type IO Namespace

Read Data

TextBox1.Text = objreader.ReadLine() --------(1)
In this Streamreader object objreader reads Single line from TextFile Whose path is given

TextBox1.Text = objreader.Read()-------------(2)
In this Streamreader object objreader reads Single Characte from TextFile Whose path is given

TextBox1.Text = objreader.ReadToEnd()------(3)
In this Streamreader object objreader reads Whole Data from TextFile Whose path is given

WRITE DATA TO TEXT FILE



A File is written by creating a file writter object is created by declaring a object of type system.io.streamwriter Namespace as follows :-



Dim objwriter As  System.IO.StreamWriter = New System.IO.StreamWriter( "path of text file" )

Here, 
           objwriter is object of type streamwriter in system.io Class That is used to write the Stream of Data to Text files . An object is similar like we create a variable of basic Data Types .
          
            System - It is a Main Namespace 
            IO - It is a Sub namespace included in system Namespace
            Streamwriter - It is a Class of Type IO Namespace

Write Data

TextBox1.Text = objwriter.Writeline() --------(1)
In this StreamWriter object objwriter Writes Single line To TextFile Whose path is given

TextBox1.Text = objreader.Read()-------------(2)
In this StreamWriter object objwriter Writes Single Characte To TextFile Whose path is given

What is XML

 HTML and XML are brother and sister. Their mother is SGML


XML is Widely used For Communication over web with various types of web services
When we communicate over web or Internet using Hyper text protocols Get and Post Method
To Get and Post data over web XML is highly used 

XML stands for Extensible Markup Language
XML is a markup language much like HTML And Similarly It consist of Tags.
XML was designed to Deal Mainly with Storage of Data Rather Than Display or Presentation     Of Data as Done in HTML
XML tags are not Fixed Tags You Can define your own tags with Different Names And these tags can be defined by user or declared by user According to Data You want to Store
XML is Self - Descriptive in nature And All Tags Are According to Data That is to be stored
XML is a Most Widely used Data storage Today

DIFFERENCE BETWEEN HTML AND XML

HTML Is a Hypertext markUp Language.
XML Is a Extensible markUp Language

HTML Focus on Providing Good Presentation of Data Or how to present the data
XML Focus on Storage Of Data 

HTML Does not allow you to create your own Tags
XML Allow you to Create your Own Tags


ADVANTAGES OF XML

* XML is Extensible markup language that is free of cost to use. XML can be opened in
Notepad or other default Text Editor availaible in your operating System
* XML is Independent of Operating System . It can be used with any operating availaible
today
* It is easy to read Storage of Data As it is in Hierarchial Structure. We can easily
recognize the structural Elements 

* XML Is Self-Descriptive . Like HTML it consist of tags that describe the data automatically

XML WITH VISUAL BASIC.NET

* .NET Provides good support for XML. It can easily used for storing data From Winform 
In .NET To XML Files 

* In .NET Namespace used for using XML files is :- 

System.xml

1. First ,  We Require XML Document
2. Secondly, We Require other Elements like - Declaration, comment, root, element1(name), element2(age),element3(gender).
3. Now Get Values to be stored or to get to and from XML Document
4. Now Create the xml doc.

CREATE XML DOCUMENT

An xml document is created by declaring the following elements first :-

 Dim declarexmldoc As XmlDeclaration = doc.CreateXmlDeclaration("1.0", "UTF-8", "yes")
            Dim xmlcomment As XmlComment = doc.CreateComment("This is my xml document")
            Dim xmlroot As XmlElement = doc.CreateElement("Persons")
            Dim person As XmlElement = doc.CreateElement("Person")
            Dim name As XmlAttribute = doc.CreateAttribute("name")
            Dim age As XmlElement = doc.CreateElement("age")
            Dim gender As XmlElement = doc.CreateElement("gender")



1. declarexmldoc :- It is an object of type xmldeclaration. It consist of three arguments 

First :- First argument tells the verson number "1.0" of XML that currently we are using.

Second :- Second Argument tells the Enconding technique that we are using "UTF-8".
Where UTF-8 is a UCS Transformation Format . It is 8-bit character encoding technique .

Third :- Third Argument tells whether to create it standalone or not 

2.  xmlroot = Persons in example given below.
3.  person ,name , age, gender are elements of xml document given in example below.

EXAMPLE of AN XML DOCUMENT

<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
<!--This is my xml document-->
<Persons>
  <Person name="one">
    <age>1</age>
    <gender>I am single</gender>
  </Person>
  <Person name="two">
    <age>2</age>
    <gender>I am double</gender>
  </Person>
  <Person name="Three">
    <age>3</age>
    <gender>I am triple</gender>
  </Person>
  <Person name="Quadruple">
    <age>4</age>
    <gender>We are quadruple</gender>
  </Person>
</Persons>

Wednesday, 3 July 2013

What is XML

 HTML and XML are brother and sister. Their mother is SGML


XML is Widely used For Communication over web with various types of web services
When we communicate over web or Internet using Hyper text protocols Get and Post Method
To Get and Post data over web XML is highly used 

XML stands for Extensible Markup Language
XML is a markup language much like HTML And Similarly It consist of Tags.
XML was designed to Deal Mainly with Storage of Data Rather Than Display or Presentation     Of Data as Done in HTML
XML tags are not Fixed Tags You Can define your own tags with Different Names And these tags can be defined by user or declared by user According to Data You want to Store
XML is Self - Descriptive in nature And All Tags Are According to Data That is to be stored
XML is a Most Widely used Data storage Today

DIFFERENCE BETWEEN HTML AND XML

HTML Is a Hypertext markUp Language.
XML Is a Extensible markUp Language

HTML Focus on Providing Good Presentation of Data Or how to present the data
XML Focus on Storage Of Data 

HTML Does not allow you to create your own Tags
XML Allow you to Create your Own Tags


ADVANTAGES OF XML

* XML is Extensible markup language that is free of cost to use. XML can be opened in
Notepad or other default Text Editor availaible in your operating System
* XML is Independent of Operating System . It can be used with any operating availaible
today
* It is easy to read Storage of Data As it is in Hierarchial Structure. We can easily
recognize the structural Elements 

* XML Is Self-Descriptive . Like HTML it consist of tags that describe the data automatically

XML WITH VISUAL BASIC.NET

* .NET Provides good support for XML. It can easily used for storing data From Winform 
In .NET To XML Files 

* In .NET Namespace used for using XML files is :- 

System.xml

1. First ,  We Require XML Document
2. Secondly, We Require other Elements like - Declaration, comment, root, element1(name), element2(age),element3(gender).
3. Now Get Values to be stored or to get to and from XML Document
4. Now Create the xml doc.

CREATE XML DOCUMENT

An xml document is created by declaring the following elements first :-

 Dim declarexmldoc As XmlDeclaration = doc.CreateXmlDeclaration("1.0", "UTF-8", "yes")
            Dim xmlcomment As XmlComment = doc.CreateComment("This is my xml document")
            Dim xmlroot As XmlElement = doc.CreateElement("Persons")
            Dim person As XmlElement = doc.CreateElement("Person")
            Dim name As XmlAttribute = doc.CreateAttribute("name")
            Dim age As XmlElement = doc.CreateElement("age")
            Dim gender As XmlElement = doc.CreateElement("gender")



1. declarexmldoc :- It is an object of type xmldeclaration. It consist of three arguments 

First :- First argument tells the verson number "1.0" of XML that currently we are using.

Second :- Second Argument tells the Enconding technique that we are using "UTF-8".
Where UTF-8 is a UCS Transformation Format . It is 8-bit character encoding technique .

Third :- Third Argument tells whether to create it standalone or not 

2.  xmlroot = Persons in example given below.
3.  person ,name , age, gender are elements of xml document given in example below.

EXAMPLE of AN XML DOCUMENT

<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
<!--This is my xml document-->
<Persons>
  <Person name="one">
    <age>1</age>
    <gender>I am single</gender>
  </Person>
  <Person name="two">
    <age>2</age>
    <gender>I am double</gender>
  </Person>
  <Person name="Three">
    <age>3</age>
    <gender>I am triple</gender>
  </Person>
  <Person name="Quadruple">
    <age>4</age>
    <gender>We are quadruple</gender>
  </Person>
</Persons>

Tuesday, 2 July 2013

Conversion Functions VB.NET

Visual Basic supports a number of ways of converting from one type to another. The conversion function would take such a value , String, expression and attempt to convert it. It the conversion is successful , the function would return an appropriate value. 1. CBool :- CBool Stands for Convert to Bool . It converts String , Charcter or numeric expression into boolean value . Synatax :- CBool ( expression ) Example :- Dim a, b As Integer         a = 10         b = 20         Dim check As Boolean         check = CBool(a > b)         MsgBox(check) 2. CByte :- CByte stands for Convert to Byte Data Type. It converts numeric or floating values to byte Data Type.. If fractional part is given in variable-name then it will round off it to integer type. Synatax :- CByte ( variable-name ) Example :- Dim num1 as Double Dim num2 as Byte num1 = 2144.7865789 num2 = VByte( num1 ) Msgbox ( num2 ) 3. CDate :- CDate Stands for Convert to Date type. It converts any valid form date format given as argument to it into Date Syntax :- CDate ( Sting_Variable_Name )
Example :- 
Dim DateString As String 
Dim Finl_Date As Date
DateString = "July 3, 2013"
'The following line converts date format given in Date Type and give
it to Finl_Date
Finl_Date = CDate ( aDateString )
Msgbox ( Finl_Date.tostring())

4. CDbl :- CDbl stands for Convert to Double Data-Type. It converts 
the any given integer value to Double floating value

5. CInt :- CInt Stands for Convert to Integer Date -Type . CInt is 
widely used when converting from numbers or integers entered in string variable to convert it into integers to perform any Arithmetic operations.

Syntax :- 
CInt ( String_Variable )

Example :- 
Dim Var As String = "10"
        Dim num1, num2 As Integer
        num1 = CInt(Var)
        num2 = 10
        MsgBox(num1 + num2)
'It Returns 20

6. CChar :- CChar Stands for Convert to character. It Takes a String 
Variable as input Argument and as it convert it into char so it passes
the first character of specified string varible to a character 
variable

Syntax :-
CChar ( String_Variable )

Example :-
Dim String_variable As String = "bvf"
        Dim char_variable As Char
        char_variable = CChar(String_variable)
        MsgBox ( char_variable )

7. Cstr :- Cstr stands for convert to string . It converts any 
integer floating value given as input to CStr into string type value

Syntax :-
Cstr ( Variable_Name )

Example :-
Dim Str as String
Dim input as integer
input = 12267.9999
Str = Cstr ( input )
Msgbox ( Str )
' It Returns 12267.9999 

8. CUInt :- It converts given data value into CUint datatype . Here, 
UInt stands for Unsigned integer type.
Dim Double_Variable As Double 
Dim aUInt_Variable As UInteger
Double_Variable = 39.501
aUInt_Variable = CUInt(Double_Variable)
Msgbox ( aUInt_Variable )
'It Return 40

9. CShort :- It converts the given data value into short integer type
data value.
Syntax :- 
CShort ( Byte_Variable )
Example :-
Dim Byte_Variable As Byte 
Dim Short_Variable As Short
Byte_Variable = 100
Short_Variable = CShort(Byte_Variable)
Msgbox ( Short_Variable )

10. CDec :- It converts the given data value into Decimal Data-Type
value.
Syntax :-
CDec ( Variable_Name )
Example :-
Dim Double_Variable As Double 
Dim Decimal_Variable As Decimal
Double_Variable = 10000000.0587
Decimal_Variable = CDec(Double_Variable)
Msgbox ( Decinal_Variable )

Monday, 1 July 2013

Numeric Functions in VB.NET

Numeric Funcitons provides various function to be operated on integer or numeric variables to get Required result. Main Numeric Functions in VB.NET are :-


1. Round Function :-The Round function is used for rounding numbers to the number of digits you want. It will replace number to its most nearest by rounding off it

Syntax:-  
Round ( expression , precession)

expression  :- expression is value which Round function will round
precession :- It denotes to how many digits you want after decimal point 

Example :-

Dim num1 as integer
Dim num2 as integer
num1 = 10
num2 = 3
Dim precession as integer
Msgbox (round ( num1 / num2 , precession ))

2. Int and Fix Function :- 
Int Function is used to drop fractional part of a positive number .
Fix Function is used to drop fractional part of negative number

Syntax :-
Int ( +/-  num1 / num2 )
Fix ( +/-  num1 / num2 )

Example :-

Dim num1 as integer
Dim num2 as integer
num1 = 10
num2 = 3
Msgbox ( Int ( num1 / num2 ))
Msgbox ( Int ( - num1 / num2 )
Msgbox ( Fix ( num1 / num2 ))
Msgbox ( Fix ( - num1 / num2 ))

When Int is used with negative number , it returns the next lowest whole number.

3. Abs Function :- The Abs function returns the absolute value of a number. It means it remove the negative sign of number and it always returns the positive value.

Syntax :- 
Abs ( num1 )

Example :-

Dim num1 as integer
Dim num2 as integer
num1 = 10
num2 = -10
Msgbox ( Abs ( num1 ))
Msgbox ( Abs( num2 ))

4. Rnd Function :- Rnd Function returns a single precision , random numbers between specified value Range. 
Syntax :- 
Rnd * value

Exmple :-

Dim Random_number as integer
Random_number = Rnd * 5     ''It will produce Random numbers between 0 to 5
Msgbox ( Random_number )

5. Sgn Function :- This Function returns 1 for any positive number , -1 for any given negative number and 0 for zero number . 

Syntax :- 
Sgn ( number )

Example :-

Dim num1 as integer
Dim num2 as integer
Dim num3 as integer
num1 = 20
num2 = -20
num3 = 0
Msgbox ( sgn ( num1 ))
Msgbox ( sgn ( num2 ))
Msgbox ( sgn ( num3 ))

6. Sqr Function :- This Function returns the square root of number or specified number

Syntax :-
Sqr ( number )

Example :-

Dim num1 as integer
num1 = 10
Msgbox ( sqr ( num1))

7. Hex And Oct Function :- 
Hex Function returns hexadecimal equivalent of a decimal number 
Oct Function returns octal equivalent of decimal number

Example :-

Hex ( 12 )    ' returns a value C
Hex ( 2658  )    ' returns a value A62
Oct ( 19 )        ' returns a value 23
Oct ( 109 )        ' returns a value 135

8. Max Function :- Max Function is used several times in programming environment. Max Function returns maximum number from two numbers given as arguments to Max Function . This Max Function is applicanle for only two numbers not for more than two numbers 

Syntax :
Max ( number1 , number2 )

Example :-

Dim num1 as integer 
Dim num2 as integer 
num1 = 10
num2  = 20
Msgbox ( Max ( num1 , num2 ))    ' Returns 20