vp programns frm 31 (pending 27, 31, 35, 40)

Upload: vijay-sah

Post on 05-Apr-2018

213 views

Category:

Documents


0 download

TRANSCRIPT

  • 8/2/2019 VP Programns Frm 31 (Pending 27, 31, 35, 40)

    1/23

    57Q32) write a program to design the search browser by using text box ,drive list box, directory list box and file list box?Answer:-

  • 8/2/2019 VP Programns Frm 31 (Pending 27, 31, 35, 40)

    2/23

    58

  • 8/2/2019 VP Programns Frm 31 (Pending 27, 31, 35, 40)

    3/23

    59Q33) Write a program to design the stopwatch by using timer control?Answer:-

    Private Sub Command1_Click()Timer1.Enabled = TrueEnd Sub

    Private Sub Command2_Click()Timer1.Enabled = FalseLabel2.Caption = ""End Sub

    Private Sub Form_Load()

    Timer1.Enabled = FalseEnd Sub

    Private Sub Timer1_Timer()Label2.Caption = Format(Val(Label2.Caption) + 0.01, "fixed")If Label2.Caption = "60.00" ThenLabel2.Caption = lblTimeMins + 1Label2.Caption = "00:00"End IfEnd Sub

  • 8/2/2019 VP Programns Frm 31 (Pending 27, 31, 35, 40)

    4/23

    60Q34) Write a program to swap an image by using timer?Answer:-

    Private Sub Timer1_Timer()Timer1.Enabled = TrueLabel2.Caption = Time$Command1.Picture = Image1.PictureImage1.Picture = Image2.PictureImage2.Picture = Command1.PictureEnd Sub

  • 8/2/2019 VP Programns Frm 31 (Pending 27, 31, 35, 40)

    5/23

    61

    Q35) Design an app. in VB which makes use of the following controls::

    Image List, Toolbars & Progress bar & Status Bar.

    Answer:-

    Private Sub Command1_Click()StatusBar1.Panels(1).Text = "Hello."StatusBar1.Panels(2).Text = "Kamal"StatusBar1.Panels(3).Text = "Lal"StatusBar1.Panels(4).Text = "Sah"End Sub

    Private Sub Form_Load()

    Toolbar1.ImageList = ImageList1End Sub

    Private Sub Timer1_Timer()ProgressBar1.Value = 100End Sub

  • 8/2/2019 VP Programns Frm 31 (Pending 27, 31, 35, 40)

    6/23

    62Private Sub Toolbar1_ButtonClick(ByVal Button As MSComctlLib.Button)If Button.Index = 1 ThenLoad Form2Form2.ShowEnd IfIf Button.Index = 2 ThenLabel1.Caption = "size of text is" & Text1.Font.SizeEnd IfEnd Sub

    Q36) A project to imitate a mini notepad using richtext box.

    Make use of showopen, showsave, showcolor & showfont dialog

    boxes in your notepad.Also set current values of the dialog box.

    Answer:-

  • 8/2/2019 VP Programns Frm 31 (Pending 27, 31, 35, 40)

    7/23

    63

    Code:-

    Private Sub exit_Click()On Error GoTo cancelIf (Form1.Caption = "Untitled") Thena = MsgBox("Do You Want Save", 35, "Save")If (a = 6) ThenCommonDialog1.DialogTitle = "Save Files"CommonDialog1.Filter = "Text Files(*.txt,*.doc)|*.txt;*.doc|All files(*.*)|*.*"CommonDialog1.ShowSave

    CommonDialog1.DefaultExt = "*.txt"RichTextBox1.SaveFile (CommonDialog1.FileName)Form1.Caption = CommonDialog1.FileNameElseEndEnd If

    ElseEnd

    End If

    cancel:End Sub

    Private Sub font_Click()CommonDialog1.Flags = &H2 Or &H100CommonDialog1.ShowFont

  • 8/2/2019 VP Programns Frm 31 (Pending 27, 31, 35, 40)

    8/23

    64If ((RichTextBox1.SelLength = Len(RichTextBox1.Text)) > 0) ThenRichTextBox1.SelFontName = CommonDialog1.FontNameRichTextBox1.SelFontSize = CommonDialog1.FontSizeRichTextBox1.SelBold = CommonDialog1.FontBoldRichTextBox1.SelItalic = CommonDialog1.FontItalicRichTextBox1.SelUnderline = CommonDialog1.FontUnderlineRichTextBox1.SelStrikeThru = CommonDialog1.FontStrikethruRichTextBox1.SelColor = CommonDialog1.ColorElseRichTextBox1.find (RichTextBox1.Text)RichTextBox1.SelFontName = CommonDialog1.FontNameRichTextBox1.SelFontSize = CommonDialog1.FontSizeRichTextBox1.SelBold = CommonDialog1.FontBoldRichTextBox1.SelItalic = CommonDialog1.FontItalic

    RichTextBox1.SelUnderline = CommonDialog1.FontUnderlineRichTextBox1.SelStrikeThru = CommonDialog1.FontStrikethruRichTextBox1.SelColor = CommonDialog1.ColorEnd IfEnd Sub

    Private Sub Form_Load()Form1.Caption = "Untitled"End Sub

    Private Sub new_Click()Form1.Caption = "Untitled"RichTextBox1.Text = ""End Sub

    Private Sub open_Click()On Error GoTo cancelCommonDialog1.DialogTitle = "OPEN Files"CommonDialog1.InitDir = "E:\"

    CommonDialog1.Filter = "Text files(*.txt,*.doc)|*.txt;*.doc|All files(*.*)|*.*"CommonDialog1.ShowOpenRichTextBox1.LoadFile (CommonDialog1.FileName)Form1.Caption = CommonDialog1.FileNamecancel:End Sub

  • 8/2/2019 VP Programns Frm 31 (Pending 27, 31, 35, 40)

    9/23

    65Private Sub save_Click()On Error GoTo cancelCommonDialog1.DialogTitle = "Save Files"CommonDialog1.Filter = "Text Files(*.txt,*.doc)|*.txt;*.doc|All files(*.*)|*.*"CommonDialog1.ShowSaveCommonDialog1.DefaultExt = "*.txt"RichTextBox1.SaveFile (CommonDialog1.FileName)Form1.Caption = CommonDialog1.FileNamecancel:End Sub

    Private Sub saveas_Click()On Error GoTo cancelCommonDialog1.DialogTitle = "Save As Files"

    CommonDialog1.Filter = "Text Files(*.txt,*.doc)|*.txt;*.doc|All files(*.*)|*.*"CommonDialog1.ShowSaveCommonDialog1.DefaultExt = "*.txt"RichTextBox1.SaveFile (CommonDialog1.FileName)Form1.Caption = CommonDialog1.FileNamecancel:End Sub

    Q37) Simulate a Traffic Light System using various controls from your

    tool Box.

    Answer:-

    Private Sub Command1_Click()EndEnd Sub

    Private Sub Timer1_Timer()Timer1.Enabled = True

    Label5.Caption = Time$start = 0nd = 5If (start = 0 And nd = 5) ThenFor j = start To ndShape1.FillStyle = 0Shape1.FillColor = vbRed

  • 8/2/2019 VP Programns Frm 31 (Pending 27, 31, 35, 40)

    10/23

    66Shape2.FillStyle = 1Shape3.FillStyle = 1Next jstart = 5nd = 10End IfIf (start = 5 And nd = 10) ThenFor j = start To ndShape2.FillStyle = 0Shape2.FillColor = vbYellowShape1.FillStyle = 1Shape3.FillStyle = 1Next jstart = 10

    nd = 15End If

    If (start = 10 And nd = 15) ThenFor j = start To ndShape3.FillStyle = 0Shape3.FillColor = vbGreenShape2.FillStyle = 1Shape1.FillStyle = 1Next jstart = 0nd = 5End If

    End Sub

  • 8/2/2019 VP Programns Frm 31 (Pending 27, 31, 35, 40)

    11/23

    67

    Q38) Design a project for a MDI application, such that child1 contains

    no menu and child2 contains menu. With this demonstrate working of an

    MDI form?

    Answer:-Private Sub mnuformchild_Click()MDIForm1.Hide

    Form1.ShowEnd Sub

    Private Sub mnuformdiff_Click()MDIForm1.HideForm2.ShowEnd Sub

  • 8/2/2019 VP Programns Frm 31 (Pending 27, 31, 35, 40)

    12/23

    68

  • 8/2/2019 VP Programns Frm 31 (Pending 27, 31, 35, 40)

    13/23

    6939) Write a program, using recursive function to generate Fibonacci

    Series.

    Answer:-

    Private Sub Command1_Click()Dim n As Integern = Val(Text1.Text)a = Fib(n)End Sub

    Public Function Fib(num As Integer) As IntegerLabel3.Caption = "0" & " , " & "1" & " , " & "1"If num

  • 8/2/2019 VP Programns Frm 31 (Pending 27, 31, 35, 40)

    14/23

    70

    Q40) Write a program, using recursive function to calculate Power of a

    number.

    Answer:-

    Private Sub Command1_Click()Dim n As Integer

    Dim p As IntegerDim x As Integern = Text1.Textp = Text2.Textx = power(n, p)Label4.Caption = "Answer is:" & xEnd SubPublic Function power(num As Integer, pow As Integer) As IntegerIf pow = 2 Then

    power = num * numElse

    power = num * power(num, pow - 1)End IfEnd Function

    Private Sub Command2_Click()

  • 8/2/2019 VP Programns Frm 31 (Pending 27, 31, 35, 40)

    15/23

    71If MsgBox("Are you sure you want to exit ?", vbYesNo) = vbYes ThenEndEnd IfEnd Sub

  • 8/2/2019 VP Programns Frm 31 (Pending 27, 31, 35, 40)

    16/23

    72Q41) Create a project for Reading & Refreshment that calculates theamount due for individual orders and maintains accumulated totals for asummary. Have a textbox for Quantity ,checkbox for Takeout items,

    which are taxable(5 percent);all other orders are nontaxable.Include

    option buttons for the five coffee selections - Cappuccino, Espresso,Latte, Iced Cappuccino and Iced Latte. The prices for each will be

    assigned using these Constants:

    Cappuccino 20.00

    Espresso 22.00

    Latte 18.00

    Iced(either) 25.00

    Use a command button for Calculate Selection , which will calculate and

    display the amount due for each item. A command button for Clear forNext Item will clear the selections and amount for the single item.

    Additional labels in a separate frame will maintain the summary

    information for the current order to include subtotal, tax and total due.

    Buttons at the bottom of the form will be used for New Order, Summary

    and Exit. The New Order button will clear the bill for the current

    customer and add to the totals for the summary. The button for

    Summary should display the average sale amount per customer and the

    number of customers in a message box.

    Answer:-

  • 8/2/2019 VP Programns Frm 31 (Pending 27, 31, 35, 40)

    17/23

    73

  • 8/2/2019 VP Programns Frm 31 (Pending 27, 31, 35, 40)

    18/23

    74

    Q42) Create a project that will be used to determine the total amount

    due for the Purchase of a vehicle. You will need textboxes for the sales

  • 8/2/2019 VP Programns Frm 31 (Pending 27, 31, 35, 40)

    19/23

    75price and the trade- In allowance. Check boxes will indicate if the buyerwants additional accessories: stereo system, leather interior & computernavigation. A frame for the exterior finish will contain option buttons for

    Standard, Pearlized or Customized detailing. The prices for each will be

    assigned using these Constants:

    ITEM PRICE

    Stereo System 425

    Leather Interior 987

    Computer Navigation 1741

    Standard No additional

    Charge

    Pearlized 345

    Customized Detailing 599Tax Rate 7%

    Have the trade-in-allowance default to o; that is, if the user does not

    enter a trade-in value, use zero in your calculation. Validate the values

    from the text boxes, displaying a message box if necessary.

    To calculate, add the price of selected accessories and finish to the sales

    price, calculate the sales tax and display the result in a subtotal label.

    Then subtract any trade-in value from the total and display the result in

    an Amount due label.

    Include command buttons for Calculate, Clear & Exit. The Calculate

    button must display the total amount due after trade-in.

    Answer:-

    Private Sub Check1_Click()If Check1.Value = 1 Thenss = 425

    End IfEnd Sub

    Private Sub Check2_Click()If Check2.Value = 1 Thenli = 987End If

  • 8/2/2019 VP Programns Frm 31 (Pending 27, 31, 35, 40)

    20/23

    76End SubPrivate Sub Check3_Click()If Check3.Value = 1 Thencn = 1741End IfEnd Sub

    Private Sub Command1_Click()sp = Text1.Textta = Text2.TextIf Text1.Text = "" ThenMsgBox "enter sales price"Exit Sub

    End IfIf Text2.Text = "" ThenMsgBox "enter trade allowance price"Exit SubEnd Ifsb = spIf Check1.Value = 1 Thensb = ss + sbEnd IfIf Check2.Value = 1 Thensb = li + sbEnd IfIf Check3.Value = 1 Thensb = cn + sbEnd IfIf Option1.Value = True Thensb = sb + stEnd IfIf Option2.Value = True Then

    sb = sb + prEnd IfIf Option3.Value = True Thensb = sb + cdEnd IfLabel3.Caption = "subtotal=" & sbtax = ((sb * 7) / 100)

  • 8/2/2019 VP Programns Frm 31 (Pending 27, 31, 35, 40)

    21/23

    77Label4.Caption = "sales tax=" & taxamt = sb - ta - taxLabel5.Caption = amtEnd Sub

    Private Sub Command2_Click()Text1.Text = ""Text2.Text = ""Label3.Caption = ""Label4.Caption = ""Label5.Caption = ""End Sub

    Private Sub Command3_Click()

    EndEnd Sub

    Private Sub Option1_Click()If Option1.Value = True Thenst = 0End IfEnd Sub

    Private Sub Option2_Click()If Option2.Value = True Thenpr = 345End IfEnd Sub

    Private Sub Option3_Click()If Option3.Value = True Thencd = 599End If

    End Sub

  • 8/2/2019 VP Programns Frm 31 (Pending 27, 31, 35, 40)

    22/23

    78

    Q 43) Creating a tree view while Node1 is a parent node of Node2 and

    Node2 is a parent Node of Node3.

    Node1

    Node2

    Node3

    Answer:-

    Private Sub Form_Load()Dim node1 As NodeDim node2 As NodeDim node3 As Node

    Set node1 = TreeView1.Nodes.AddTreeView1.Nodes(1).Text = "NODE1"TreeView1.Nodes(1).Key = "NODE1"TreeView1.Nodes(1).Image = "blu"

    Set node2 = TreeView1.Nodes.Add("NODE1", tvwChild, "NODE2")TreeView1.Nodes(2).Text = "NODE2"

  • 8/2/2019 VP Programns Frm 31 (Pending 27, 31, 35, 40)

    23/23

    79TreeView1.Nodes(2).Key = "NODE2"TreeView1.Nodes(2).Image = "sun"Set node3 = TreeView1.Nodes.Add("NODE2", tvwChild, "NODE3")TreeView1.Nodes(3).Text = "NODE3"TreeView1.Nodes(3).Key = "NODE3"TreeView1.Nodes(3).Image = "ped"End Sub