Sunday, 7 July 2013

FROM VB6 TO VB.NET


The switch form the old visual studio versiom6 to newer Visual Studio .NET to Create Visual BAsic
programs represents a update in technology . It represents far more than changing of a version name. When upgrading from Visual Studio 6 , Instead of naming it version , Microsoft used the term .NET as the name of the new version to denate the difference that it carries from the older technology .Faculty members teaching programming courses in visual  basic have to learn about the changes in new version of visual basic in order to Switch from teaching the older vb6.


The Changes in VB programs are not only ones of terminology . Instead they reflect structural changes in how files are created and grouped and how they are then divided to provide the final functianality of program. In order to explain these STRUCTURAL CHANGES between the two versions of VB, we first create a simple project in VB6 to see different files and folders it created . We called this project "Proj1" and then checked then checked the files created from this program. Three files were created from this simple program in VB6. Proj1.vbp. for project file, proj1.frm for the form file and Proj1.vbw for workspace file. We then proceeded to create the same program in VB.NET and found that it created 14 files and stored them in 6 folders.

CoNCEPT OF CLASSES In VB.NET Not in VB6
Object oriented is not new to vb environment . It is used in the older vb6 environment. Most Textbooks did not cover this subject in depth . VB.NET can be taught without explaining classes and objects .

Public class frmRentals.........
        Inherits system.windows.forms.form

These lines are usually displayed at beginning of visual basic program in vb.net environment.This shows the nature of move towards OOPS concept in VB.NET. VB.NET includes a code generated code, but students can see it and may cause errors if they modify it. when user want to hidden code then they can click on + sign.

Friday, 5 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

Wednesday, 3 July 2013

Date Difference Am to Pm Visual Basic.NET



Instructions To Operate Date Difference Am to Pm 
* First Enter Date 'Hr', 'Min' and 'Sec' TextBox In First Row
* Also Choose "Am/Pm" from ComboBox In first Row
* Now Put Check Mark on  "Submit checkbox "
* Similarly Enter 'Hr', 'Min' and 'Sec' TextBox In Second Row
 * Choose "Am/Pm" from ComboBox In Second Row
* Then click on Submit checkbox in second Row

NOTE :- It is must to Click on Submit ChekBox After Entering Data at Respective Rows

* Finally click on "Get Date diff" Button .



Working Date Difference Am to Pm :-

1. In Fig.1 you can see the structure of Date diff App.

 . 


2. It also consist of combo Box To select Am/Pm Time . 

 3. After filling values in Text Boxes Its necessary to put check mark on check box "submit" .
 It display date entered .
 4. Finally click on Button Get date diff and it display date on Date-Diff labelled textboxes.

 CODE FOR Date Difference Am to Pm 



Public Class Form1
    Public gethr, getmin, getsec, gethr1, getmin1, getsec1, total1, total2, finaltotal, hr1, hr2, diffhr, min1, sec1 As Integer
    Private Sub CheckBox1_CheckedChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles CheckBox1.CheckedChanged
        If CheckBox1.Checked = True Then
            TextBox10.Text = TextBox10.Text + "-" + TextBox1.Text + "-" + TextBox2.Text + "-" + TextBox3.Text + "-" + ComboBox1.SelectedText
            gethr = Val(TextBox1.Text.ToString)
            getmin = Val(TextBox2.Text.ToString)
            getsec = Val(TextBox3.Text.ToString)
            total1 = (gethr * 3600) + (getmin * 60) + (getsec)
        End If
    End Sub
    Private Sub CheckBox2_CheckedChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles CheckBox2.CheckedChanged
        If CheckBox2.Checked = True Then
            TextBox11.Text = TextBox11.Text + "-" + TextBox4.Text + "-" + TextBox5.Text + "-" + TextBox6.Text + "-" + ComboBox2.SelectedText
            gethr1 = Val(TextBox4.Text.ToString)
            getmin1 = Val(TextBox5.Text.ToString)
            getsec1 = Val(TextBox6.Text.ToString)
            total2 = (gethr1 * 3600) + (getmin1 * 60) + (getsec1)
            If ComboBox1.SelectedIndex = 0 And ComboBox2.SelectedIndex = 1 Then
                total1 = total1 + 12 * 3600
            ElseIf ComboBox1.SelectedIndex = 1 And ComboBox2.SelectedIndex = 0 Then
                total1 = total1 + 12 * 3600
            ElseIf ComboBox1.SelectedIndex = 0 And ComboBox2.SelectedIndex = 0 Then
                total1 = total1
            ElseIf ComboBox2.SelectedIndex = 0 And ComboBox1.SelectedIndex = 0 Then
                total1 = total1
            End If
            finaltotal = (Math.Abs(total1 - total2))
        End If
    End Sub
    Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
        ComboBox1.Items.Add("Am")
        ComboBox1.Items.Add("Pm")
        ComboBox2.Items.Add("Am")
        ComboBox2.Items.Add("Pm6")
    End Sub
    Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
        If finaltotal <= 60 Then
            TextBox7.Text = "0"
            TextBox8.Text = "0"
            TextBox9.Text = Math.Floor(finaltotal)
        ElseIf finaltotal > 60 And finaltotal < 3600 Then
            TextBox7.Text = "0"
            TextBox8.Text = Math.Floor(finaltotal / 60)
            TextBox9.Text = Math.Floor(finaltotal Mod 60)
        ElseIf finaltotal >= 3600 Then
            hr1 = Math.Floor(finaltotal / 3600)
            TextBox7.Text = hr1
            hr2 = hr1 * 3600
            diffhr = finaltotal - hr2
            min1 = Math.Floor(diffhr / 60)
            TextBox8.Text = min1
            sec1 = finaltotal Mod 60
            TextBox9.Text = sec1
        End If
    End Sub
End Class

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 )




Sunday, 30 June 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








Friday, 28 June 2013

String Functions VB.NET

1. Len Function :- The Len function returns the length of the string variable given as argument to
Len Function. It counts the number of characters a string variable contains and it also counts the white spaces included in the string .
Syntax :- 
Len ( String_Variable )

Example :-

Dim Str as String  = "Hello geeks"
Dim length as integer
length = Len ( Str )
Msgbox (length )

2. Left, Right, Mid Functions :- 
* The Left Function returns specified number of characters from left side of string variable value
* The Right Function returns specified number of characters from Right side of string variable value
* The Mid Function Returns specified number of characters from anywhere in the string variable value. You have to specify from which character position to start and how much characters to take from string.

Syntax :- 
Left ( String_Variable )
Right ( String_Variable )
Mid ( String_Variable )

Example :-

Dim Str as String  = "Hello geeks"
Msgbox ( Left ( Str ))
Msgbox (Right ( Str ))
Msgbox (Mid ( Str , 3, 6 ))

3. LCase And  Ucase  :- The LCase converts a string to all lowercase and UCase Converts a String to all UpperCase Letters.

Syntax :- 
LCase ( String_Variable )
UCase ( String_Variable )

Example :- 

Dim Str as String  = "Hello geeks"
Msgbox ( LCase ( String_Variable ))
Msgbox (UCase ( String_Variable ))

4. Space Functions :- The Space Function is used to put given number of spces within string variable or between two or more string variable values .

Syntax :- 
Space ( value )

Here value specifies the number of spaces you want to put .

Example :- 

Dim Str as String  = "Hello"
Dim Str1 as String = "geeks"
Msgbox ( Str & space ( 1 ) & Str1 )
' It Returns "Hello geeks"

5. String Function :- The String Function Returns a repeating character string of Specified length The specified character will be repeated specified n number of times.

Syntax :- 
String ( n, character )

Example :-

Dim Str as String  = "Hello"
Dim Str1 as String = "geeks"
Msgbox ( String ( 4, "*" ) & Str &  String ( 1, "*" ) & Str1 & String ( 4, "*" ))
' It Returns ****Hello*geeks****

6. Instr Function :- The Instr Function is used to find a Substring within a string variable. This function uses three arguments .first is - starting position in string ,second is name of the string variable , third is Substring that is to be found within the string variable

Syntax :- 
Instr ( starting-position, var-name, Substring )

Example 

Dim Str as String = "Hello geeks"
Dim Substring as String ="gee"
Msgbox ( Instr( 0, Str, Substring ))
' It Returns 9

7. StrReverse Function :- The String Reverse Function returns a string in which the character  order will be reversed as that of order of original given string. It means in string reverse first character of original given string will be placed at last of new string after Reverse operation 

Syntax :- 
StrReverse ( String_variable )

Example :-

Dim Str as String 
Dim Reverse as String
Str = "Hello geeks"
Reverse = StrReverse ( Str )
Msgbox ( "String After Reverse is :- " + Reverse )

Thursday, 27 June 2013

Writing first program in VB.NET


First application will be named

HelloWorld

HelloWorld :-
1.  Open Visual Basic IDE. 


2.  Click File then-> New Project (Ctrl + N) and Select Windows Forms Application

3.  In Name box, write: HelloWorld. Use Browse button to select folder location for this
Application and press OK.  

4.  A new application will be created and Form will appear. Drag and drop the button from the
toolbox on the form. 

ToolBox :- 



5.  Select the form and change Text property of the button to HWGUI.

6.  Select the button and change Text property of the button to Click Me.  Double click the button
to open code page and Add the following line.
          MsgBox("Hello World")

7.  To run the code, press F5 or go to Debug > Start Debugging 

8.  In run mode, Press the button of Click Me  . A popup will appear displaying the message Hello
World

Hello worls Application Look


9.  You can run this application by clicking the exe file from
..\HelloWorld\HelloWorld\bin\Debug folder

CREATING AND USING VARIABLES IN VISUAL BASIC.NET

A Variable is Declared In following format in visual basic.NET :-

Dim variable-name As Datatype

where Dim is a keyword Used For Creating Variable in Visual Basic.
* Variable-name is Name of variable 
* As is a Keywork used to Define Datatype of variable after it
* Datatype is Type of Data That the Data is going to Accept

EXAMPLE 1 :-

Dim msg as string 
msg = "Hello How Are You"
Msgbox(msg)

This code will message "Hello How Are You" With Default Ok Button


EXAMPLE 2 :-



Dim msg as string 

Dim msg1 as string
msg = "Hello How"
msg1= "Are You"
Msgbox(msg + msg1)

This code will message "Hello How Are You" With Default Ok Button