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 )