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

CAP407 : Modern Programming Tools & Techniques – III

Home Work – III


DOA: 26/March/2011 DOT: 5/April/2011 DOS: 5/April/2011

PART- A

Q1. Using console application in vb.net create a namespace with methods to read

details of student like patient_name, registration_no, con_doctor, costperday,

total days. Use member variables, procedures ,functions to calculate the bill
display the same?

Ans) Imports System. Console


 
Namespace p1
    Public Class p2
        Dim p_name, d_name As String
        Dim  C_day, day, RegNo, total As Integer
 
 
        Public Sub getdata()
            WriteLine("write your name")
 
            P_name = ReadLine()
            WriteLine("Doctor’s name")
            D_name = ReadLine()
            WriteLine("write your Reg no")
 
            RegNo = ReadLine()
            WriteLine("Cost per day")
            C_day = ReadLine()
            WriteLine("Number of days")
            day = ReadLine()
 
        End Sub
 
        Public Function amount()
            total = C_day * day
            Return total
 
 
        End Function
 
        Public Sub disp_data()
            WriteLine("Your Name : {0}", p_name)
            WriteLine("The doctor suggested:{0}", d_name)
            WriteLine("The registration no :{0}", RegNo)
 
        End Sub
 
    End Class
 
 End Namespace

Imports name_spacescustomer.p1.pt2
 
Module module1
    Sub main()
        Dim a As New p1.p2
 
 
        Console.WriteLine("patient info")
        a.getdata()
 
        Console.WriteLine("The total amount:{0}", a.amount)
 
        Console.ReadKey()
 
    End Sub
End Module

Q3. Create a windows application that calculates salary of an employee. Make use

of controls like textbox, listbox, combobox , date/time picker. Make use of


procedures and functions where ever possible?

Ans3.
Public Class Form1

Private Sub Button2_Click(ByVal sender As System.Object, ByVal e As


System.EventArgs)
End
End Sub

Private Sub Label1_Click(ByVal sender As System.Object, ByVal e As


System.EventArgs) Handles Label1.Click

End Sub

Private Sub Label4_Click(ByVal sender As System.Object, ByVal e As


System.EventArgs) Handles Label4.Click

End Sub

Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As


System.EventArgs) Handles Button1.Click
Dim tsal As Integer
tsal = Val(TextBox1.Text) + Val(TextBox2.Text) + Val(TextBox3.Text) +
Val(TextBox4.Text)
MsgBox(tsal)
End Sub

Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As


System.EventArgs) Handles MyBase.Load

End Sub

Private Sub ComboBox1_SelectedIndexChanged(ByVal sender As System.Object,


ByVal e As System.EventArgs) Handles ComboBox1.SelectedIndexChanged

End Sub
End Class

PART- B

Q4. Using a rich text box create an application in vb.net to implement


functionality of file menu?
Ans) Imports System.IO
Public Class Form1
Dim filename As String
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles Button1.Click
Dim fo As New OpenFileDialog()
Dim sr As StreamReader
fo.Filter = "textfiles(*.text)"!.text1"&"all files*.*
If fo.ShowDialog() = DialogResult.OK Then
filename = fo.FileName
sr = New StreamReader(fo.OpenFile)
RichTextBox1.Text = sr.ReadToEnd()
End If
sr.Close()
End Sub
Private Sub Button2_Click(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles Button1.Click
Dim fs As New SaveFileDialog()
Dim sw As StreamReader
fs.Filter = "textfiles(*.text)"!.text1"&"all files*.*
If fs.ShowDialog() = DialogResult.OK Then
filename = fs.FileName
sw = New StreamReader(filename)
RichTextBox1.Text = sw.ReadToEnd()
End If
sw.Close()
End Sub
End Class

Q5. Create an application in vb.net using rich text box to implement font, colour
and use of system calculator in an application?
Ans)
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) H
andles Button1.Click
        Dim cd As New ColorDialog
        cd.ShowDialog()
        RichTextBox1.SelectionColor = cd.Color
End Sub

Code for creating bold and italic text in a RichTextBox

Drag a RichTextBox (RichTextBox1) and a Button (Button1) onto the form. Enter some text in
RichTextBox1, say, "We are working with RichTextBoxes". Paste the following code in the
click event of Button1. The following code will search for text we mention in code and sets it to
be displayed as Bold or Italic based on what text is searched for.

Private Sub Button1_Click(ByVal sender As System.Object, ByVal e_


As System.EventArgs) Handles Button1.Click
RichTextBox1.SelectionStart = RichTextBox1.Find("are")
'using the Find method to find the text "are" and setting it's
'return property to SelectionStart which selects the text to format
Dim ifont As New Font(RichTextBox1.Font, FontStyle.Italic)
'creating a new font object to set the font style
RichTextBox1.SelectionFont = ifont
'assigning the value selected from the RichTextBox the font style
RichTextBox1.SelectionStart = RichTextBox1.Find("working")
Dim bfont As New Font(RichTextBox1.Font, FontStyle.Bold)
RichTextBox1.SelectionFont = bfont
End Sub

Code for Setting the Color of Text

Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As _


System.EventArgs) Handles Button1.Click
RichTextBox1.SelectionStart = RichTextBox1.Find("are")
'using the Find method to find the text "are" and setting it's return
'property to SelectionStart which selects the text 
RichTextBox1.SelectionColor = Color.Blue
'setting the color for the selected text with SelectionColor property
RichTextBox1.SelectionStart = RichTextBox1.Find("working")
RichTextBox1.SelectionColor = Color.Yellow
End Sub
The output when the Button is Clicked is the text "are" being displayed in Blue and the text
"working" in yellow as shown in the image below.
Code for Saving Files to RTF

Drag two RichTextBoxes and two Buttons (Save, Load) onto the form. When you enter some
text in RichTextBox1 and click on Save button, the text from RichTextBox1 is saved into a
rtf (rich text format) file. When you click on Load button the text from the rtf file is displayed
into RichTextBox2. The code for that looks like this:

Private Sub Save_Click(ByVal sender As System.Object, ByVal e As_


System.EventArgs) Handles Save.Click
RichTextBox1.SaveFile("hello.rtf")
'using SaveFile method to save text in a rich text box to hard disk
End Sub

Private Sub Load_Click(ByVal sender As System.Object, ByVal e As_


System.EventArgs) Handles Load.Click
RichTextBox2.LoadFile("hello.rtf")
'using LoadFile method to read the saved file
End Sub

Q6. Create a window based application in VB.Net with a button. Display a


message box whenever the button is being clicked and count the number of
clicks user have done. Place a exit button to close the application and
display the number times user have clicked the button?
Ans)

Public Class Form1

Dim intBtnClkCount As Integer = 0


Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles Button1.Click

intBtnClkCount += 1

MessageBox.Show("Button1 has been clicked" & intBtnClkCount.ToString()


& " times.")
End Sub
End Class

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