Вы находитесь на странице: 1из 34

CALCULATOR

AIM:
To write a VB.net program using windows application to perform calculator operation.

ALGORITHM:
Step 1: Start the program. Step 2: drag a textbox and eighteen buttons from the toolbox . Step 3: Memory button used to store the current value in the textbox. Step 4: Recall button used to display the stored value in the textbox. Step 5: cancel button used to clear the textbox. Step 6: To perform addition, subtraction, multiply and division operation button 0 to 9 used as a operand by using +,-,*,/ button . Step 7: if you click = button, then it shows the output in the textbox. Step 8: Stop the program.

PROGRAM:
Public Class Form1 Dim operand1 As Double Dim operand2 As Double Dim [operator] As String Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click, Button2.Click, Button3.Click, Button4.Click, Button5.Click, Button5.Click, Button6.Click, Button6.Click, Button7.Click, Button8.Click, Button9.Click, Button11.Click TextBox1.Text = TextBox1.Text & sender.text End Sub Private Sub Button10_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button10.Click If InStr(TextBox1.Text, ".") > 0 Then Exit Sub Else TextBox1.Text = TextBox1.Text & "." End If End Sub Private Sub Button13_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button13.Click operand1 = Val(TextBox1.Text) TextBox1.Text = "" TextBox1.Focus() [operator] = "+" End Sub Private Sub Button14_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button14.Click operand1 = Val(TextBox1.Text) TextBox1.Text = TextBox1.Focus() [operator] = "-" End Sub Private Sub Button15_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button15.Click operand1 = Val(TextBox1.Text) TextBox1.Text = "" TextBox1.Focus() [operator] = "*" End Sub Private Sub Button16_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button16.Click operand1 = Val(TextBox1.Text) TextBox1.Text = ""

TextBox1.Focus() [operator] = "/" End Sub Private Sub Button17_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button17.Click Dim result As Double operand2 = Val(TextBox1.Text) Select Case ([operator]) Case "+" result = operand1 + operand2 MsgBox(result) TextBox1.Text = result Case "-" result = operand1 - operand2 MsgBox(result) TextBox1.Text = result Case "*" result = operand1 * operand2 MsgBox(result) TextBox1.Text = result Case "/" result = operand1 / operand2 MsgBox(result) TextBox1.Text = result End Select TextBox1.Text = result End Sub Private Sub Button12_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button12.Click TextBox1.Text = "" End Sub End Class

WINDOWS FORM:

OUTPUT:

RESULT:
Thus the VB.net program using windows application to perform calculator operation has been executed and the output is verified successfully.

EMPLOYEE DATABASE

AIM:
To implement and create an database application of student details using Visual Basic.Net.

ALGORITHM:
Step1: Start the program. Step 2: Choose a windows form application in VisualBasic Step 3: Design the form as per the form design Step 4: Write the code for all the required events Step 5: Create a database for storing all the required data Step 6: Compile the program using build command Step 7: Run the program using start debugging command. Step8: Stop the program.

WINDOW FORM:

PROGRAM:
Imports System.Data.OleDb Public Class Form1 Dim con As New OleDbConnection Dim com As New OleDbCommand Dim da As New OleDbDataAdapter Dim rd As OleDbDataReader Dim dps, sql As String Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load dps= "Provider=Microsoft.ACE.OLEDB.12.0;Data Source=F:\abinaya01\empdetails\emp.accdb" con.ConnectionString = dps con.Open() End Sub Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click sql = "insert into empo (name,age) values ('" & TextBox1.Text & "'," & TextBox2.Text & ")" da.InsertCommand = New OleDbCommand(Sql, con) da.InsertCommand.ExecuteNonQuery() MsgBox("inserted to db") TextBox1.Text = "" TextBox2.Text = "" TextBox3.Text = "" End Sub Private Sub Button2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button2.Click sql = "update empo set salary = " & TextBox3.Text & "where name = '" & TextBox1.Text & "'" da.UpdateCommand = New OleDbCommand(sql, con) da.UpdateCommand.ExecuteNonQuery() MsgBox("updated to db") TextBox1.Text = "" TextBox2.Text = "" TextBox3.Text = "" End Sub Private Sub Button3_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button3.Click sql = "delete from empo where name='" & TextBox1.Text & "'" da.DeleteCommand = New OleDbCommand(sql, con) da.DeleteCommand.ExecuteNonQuery() MsgBox("deleted from db") TextBox1.Text = "" TextBox2.Text = "" TextBox3.Text = "" End Sub

Private Sub Button4_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button4.Click sql = "select age,salary from empo where name = '" & TextBox1.Text & "'" com.CommandText = sql com.Connection = con rd = com.ExecuteReader() If rd.Read Then TextBox2.Text = rd.GetValue(0) TextBox3.Text = rd.GetValue(1) rd.Close() End If End Sub Private Sub Button5_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button5.Click TextBox1.Text = "" TextBox2.Text = "" TextBox3.Text = "" End Sub End Class

OUTPUT:

RESULT:
Thus employee details application has been implemented and executed successfully.

MDI APPLICATION Aim: To write a VB.net program using windows application to implement multiple document interface.

Algorithm: 1. Create three forms as form1, form2 and form3. 2. In form1, drag two labels, textboxes and button. 3. In form2 and form3, drag two labels. 4. If you click button1 in the form1, then it shows form2 with content in the textbox1. 5. If you click button2 in the form1, then it shows form3 with content in the textbox2.

PROGRAM CODE: Public Class Form1 Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click Dim a As New Form2 a.Show() End Sub Private Sub Button2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button2.Click Dim a1 As New Form3 a1.Show() End Sub End Class Public Class Form2 Private Sub Form2_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load Label2.Text = Form1.TextBox1.Text End Sub End Class Public Class Form3 Private Sub Form3_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load Label2.Text = Form1.TextBox2.Text End Sub End Class

OUTPUT:

RESULT: Thus the Project to perform MDI Operation in VB.Net using the concept of Window Forms was successfully implemented and executed.

MENU CONTROLS

Aim: To develop a Project to perform menu controls Operation in VB.Net using the concept of Window Forms. Algorithm: 1. Drag the menustrip, savedialog, opendialog, fontdialog and a textbox. 2. In textbox, select the multiline. 3. Create file, edit, help menu and also new, open, save, close, cut, copy, paste, font, about option using menustrip tool. 4. In file menu, open a new file using new option, open a file using open option, save a file using save option, close the form using close option. 5. In edit menu, cut the content using cut option, copy the content using copy option, copied content will be paste by using paste option, change the font of the content 6.In help menu, about is used to display the message.

PROGRAM: Public Class Form1 Private Sub NewToolStripMenuItem_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles NewToolStripMenuItem.Click TextBox1.Text = "" End Sub Private Sub OpenToolStripMenuItem_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles OpenToolStripMenuItem.Click OpenFileDialog1.ShowDialog() If OpenFileDialog1.FileName = "" Then Exit Sub End If Dim tmp As String FileSystem.FileOpen(1, OpenFileDialog1.FileName, OpenMode.Input) Do While Not FileSystem.EOF(1) tmp = tmp & FileSystem.LineInput(1) If Not EOF(1) Then End If Loop FileSystem.FileClose() TextBox1.Text = tmp End Sub Private Sub SaveToolStripMenuItem_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles SaveToolStripMenuItem.Click SaveFileDialog1.ShowDialog() If SaveFileDialog1.FileName = "" Then Exit Sub End If FileSystem.FileOpen(1, SaveFileDialog1.FileName, OpenMode.Output) FileSystem.Print(1, TextBox1.Text) FileSystem.FileClose() End Sub Private Sub CloseToolStripMenuItem_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles CloseToolStripMenuItem.Click End End Sub Private Sub CutToolStripMenuItem_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles CutToolStripMenuItem.Click TextBox1.SelectedText = " " End Sub Private Sub CopyToolStripMenuItem_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles CopyToolStripMenuItem.Click Clipboard.SetText(TextBox1.SelectedText) End Sub

Private Sub PasteToolStripMenuItem_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles PasteToolStripMenuItem.Click TextBox1.SelectedText = Clipboard.GetText End Sub Private Sub FontToolStripMenuItem_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles FontToolStripMenuItem.Click fontdialog1.showdialog() TextBox1.Font = FontDialog1.Font End Sub Private Sub AboutToolStripMenuItem_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles AboutToolStripMenuItem.Click MsgBox("this is vb.net") End Sub End Class

OUTPUT:

RESULT: Thus the Project to perform Menu controls Operation in VB.Net using the concept of Window Forms was successfully implemented and executed.

NOTEPAD Aim: To develop a Project to perform Notepad Operation in VB.Net using the concept of Window Forms. Algorithm: 1. Create a form to display the text using text box. 2. In the form place rich text box to display the text. 3. Using menu strip, create menus such as New, Open, Save, Save as, Print, Exit, Cut, Copy, Paste, Find etc. 4. Add open dialog, save dialog, font dialog, to the form which is used to show the Open, Save dialog box. 5. Write a necessary coding for the menus. 6. Execute the program.

PROGRAM: Public Class Form1 Private Sub NewToolStripMenuItem_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles NewToolStripMenuItem.Click If RichTextBox1.Modified = True Then Dim x As Integer = MsgBox("Do you want to save the modified document ?", MsgBoxStyle.YesNo) If x = vbYes Then SaveToolStripMenuItem.PerformClick() Else Me.Text = "Untitled" RichTextBox1.Clear() End If Me.Text = "Untitled" RichTextBox1.Clear() End If End Sub Private Sub OpenToolStripMenuItem_Click(ByVal sender As System.Object, ByVal e System.EventArgs) Handles OpenToolStripMenuItem.Click Try Dim dlg As OpenFileDialog = New OpenFileDialog dlg.Title = "Open" dlg.Filter = "Rich Text Files (*.rtf|*.rtf" If dlg.ShowDialog() = System.Windows.Forms.DialogResult.OK Then RichTextBox1.LoadFile(dlg.FileName) End If Catch ex As Exception : End Try End Sub Private Sub SaveToolStripMenuItem_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles SaveToolStripMenuItem.Click Try Dim dlg As SaveFileDialog = New SaveFileDialog dlg.Title = "Save" dlg.Filter = "Rich Text Files(*.rtf)|*.rtf" If dlg.ShowDialog() = System.Windows.Forms.DialogResult.OK Then RichTextBox1.SaveFile(dlg.FileName, RichTextBoxStreamType.RichText) End If Catch ex As Exception : End Try End Sub As

Private Sub SaveAsToolStripMenuItem_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles SaveAsToolStripMenuItem.Click Try Dim dlg As SaveFileDialog = New SaveFileDialog dlg.Title = "Save As" dlg.Filter = "Rich Text Files(*.rtf)|*.rtf" If dlg.ShowDialog() = System.Windows.Forms.DialogResult.OK Then RichTextBox1.SaveFile(dlg.FileName, RichTextBoxStreamType.RichText) End If Catch ex As Exception : End Try End Sub Private Sub PrintToolStripMenuItem_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles PrintToolStripMenuItem.Click PrintDialog1.ShowDialog() End Sub Private Sub ExitToolStripMenuItem_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles ExitToolStripMenuItem.Click 'exit the program End End Sub Private Sub CutToolStripMenuItem_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles CutToolStripMenuItem.Click RichTextBox1.Clear() End Sub Private Sub CopyToolStripMenuItem_Click(ByVal sender As System.Object, ByVal e System.EventArgs) Handles CopyToolStripMenuItem.Click RichTextBox1.Copy() End Sub Private Sub PasteToolStripMenuItem_Click(ByVal sender As System.Object, ByVal e System.EventArgs) Handles PasteToolStripMenuItem.Click RichTextBox1.Paste() End Sub As

As

Private Sub SelectAllToolStripMenuItem_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles SelectAllToolStripMenuItem.Click RichTextBox1.SelectAll() End Sub Private Sub UndoToolStripMenuItem_Click(ByVal sender As System.Object, ByVal e System.EventArgs) Handles UndoToolStripMenuItem.Click If RichTextBox1.CanUndo Then As

RichTextBox1.Undo() End If End Sub Private Sub RedoToolStripMenuItem_Click(ByVal sender As System.Object, ByVal e System.EventArgs) Handles RedoToolStripMenuItem.Click RichTextBox1.Redo() End Sub Private Sub FontToolStripMenuItem_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles FontToolStripMenuItem.Click FontDialog1.ShowDialog() RichTextBox1.Font = FontDialog1.Font End Sub Private Sub FindToolStripMenuItem_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles FindToolStripMenuItem.Click Dim a As String Dim b As String a = InputBox("Enter text to be found") b = InStr(RichTextBox1.Text, a) If b Then RichTextBox1.Focus() RichTextBox1.SelectionStart = b - 1 RichTextBox1.SelectionLength = Len(a) Else MsgBox("Text not found.") End If End Sub End Class As

OUTPUT:

RESULT: Thus the Project to perform Notepad Operation in VB.Net using the concept of Window Forms was successfully implemented and executed.

Вам также может понравиться