advancedvisualbasiclab.pdf

Upload: velsakthi3152

Post on 14-Apr-2018

213 views

Category:

Documents


0 download

TRANSCRIPT

  • 7/27/2019 AdvancedVisualBasicLab.pdf

    1/243

    Lab Excercises and Solutions

    Centre for Information Technology and Engineering, Manonmaniam Sundarnar University1

    MS1.4 Advanced Visual Basic

    LAB EXERCISES AND SOLUTIONS

    Ex1 - TextBoxDemo

    Create a standard exe

    Open a new form and change the name of the form as example & change the caption as

    TextBoxDemo

    Paste one text box

    Paste three command buttons and change the captions of

    Command1 as Clear Text

    Command2 as Insert Date

    Command3 as Show Message

    The form will look like

    Opt i on Expl i ci t

    Pr i vat e Sub Command1_Cl i ck( )

    Text 1. Text = ""

    End Sub

    Pr i vat e Sub Command2_Cl i ck( )

    Text 1. Text = Dat eEnd Sub

    Pr i vat e Sub Command3_Cl i ck( )

    Text 1. Text = "Wel come t o Vi sual Basi c 5. 0"

    End Sub

    Run the program

  • 7/27/2019 AdvancedVisualBasicLab.pdf

    2/243

    Advanced Visual Basic

    Centre for Information Technology and Engineering, Manonmaniam Sundarnar University2

    Ex2 - LabelBoxDemo

    create a standard exe

    Paste 3 forms

    In the form1 change the caption as form loader

    In form1 paste two command buttons

    And change the caption of command1 as show form2 & command2 as show form3

    Paste two label box and change the caption of label1 as Initializing and label2 as please wait (open

    the property window of the label boxes and change the font property and font size property and

    height,width of the label boxes)

    The first form will look like

  • 7/27/2019 AdvancedVisualBasicLab.pdf

    3/243

    Lab Excercises and Solutions

    Centre for Information Technology and Engineering, Manonmaniam Sundarnar University3

    In form 2 paste a label box and change the caption as form2

    Change the font type and font size in the property window

    The second form will look like

    o open the third form and past one label boxo change the caption of the label box as FORM3o change the font size and font type in the property window of the label box.Now the third form will look like

  • 7/27/2019 AdvancedVisualBasicLab.pdf

    4/243

    Advanced Visual Basic

    Centre for Information Technology and Engineering, Manonmaniam Sundarnar University4

    Write the following code in form1s corresponding controls event.

    Opt i on Expl i ci t

    Pr i vat e Sub Command1_Cl i ck( )

    For m2. Show

    End Sub

    Pr i vat e Sub Command2_Cl i ck( )

    For m3. Show

    End Sub

    Pr i vate Sub Form_Load( )

    For m1. Show

    Form1. MousePoi nter = vbHour gl ass

    DoEvent s

    For m1. Capt i on = "Loadi ng For m2. . . "

    Load For m2

    For m1. Capt i on = "Loadi ng For m3. . . "

    Load For m3

    For m1. Capt i on = "For m Loader "

    Command1. Vi si bl e = True

    Command2. Vi si bl e = True

    Label 1. Capt i on = "Appl i cat i on Loaded"

    Label 2. Capt i on = "Cl i ck on t he but t ons t o l oad a Form"

    Form1. MousePoi nter = vbDef aul t

    DoEvent s

    End Sub

    Write the following code in form2

    Pr i vate Sub Form_Load( )

    Di m LTi me

    LTi me = Ti mer

    Whi l e Ti mer - LTi me < 5

    Wend

    End Sub

    Wr i t e the f ol l owi ng code i n f orm3

    Pr i vate Sub Form_Load( )

    Di m LTi me

    LTi me = Ti mer

    Whi l e Ti mer - LTi me < 5

    Wend

    End Sub

    Run the program

  • 7/27/2019 AdvancedVisualBasicLab.pdf

    5/243

    Lab Excercises and Solutions

    Centre for Information Technology and Engineering, Manonmaniam Sundarnar University5

    Ex3 - Timer Program

    o Open a new standard EXE project

    o Design your form as shown below

    o Current Time should be displayed on the Text1

    o Current Date should be displayed on the Text2

    o Change the Caption properties of the Form to Timer Program

    o Right Click the Timer control, click Properties

  • 7/27/2019 AdvancedVisualBasicLab.pdf

    6/243

    Advanced Visual Basic

    Centre for Information Technology and Engineering, Manonmaniam Sundarnar University6

    o Set the Interval property of the Timer Control to 1000 which implies that the Timer is activated

    every one second

    Ent er t he code i n the Form_Load( ) procedure.

    Pr i vate Sub Form_Load( )

    Text 1. Text = Ti me$Text 2. Text = Dat e$

    End Sub

    Pri vat e Sub Ti mer1_Ti mer( )

    Text 1. Text = Ti me$

    End Sub

    Execut e the Progr am

    Ex4 - Application with Command Button

    o Open a standard EXE project with four text boxes, two command button, with two lable boxes

    o In the Text1 Box enter a date

    o In the Text3 Box enter a text

    o If you click the Command Button1, Day of the Date should be displayed in the Text2 Box

    o If you click the Command Button2, UpperCase of the text should be displayed in the Text4 Box

    o Desi gn your f orm as shown bel ow

    Pr i vat e Sub Command1_Cl i ck( )

    Di m MYDATE As Dat e

  • 7/27/2019 AdvancedVisualBasicLab.pdf

    7/243

    Lab Excercises and Solutions

    Centre for Information Technology and Engineering, Manonmaniam Sundarnar University7

    MYDATE = For mat ( Text 1. Text , "D- MMM- YY")

    Text 3. Text = For mat ( MYDATE, "dddd")

    End Sub

    Pr i vat e Sub Command2_Cl i ck( )

    Text 4. Text = For mat ( Text 2. Text , ">")End Sub

    Execute the program

    Ex 5 : List Box Controls

    1. Open a new standard EXE project.

    2. Paste one combo box, one list box, one label box , two command button and write the following

    code in the corresponding controls.

    3. If we Click Command1, the item is entered in the inputbox and added to the List1.

    4. If we Click Command2, the selected item of the listbox will be removed.

    5. Design your form as shown below.

  • 7/27/2019 AdvancedVisualBasicLab.pdf

    8/243

    Advanced Visual Basic

    Centre for Information Technology and Engineering, Manonmaniam Sundarnar University8

    When we select the item in the List1, that item will be added in the Combo1 & displayed in the Text1.

    Pr i vat e Sub Command1_Cl i ck( )

    Di m a As St r i ng

    a = I nputBox( "Ent er t he name")

    Li st1. AddI t em aEnd Sub

    Pr i vat e Sub Command2_Cl i ck( )

    Di m a As I nt eger

    a = Li st1. Li stI ndex

    Combo1. AddI t em ( Li st 1. Li st ( a) )

    Text 1. t ext = l i st 1. l i st ( a)

    Li st 1. RemoveI t em( a)

    End Sub

    Pr i vat e Sub Li st1_Cl i ck( )

    Text 1. Text = Li st 1. Sel Count

    End Sub

    3. Run the program by pressing

    Ex6 - Calculator Program

    o Open a new Standard EXE project

    o Paste 5 command buttons and create one control array for 0 to 9 numbers, another control array for

    four operators, one for decimal point, one for cancel, one for cancel entry.

    o Design your form as shown below and perform a Calculator Project, which can able to work as like

    as Windows Calculator Use Control Arrays)

  • 7/27/2019 AdvancedVisualBasicLab.pdf

    9/243

    Lab Excercises and Solutions

    Centre for Information Technology and Engineering, Manonmaniam Sundarnar University9

    o Write the following code in the corresponding control events.

    Opt i on Expl i ci t

    Di m Op1, Op2Di m Deci mal Fl ag As I nt eger

    Di m NumOps As I nteger

    Di m Last I nput

    Di m OpFl ag

    Di m TempReadout

    Pri vat e Sub Cancel _Cl i ck()

    Readout = For mat ( 0, "0. ")

    Op1 = 0

    Op2 = 0

    For m_Load

    End Sub

    Pri vat e Sub Cancel Ent r y_Cl i ck()Readout = For mat ( 0, "0. ")

    Deci mal Fl ag = Fal se

    Last I nput = "CE"

    End Sub

    Pri vat e Sub Deci mal _Cl i ck()

    I f Last I nput = "NEG" Then

    Readout = Format ( 0, " - 0. " )

    El seI f Last I nput "NUMS" Then

    Readout = Format ( 0, "0. " )

    End I f

    Deci mal Fl ag = Tr ue

    Last I nput = "NUMS"

    End Sub

    Pr i vate Sub Form_Load( )

    Deci mal Fl ag = Fal se

    NumOps = 0

    Last I nput = "NONE"

    OpFl ag = " "

    Readout = For mat ( 0, "0. ")

    End Sub

  • 7/27/2019 AdvancedVisualBasicLab.pdf

    10/243

    Advanced Visual Basic

    Centre for Information Technology and Engineering, Manonmaniam Sundarnar University10

    Pri vat e Sub Number_Cl i ck( I ndex As I nteger)

    I f Last I nput "NUMS" Then

    Readout = Format ( 0, " . " )

    Deci mal Fl ag = Fal se

    End I f

    I f Deci mal Fl ag ThenReadout = Readout + Number( I ndex) . Capt i on

    El se

    Readout = Lef t ( Readout , I nSt r ( Readout , For mat ( 0, ". ") ) - 1) +

    Number( I ndex) . Capt i on + For mat( 0, " . ")

    End I f

    I f Last I nput = "NEG" Then Readout = " - " & Readout

    Last I nput = "NUMS"

    End Sub

    Pri vat e Sub Operator _Cl i ck(I ndex As I nt eger )

    TempReadout = Readout

    I f Last I nput = "NUMS" Then

    NumOps = NumOps + 1End I f

    Sel ect Case NumOps

    Case 0

    I f Oper ator( I ndex) . Capt i on = " - " And Last I nput "NEG" Then

    Readout = " - " & Readout

    Last I nput = "NEG"

    End I f

    Case 1

    Op1 = Readou

    I f Oper at or ( I ndex) . Capt i on = " - " And Last I nput "NUMS" And OpFl ag "="

    Then

    Readout = " - "Last I nput = "NEG"

    End I f

    Case 2

    Op2 = TempReadout

    Sel ect Case OpFl ag

    Case " +"

    Op1 = CDbl ( Op1) + CDbl ( Op2)

    Case " - "

    Op1 = CDbl ( Op1) - CDbl ( Op2)

    Case " X"

    Op1 = CDbl ( Op1) * CDbl ( Op2)

    Case " / "

    I f Op2 = 0 ThenMsgBox "Can' t di vi de by zer o", 48, "Cal cul ator"

    El se

    Op1 = CDbl ( Op1) / CDbl ( Op2)

    End I f

    Case " ="

    Op1 = CDbl ( Op2)

    Case " %"

    Op1 = CDbl ( Op1) * CDbl ( Op2)

  • 7/27/2019 AdvancedVisualBasicLab.pdf

    11/243

    Lab Excercises and Solutions

    Centre for Information Technology and Engineering, Manonmaniam Sundarnar University11

    End Sel ect

    Readout = Op1

    NumOps = 1

    End Sel ect

    I f Last I nput "NEG" ThenLast I nput = "OPS"

    OpFl ag = Operator ( I ndex) . Capt i on

    End I f

    End Sub

    Pr i vat e Sub Per cent _Cl i ck( )

    Readout = Readout / 100

    Last I nput = "Ops"

    OpFl ag = "%"

    NumOps = NumOps + 1

    Deci mal Fl ag = Tr ue

    End Sub

    Run the Program by press F5.

    Ex7 - String Operations Program

    1. Create a new standard EXE project.

    2. Design your form as shown below.

  • 7/27/2019 AdvancedVisualBasicLab.pdf

    12/243

    Advanced Visual Basic

    Centre for Information Technology and Engineering, Manonmaniam Sundarnar University12

    3. We have to Create CSting Class, follow this Steps.

    4. In the Menu Project->Add Class Module in the Form1

    5. We write the code in the Class Module (NumStr.cls)

    Pr i vat e Bi naryDi gi t s(16) As Str i ng

    Pr i vat e NDi gi t s( 20) As St r i ngPri vat e NTens( 10) As Str i ng

    Pri vat e Sub Cl ass_I ni t i al i ze()

    Bi naryDi gi t s( 0) = "0000"

    Bi naryDi gi t s( 1) = "0001"

    Bi naryDi gi t s( 2) = "0010"

    Bi naryDi gi t s( 3) = "0011"

    Bi naryDi gi t s( 4) = "0100"

    Bi naryDi gi t s( 5) = "0101"

    Bi naryDi gi t s( 6) = "0110"

    Bi naryDi gi t s( 7) = "0111"

    Bi naryDi gi t s( 8) = "1000"

    Bi naryDi gi t s( 9) = "1001"Bi naryDi gi t s( 10) = "1010"

    Bi naryDi gi t s( 11) = "1011"

    Bi naryDi gi t s( 12) = "1100"

    Bi naryDi gi t s( 13) = "1101"

    Bi naryDi gi t s( 14) = "1110"

    Bi naryDi gi t s( 15) = "1111"

    NDi gi t s( 1) = "one"

    NDi gi t s( 2) = " t wo"

    NDi gi t s( 3) = "t hr ee"

    NDi gi t s( 4) = "f our "

    NDi gi t s( 5) = "f i ve"

    NDi gi t s( 6) = "si x"

    NDi gi t s( 7) = "seven"NDi gi t s( 8) = "ei ght "

    NDi gi t s( 9) = "ni ne"

    NDi gi t s(10) = "t en"

    NDi gi t s( 11) = "el even"

    NDi gi t s( 12) = "t wel ve"

    NDi gi t s(13) = "t hi rt een"

    NDi gi t s( 14) = "f our t een"

    NDi gi t s(15) = "f i f teen"

    NDi gi t s(16) = "si xteen"

    NDi gi t s( 17) = "sevent een"

    NDi gi t s( 18) = "ei ght een"

    NDi gi t s( 19) = "ni net een"

    NTens(2) = "t went y"

    NTens(3) = "t hi rt y"

    NTens( 4) = "f or t y"

    NTens(5) = "f i f ty"

    NTens( 6) = "si xty"

    NTens(7) = "sevent y"

    NTens( 8) = "ei ght y"

    NTens( 9) = "ni net y"

  • 7/27/2019 AdvancedVisualBasicLab.pdf

    13/243

    Lab Excercises and Solutions

    Centre for Information Technology and Engineering, Manonmaniam Sundarnar University13

    End Sub

    Pri vat e Funct i on ReadSi ngl e(Number ) As Str i ng

    I f Number > 0 And Number < 20 Then

    ReadSi ngl e = NDi gi t s( Number )

    El seReadSi ngl e = "** ** *"

    End I f

    End Funct i on

    Pr i vate Funct i on ReadTent hs( Number )

    t number = I nt( Number / 10)

    I f t number > 1 And tnumber < 10 Then

    ReadTenths = NTens( t number )

    El se

    ReadTent hs = "** ** *"

    End I f

    End Funct i on

    Publ i c Funct i on Number 2St r i ng( Number )Di m t ent h As Long

    Di m l ef t over As Long

    Di m hundr ed As Long

    Di m t housand As Long

    I f Number < 20 Then

    NumStr i ng = ReadSi ngl e( Number)

    El seI f Number < 100 Then

    t ent h = Fi x( Number / 10)

    NumStr i ng = ReadTent hs( t ent h * 10)

    l ef t over = Number - ( t ent h * 10)

    I f l ef t over > 0 Then

    NumStr i ng = NumStr i ng & " " & ReadSi ngl e( l ef t over)

    End I f

    El seI f Number < 1000 Then

    hundred = Fi x( Number / 100)

    NumStr i ng = ReadSi ngl e(hundr ed) & " hundr ed"

    l ef t over = Number - ( hundr ed * 100)

    I f l ef t over > 0 Then

    tenth = Fi x( l ef tover / 10)

    I f t enth >0 Then NumStr i ng = NumStr i ng & " " & ReadTent hs( t enth * 10)

    l ef t over = Number - ( hundr ed * 100) - ( t ent h * 10)

    I f l ef tover > 0 Then

    NumStr i ng = NumStr i ng & " " & ReadSi ngl e( l ef t over )

    End I fEnd I f

    El se

    t housand = Fi x( Number / 1000)

    NumStr i ng = ReadSi ngl e( t housand) & " t housand"

    l ef t over = Number - ( t housand * 1000)

    I f l ef t over > 0 Then

    hundr ed = Fi x( l ef t over / 100)

  • 7/27/2019 AdvancedVisualBasicLab.pdf

    14/243

    Advanced Visual Basic

    Centre for Information Technology and Engineering, Manonmaniam Sundarnar University14

    I f hundred > 0 Then

    NumSt r i ng = NumSt r i ng & " " & ReadSi ngl e( hundred) & " hundred"

    End I f

    l ef t over = Number - ( t housand * 1000) - ( hundr ed * 100)

    I f l ef tover > 0 Thent ent h = Fi x(l ef t over / 10)

    I f t ent h > 0 Then

    NumSt r i ng = NumSt r i ng & " " & ReadTent hs( t ent h * 10)

    End I f

    l ef t over =Number - ( t housand*1000) - ( hundr ed * 100) - ( t ent h * 10)

    I f l ef t over > 0 Then

    NumStr i ng = NumStr i ng & " " & ReadSi ngl e( l ef t over )

    End I f

    End I f

    End I f

    End I f

    Number 2St r i ng = NumSt r i ng

    End Funct i on

    Publ i c Funct i on LowerCaps( st r As St r i ng) As St r i ng

    Di m newWord As St r i ng, newStr As St r i ng

    Di m t empSt r As Str i ng

    Di m WDel i mi t er As I nteger

    t empSt r = Tri m( st r )

    WDel i mi t er = I nSt r ( t empSt r , " " )

    Whi l e WDel i mi t er > 0

    newWord = Lef t ( t empSt r , WDel i mi t er )

    t empSt r = Ri ght ( t empSt r , Len( t empSt r ) - WDel i mi t er)

    newSt r = newSt r & UCase( Lef t ( newWor d, 1) ) & Mi d( newWor d, 2, Len(newWord)

    - 1) WDel i mi t er = I nSt r ( t empSt r , " ")

    Wend

    newWor d = t empSt r

    newSt r = newSt r & UCase( Lef t ( newWor d, 1) ) & Mi d( newWor d, 2, Len( newWor d)

    - 1)

    Lower Caps = newSt r

    End Funct i on

    Publ i c Funct i on I nteger2Bi nar y( ByVal Number As Long) As St r i ng

    HexNum = Hex( Number )

    For i = 1 To Len( HexNum)

    Bi nNum = Bi nNum & Bi naryDi gi t s( "&H" & Mi d( HexNum, i , 1))

    Next

    I nteger2Bi nar y = Bi nNum

    End Funct i on

    6. We have to create the Instance of Class Module .

    Di m NS As New NumStr i ngs. St r i ngCl ass

    7. When we select the CmdString Button, the value of Text1 is converted to the String in the Text2.

  • 7/27/2019 AdvancedVisualBasicLab.pdf

    15/243

    Lab Excercises and Solutions

    Centre for Information Technology and Engineering, Manonmaniam Sundarnar University15

    Pri vat e Sub Cmdst r i ng_Cl i ck()

    Text 2. Text = NS. Number2Str i ng(Text 1. Text )

    End Sub

    8. When we select the CmdLcaps Button, the value of Text1 is converted to the Capital of the first

    Word.

    Pri vat e Sub CmdLcaps_Cl i ck( )

    Di m NSt r As St r i ng

    NStr = NS. Number 2St r i ng(Text 1. Text )

    Text 3. Text = NS. Lower Caps( NSt r )

    End Sub

    9. When we select the CmdBinary Button, the value of Text1 is converted to the Binary in the Text2.

    Pri vat e Sub Cmdbi nar y_Cl i ck( )

    Text 4. Text = NS. I nt eger 2Bi nary( Text 1. Text )

    End Sub

    10. Run the Program.

    Ex8 - PicutreBoxDemo

    o Create a standard exe

    o Create a new form

    o Paste two picture box in the form

    o Paste 3 lable box in the first picture box and change caption of

    l abl e1 as Red = 128

    l abl e2 as Gr een =128

    l abl e3 as Bl ue = 128

    o Paste again 3 label box in the second picture box and change caption of

    l abel 4as Red =128

    & l abel 5 as Gr een = 128

    &l abel 6 as Bl ue = 128.

  • 7/27/2019 AdvancedVisualBasicLab.pdf

    16/243

    Advanced Visual Basic

    Centre for Information Technology and Engineering, Manonmaniam Sundarnar University16

    o Paste 3 hrscroll bar and change its value property as 128

    o Paste 3 more labels and change the captions of label 7 as Red component & label8 as GreenComponent & label9 as Blue component

    The form will look like

    Write the following code in corresponding controls event like shown below

    Pri vat e Sub HScrol l 1_Change()

    Label 4. Capt i on = "Red = " & HScrol l 1. Val ue

    Pi ct ur e2. BackCol or = RGB( HScr ol l 1. Val ue, HScr ol l 2. Val ue, HScr ol l 3. Val ue)

    End Sub

    Pr i vat e Sub HScrol l 1_Scrol l ( )

    Label 1. Capt i on = "Red = " & HScrol l 1. Val ue

    Pi ct ur e1. BackCol or = RGB( HScr ol l 1. Val ue, HScr ol l 2. Val ue, HScr ol l 3. Val ue)

    End Sub

    Pri vat e Sub HScrol l 2_Change()

    Label 5. Capt i on = "Gr een = " & HScrol l 2. Val ue

    Pi ct ur e2. BackCol or = RGB( HScr ol l 1. Val ue, HScr ol l 2. Val ue, HScr ol l 3. Val ue)

    End Sub

    Pr i vat e Sub HScrol l 2_Scrol l ( )

    Label 2. Capt i on = "Gr een = " & HScrol l 2. Val ue

    Pi ct ur e1. BackCol or = RGB( HScr ol l 1. Val ue, HScr ol l 2. Val ue, HScr ol l 3. Val ue)End Sub

    Pri vat e Sub HScrol l 3_Change()

    Label 6. Capt i on = "Bl ue = " & HScr ol l 3. Val ue

    Pi ct ur e2. BackCol or = RGB( HScr ol l 1. Val ue, HScr ol l 2. Val ue, HScr ol l 3. Val ue)

    End Sub

    Pr i vat e Sub HScrol l 3_Scrol l ( )

  • 7/27/2019 AdvancedVisualBasicLab.pdf

    17/243

    Lab Excercises and Solutions

    Centre for Information Technology and Engineering, Manonmaniam Sundarnar University17

    Label 3. Capt i on = "Bl ue = " & HScr ol l 3. Val ue

    Pi ct ur e1. BackCol or = RGB( HScr ol l 1. Val ue, HScr ol l 2. Val ue, HScr ol l 3. Val ue)

    End Sub

    Run the above program

    Out put is :

    Ex 9 - Multiple File Selection

    Create a standard exe

    Add a form and change its name as multiple files & change its caption as multiple file selection

    with file open the common dialog box. Paste two label box and change the caption of label 1 as empty & label 2 as selection path

    Paste one common dialog box

    Paste a command button and change its caption as select multiple files

    Paste one list control

    The form will look like

  • 7/27/2019 AdvancedVisualBasicLab.pdf

    18/243

    Advanced Visual Basic

    Centre for Information Technology and Engineering, Manonmaniam Sundarnar University18

    Write the following code in the command buttons click event

    Pr i vat e Sub Command1_Cl i ck( )

    CommonDi al og1. Fl ags = cdl OFNAl l owMul t i sel ect

    Label 1. Capt i on = ""Li st1. Cl ear

    CommonDi al og1. Fi l t er = "Al l Fi l es| *. *"

    CommonDi al og1. ShowOpen

    f i l enames = CommonDi al og1. Fi l eName

    I f Len( f i l enames) = 0 Then

    MsgBox "No f i l es sel ected"

    Exi t Sub

    End I f

    ' Ext r act pat h name:

    ' I F FI LETI TLE I S NOT EMPTY, THEN A SI NGLE FI LE

    ' HAS BEEN SELECTED. DI SPLAY I T AND EXI T

    I f CommonDi al og1. Fi l eTi t l e " " ThenLi st 1. AddI t em CommonDi al og1. Fi l eTi t l e

    Exi t Sub

    End I f

    ' FI LETI TLE I S NOT EMPTY, THEN MANY FI LES WERE SELECTED

    ' AND WE MUST EXTRACT THEM FROM THE FI LENAME PROPERTY

    spPosi t i on = I nSt r( f i l enames, " " )

    pathName = Lef t ( f i l enames, spPosi t i on - 1)

    Label 1. Capt i on = pathName

    f i l enames = Mi d( f i l enames, spPosi t i on + 1)

    ' t hen ext r act each space del i mi t ed f i l e nameI f Len( f i l enames) = 0 Then

    Li st1. AddI t em "No f i l es sel ected"

    Exi t Sub

    El se

    spPosi t i on = I nSt r ( f i l enames, " " )

    Whi l e spPosi t i on > 0

    Li st1. AddI t em Lef t ( f i l enames, spPosi t i on - 1)

    f i l enames = Mi d(f i l enames, spPosi t i on + 1)

    spPosi t i on = I nSt r ( f i l enames, " ")

    Wend

    ' Add t he l ast f i l e' s name t o t he l i st

    ' ( t he l ast f i l e name i sn' t f ol l owed by a space)

    Li st 1. AddI t em f i l enames

    End I f

    End Sub

    Run the above program

    The output is

  • 7/27/2019 AdvancedVisualBasicLab.pdf

    19/243

    Lab Excercises and Solutions

    Centre for Information Technology and Engineering, Manonmaniam Sundarnar University19

  • 7/27/2019 AdvancedVisualBasicLab.pdf

    20/243

    Advanced Visual Basic

    Centre for Information Technology and Engineering, Manonmaniam Sundarnar University20

    Ex 10 - for If statement

    Create a standard exe

    Change the form caption as IF-ELSE-ENDIF- DEMO Paste three text boxes and clear its text property

    Paste two label boxes and change label1 caption as Enter A value & caption of label2 as Enter Bvalue

    Paste a command button and change its caption as ResultThe form will look like

    Write the following code in the command button click event

    Pr i vat e Sub Command1_Cl i ck( )

    I f Val ( Text 1. Text) > Val ( Text2. Text) Then

    Text 3. Text = "THE VALUE OF A I S BI GGEST"

    El se

    Text 3. Text = "THE VALUE OF B I S BI GGEST"

    End I f

    End Sub

  • 7/27/2019 AdvancedVisualBasicLab.pdf

    21/243

    Lab Excercises and Solutions

    Centre for Information Technology and Engineering, Manonmaniam Sundarnar University21

    Run the above program

    The out put is

    Ex 11 - for loop Open Standard exe

    Add a form and change its caption as FOR.. NEXT LOOP - DEMO

    Paste 9 command button

    Change the caption of command1 as FORLOOP1

    Command2 as FORLOOP2

    Command3 as FORLOOP3

    Command4 as FORLOOP4

    Command5 as FORLOOP5

    Command6 as FORLOOP6

    Command7 as FORLOOP7

    Command8 as POLYNDROM

    Command9 as EXIT

    The form will look like

    Write the following code in the command buttons click events

    Pr i vat e Sub COMMAND1_Cl i ck( )

  • 7/27/2019 AdvancedVisualBasicLab.pdf

    22/243

    Advanced Visual Basic

    Centre for Information Technology and Engineering, Manonmaniam Sundarnar University22

    Me. Cl s

    For I = 1 To 10

    Pr i nt I

    Next I

    End Sub

    Pr i vat e Sub Command2_Cl i ck( )

    Me. Cl s

    For I = 1 To 10 St ep 2

    Pr i nt I

    Next I

    End Sub

    Pr i vat e Sub Command3_Cl i ck( )

    Me. Cl s

    For I = 10 To 1 Step - 2

    Pr i nt I

    Next I

    End Sub

    Pr i vat e Sub Command4_Cl i ck( )

    Me. Cl s

    Di m STR As St r i ng

    Di m I As I nt eger

    Di m A, B

    STR = I nputBox( "ENTER A STRI NG")

    A = Len( STR)

    For I = 1 To A St ep 1

    B = Mi d( STR, I , 1)

    Pr i nt B

    Next I

    End Sub

    Pr i vat e Sub Command5_Cl i ck( )Me. Cl s

    Di m STR As St r i ng

    Di m I As I nt eger

    Di m A, B

    STR = I nputBox( "ENTER A STRI NG")

    A = Len( STR)

    For I = A To 1 St ep - 1

    B = Mi d( STR, I , 1)

    Pr i nt B

    Next I

    End Sub

    Pr i vat e Sub Command6_Cl i ck( )

    Me. Cl sDi m STR As St r i ng

    Di m I As I nt eger

    Di m A, B

    STR = I nputBox( "ENTER A STRI NG")

    A = Len( STR)

    Pr i nt "THE GI VEN STRI NG I S - - > " & STR

    For I = 1 To A Step 1

  • 7/27/2019 AdvancedVisualBasicLab.pdf

    23/243

    Lab Excercises and Solutions

    Centre for Information Technology and Engineering, Manonmaniam Sundarnar University23

    B = Mi d( STR, 1, I )

    Pr i nt B

    Next

    End Sub

    Pr i vat e Sub Command7_Cl i ck( )Me. Cl s

    Di m STR As St r i ng

    Di m I As I nt eger

    Di m A, B, C

    STR = I nputBox( "ENTER A STRI NG")

    A = Len( STR)

    Pr i nt "THE GI VEN STRI NG I S - - > " & STR

    For I = 1 To A Step 1

    B = Mi d( STR, 1, I )

    Pr i nt B

    Next

    C = A - 1

    For I = C To 1 Step - 1

    B = Mi d( STR, 1, I )

    Pr i nt B

    Next

    End Sub

    Pr i vat e Sub Command8_Cl i ck( )

    Me. Cl s

    Di m STR As St r i ng

    Di m I , J As I nteger

    Di m A, B, C

    STR = I nputBox( "ENTER A STRI NG")

    A = Len( STR)

    Pr i nt "THE GI VEN STRI NG I S - - > " & STR

    For I = 1 To A

    For J = A To 1 St ep - 1

    I f Mi d( STR, I , 1) = Mi d( STR, J , 1) Then

    Pr i nt "THE GI VEN STRI NG I S PALI NDROME"

    Exi t Sub

    El sePr i nt " THE GI VEN STRI NG I S NOT PALI NDROME"

    Exi t Sub

    End I f

    Next J

    Next I

    End Sub

    Pr i vat e Sub Command9_Cl i ck( )

  • 7/27/2019 AdvancedVisualBasicLab.pdf

    24/243

    Advanced Visual Basic

    Centre for Information Technology and Engineering, Manonmaniam Sundarnar University24

    End

    End Sub

    Run the above program

    Out put for the first forloop1 button is shown below

    Output for the FORLOOP2 button is

    Out put for the FORLOOP3 button is

  • 7/27/2019 AdvancedVisualBasicLab.pdf

    25/243

    Lab Excercises and Solutions

    Centre for Information Technology and Engineering, Manonmaniam Sundarnar University25

    OUTPUT for FORLOOP4 is

    Output for FORLOOP5 is

  • 7/27/2019 AdvancedVisualBasicLab.pdf

    26/243

    Advanced Visual Basic

    Centre for Information Technology and Engineering, Manonmaniam Sundarnar University26

    Output for FORLOOP6 is

  • 7/27/2019 AdvancedVisualBasicLab.pdf

    27/243

    Lab Excercises and Solutions

    Centre for Information Technology and Engineering, Manonmaniam Sundarnar University27

    output for FORLOOP 7 is

    Output for the PALINDROME is

  • 7/27/2019 AdvancedVisualBasicLab.pdf

    28/243

    Advanced Visual Basic

    Centre for Information Technology and Engineering, Manonmaniam Sundarnar University28

    Ex 12 - Select Case

    Create a standard exe

    Change the caption of the form as SELECT_CASE_STATEMENT form

    Add two text boxes and clear its caption property

    Add one label box and change its caption as Enter a number between 1 and 10

    Add one command button and change its caption property as &Print

    The form will look like

  • 7/27/2019 AdvancedVisualBasicLab.pdf

    29/243

    Lab Excercises and Solutions

    Centre for Information Technology and Engineering, Manonmaniam Sundarnar University29

    Write the following code in the corresponding control events.

    Pr i vat e Sub Command1_Cl i ck( )

    Di m NUM

    Text 2. Enabl ed = Tr ueNUM = Val ( Text 1. Text )

    Sel ect Case NUM

    Case 1 To 5

    Text 2. Text = " Bet ween 1 and 5"

    Case 6, 7, 8

    Text 2. Text = " Bet ween 6 and 8"

    Case 9 To 10

    Text 2. Text = " Gr eater t han 8"

    Case El se

    Text 2. Text = " Not between 1 and 10"

    End Sel ect

    End SubPr i vate Sub Form_Load( )

    Command1. Enabl ed = Fal se

    Text 2. Enabl ed = Fal se

    End Sub

    Pr i vat e Sub Text1_CHANGE( )

    Command1. Enabl ed = True

    End Sub

    Run the program

    Out put is

  • 7/27/2019 AdvancedVisualBasicLab.pdf

    30/243

    Advanced Visual Basic

    Centre for Information Technology and Engineering, Manonmaniam Sundarnar University30

    Ex 13 Switch statement using function

    Create a standard exe

    add a form

    Paste two label boxes in the form and change label1 caption as City name & label2 caption as

    Language

    Add one list box and its property window input the city name Landon, Rome, Paris one by one in

    the list property.

    Add one text box and clear its caption

    Add one command button and change its caption as &Print

    The form will look like

    z Choose the TOOL menu bar z Select Add Procedure optionz The following window will be displayed z Give the function name as MATCH

  • 7/27/2019 AdvancedVisualBasicLab.pdf

    31/243

    Lab Excercises and Solutions

    Centre for Information Technology and Engineering, Manonmaniam Sundarnar University31

    Click ok button

    In the code window write the following codePubl i c Funct i on MATCH( CI TYNAME As St r i ng)MATCH = Swi t ch(CI TYNAME = "London", "Engl i sh", CI TYNAME _

    = "Rome", "I t al i an", CI TYNAME = "Par i s", "Fr ench")End Funct i on

    Pr i vat e Sub Command1_Cl i ck( )Di m I As Str i ngI = MATCH( Li st 1. Text )

    Text 1. Text = IEnd Sub

    Run the above programThe output for the program is

  • 7/27/2019 AdvancedVisualBasicLab.pdf

    32/243

    Advanced Visual Basic

    Centre for Information Technology and Engineering, Manonmaniam Sundarnar University32

    Ex 14 - Using Option box

    Open a standard exe

    Paste 3 label boxes change label1 caption as Number , label2 caption as Name & label3 caption asSubjects.

    Paste a Frame control and change its caption as Subjects

    Paste 3 option controls in the frame control and change option1 label as tamil, Option2 Caption asEnglish , Option3 caption as French

    Paste 3 text boxes and clear its caption property

    Paste 2 Command buttons and change command1 caption as Click me & command2 caption asExit.

    Now your form will look like

    Write the following code in the corresponding control events

    Opt i on Expl i ci t

  • 7/27/2019 AdvancedVisualBasicLab.pdf

    33/243

    Lab Excercises and Solutions

    Centre for Information Technology and Engineering, Manonmaniam Sundarnar University33

    Pr i vat e Sub Command1_Cl i ck( )Opt i on1. Enabl ed = True

    Opt i on2. Enabl ed = Tr ueOpt i on3. Enabl ed = Tr ue

    Text 1. Text = I nput Box( "Enter t he Regi st er numebr")

    Text 2. Text = I nput Box( "Enter t he name " )MsgBox ( "Pl ease sel ect any two opt i onal subj ect s f r omt he Subj ect box")End Sub

    Pr i vat e Sub Command2_Cl i ck( )EndEnd Sub

    Pr i vate Sub Form_Load( )Form1. Wi ndowStat e = 2Opt i on1. Enabl ed = Fal seOpt i on2. Enabl ed = Fal seOpt i on3. Enabl ed = Fal se

    End Sub

    Pri vat e Sub Opt i on1_Cl i ck()I f Opt i on1. CausesVal i dati on = True Then

    Text 3. Text = Text 3. Text + " Tami l "End I f

    End Sub

    Pri vat e Sub Opt i on2_Cl i ck()I f Opt i on2. CausesVal i dati on = True Then

    Text 3. Text = Text 3. Text + " Engl i sh"End I f

    End Sub

    Pri vat e Sub Opt i on3_Cl i ck()I f Opt i on3. CausesVal i dati on = True Then

    Text 3. Text = Text 3. Text + " Fr ench"End I f

    End Sub

    Run the above program

    The output is

  • 7/27/2019 AdvancedVisualBasicLab.pdf

    34/243

    Advanced Visual Basic

    Centre for Information Technology and Engineering, Manonmaniam Sundarnar University34

  • 7/27/2019 AdvancedVisualBasicLab.pdf

    35/243

    Lab Excercises and Solutions

    Centre for Information Technology and Engineering, Manonmaniam Sundarnar University35

    Ex 15 - Using Check box

    Open a standard exe

    Paste 3 label boxes change label1 caption as Number , label2 caption as Name & label3 caption asSex.

    Paste a Frame control and change its caption as Sex

    Paste 2 Check box controls in the frame control and change check1 caption as Male, Check2Caption as Female.

    Paste 3 text boxes and clear its caption property

    Paste 2 Command buttons and change command1 caption as Click me & command2 caption asExit.

    Now your form will look like

    Write the following code in the corresponding control events

    Opt i on Expl i ci t

    Pri vat e Sub Check1_Cl i ck()

    101

    Sankar

  • 7/27/2019 AdvancedVisualBasicLab.pdf

    36/243

    Advanced Visual Basic

    Centre for Information Technology and Engineering, Manonmaniam Sundarnar University36

    I f Check1. CausesVal i dat i on = True ThenText 3. Text = " Mal e"End I fEnd Sub

    Pri vat e Sub Check2_Cl i ck()

    I f Check2. CausesVal i dat i on = True ThenText 3. Text = " Femal e"End I fEnd Sub

    Pr i vat e Sub Command1_Cl i ck( )Check1. Enabl ed = True

    Text 1. Text = I nput Box( "Enter t he Regi st er numebr")Text 2. Text = I nput Box( "Enter t he name " )MsgBox (" Pl ease sel ect Sex f r omt he Sex box")End Sub

    Pr i vat e Sub Command2_Cl i ck( )EndEnd Sub

    Pr i vate Sub Form_Load( )Form1. Wi ndowStat e = 2End Sub

    Run the program

  • 7/27/2019 AdvancedVisualBasicLab.pdf

    37/243

    Lab Excercises and Solutions

    Centre for Information Technology and Engineering, Manonmaniam Sundarnar University37

    Ex 16 - Example for Creation of Menu

    o Ceate a Standard Exeo Right click the form and Select the option Menu Editor o In the Menu Editor Window type the following

  • 7/27/2019 AdvancedVisualBasicLab.pdf

    38/243

    Advanced Visual Basic

    Centre for Information Technology and Engineering, Manonmaniam Sundarnar University38

    Write the following code in the code windows corresponding menu events

    Opt i on Expl i ci t

    Pri vat e Sub Copy_Cl i ck()Label 1. Capt i on = " Copy opt i on i s sel ect ed"End Sub

    Pr i vat e Sub Cut _Cl i ck( )Label 1. Capt i on = " Cut opt i on i s sel ected"End Sub

    Pr i vate Sub Form_Load( )Label 1. Font Si ze = 16Label 1. Font Bol d = Fal seEnd Sub

    Pri vat e Sub New_Cl i ck( )Label 1. Capt i on = " New opt i on i s sel ect ed"End Sub

    Pri vat e Sub Open_Cl i ck( )Label 1. Capt i on = " Open opt i on i s sel ect ed"End Sub

    Pr i vat e Sub Past e_Cl i ck( )Label 1. Capt i on = " Past e opt i on i s sel ected"End Sub

    Pr i vat e Sub Qui t _Cl i ck( )Label 1. Capt i on = " Qui t opt i on i s sel ected"MsgBox ( "The progr amwi l l be Ter mi nat ed")EndEnd Sub

    Pri vat e Sub Save_Cl i ck()

    Label 1. Capt i on = " Save opt i on i s sel ect ed"End SubRun the program

    Click the file menu and select the Option optionThe output will be

  • 7/27/2019 AdvancedVisualBasicLab.pdf

    39/243

    Lab Excercises and Solutions

    Centre for Information Technology and Engineering, Manonmaniam Sundarnar University39

    When select the Exit menus Quit option the output will be

    Ex 17 Multiple Document Interface

    o Open a New standard EXE project

    o Design your form as shown below

    o On clicking the Picture & Application button another form should be loaded

    o Change the Caption property of the form.

    o On the Tool menu click Menu Editor.

    o Add the following Menu items.

    Caption Name

    &Picture mnmaster

    &Application mntrans

    1. Enter the code in the declaration section of the form

  • 7/27/2019 AdvancedVisualBasicLab.pdf

    40/243

    Advanced Visual Basic

    Centre for Information Technology and Engineering, Manonmaniam Sundarnar University40

    Pri vat e Sub mnmaster_Cl i ck( )

    For m3. Show

    End Sub

    Pri vat e Sub mnt r ans_Cl i ck()For m1. Show

    End Sub

    Execute the program

    Ex18 - Using List Controls

    Open a standard exe

    Paste 2 list controls boxes change list1 list as empty , list2 list as empty

    Paste a label control and change its caption as Position of your Selected item is

    Paste 3 command controls in the form and change command1 option1 as Click me, Command2Caption as Copy , Command3 caption as Exit.

    Paste 1 text box and clear its caption property

    Now your form will look like

  • 7/27/2019 AdvancedVisualBasicLab.pdf

    41/243

    Lab Excercises and Solutions

    Centre for Information Technology and Engineering, Manonmaniam Sundarnar University41

    Write the following code in the command button events

    Opt i on Expl i ci t

    Pr i vat e Sub Command1_Cl i ck( )Di m a As St r i nga = I nputBox( "Ent er a name")Li st1. AddI t em aEnd Sub

    Pr i vat e Sub Command2_Cl i ck( )Text 1. Text = Li st 1. Li st I ndex + 1Li st2. AddI t em ( Li st1. Text )End Sub

    Pr i vat e Sub Command3_Cl i ck( )EndEnd Sub

    Run the program

    o Click the Click Me Button

    o Enter the name and Click OK Button

  • 7/27/2019 AdvancedVisualBasicLab.pdf

    42/243

    Advanced Visual Basic

    Centre for Information Technology and Engineering, Manonmaniam Sundarnar University42

    o Select a particular name and Click Copy Button.

    Ex 19 - Creating a Table Using Visual Data Manager

    Create a Standard Exe

    Selecte the Add_ins command in the menu bar

    Select Visual data manager

  • 7/27/2019 AdvancedVisualBasicLab.pdf

    43/243

    Lab Excercises and Solutions

    Centre for Information Technology and Engineering, Manonmaniam Sundarnar University43

    o select Filemenu -> New ->Ms Access -> version 7.0

    o Give a data base name (ie. MSIT)

  • 7/27/2019 AdvancedVisualBasicLab.pdf

    44/243

    Advanced Visual Basic

    Centre for Information Technology and Engineering, Manonmaniam Sundarnar University44

    Click properties and Select new table now Table structure will be displayed

    o Give the table in the Table name text box

    o Click Add field button

    o Enter the fileld name, field type & field wideth in the appropriate text Boxes of the add field

    window.

    Give the table name and click Add field

  • 7/27/2019 AdvancedVisualBasicLab.pdf

    45/243

    Lab Excercises and Solutions

    Centre for Information Technology and Engineering, Manonmaniam Sundarnar University45

    Ex20 - To Ceate DLL

    o Open New project and select ActiveX DLL

  • 7/27/2019 AdvancedVisualBasicLab.pdf

    46/243

    Advanced Visual Basic

    Centre for Information Technology and Engineering, Manonmaniam Sundarnar University46

    o Select the Tool in the menu bar and click the Add procedure option .o A window will be displayed like given below

    o Give one name for the procedure

    o Select Function and click ok button

    o Write the following code in the windows

  • 7/27/2019 AdvancedVisualBasicLab.pdf

    47/243

    Lab Excercises and Solutions

    Centre for Information Technology and Engineering, Manonmaniam Sundarnar University47

    Save the class module and the project

    Open the class module property window and change the name as SIM

    From the file menu select the option make project dll

    Save the dll name

  • 7/27/2019 AdvancedVisualBasicLab.pdf

    48/243

    Advanced Visual Basic

    Centre for Information Technology and Engineering, Manonmaniam Sundarnar University48

    Open a new Standard Exe and write the following code in the load event.

    o Select project in the Munu bar

    o Select Reference option in the project menu

    o Now you can see your dll in the Reference

    o Select your dll

    o Write the following code in the form load event

    Di m A As New PRJ SI M. SI M

    Pr i vate Sub Form_Load( )MsgBox A. SI MI NT( 10000, 2, 2)

    End Sub

    Run the program

    THE OUT PUT IS

    Ex 21 - Using Data Control

    Create a form with the following controls ie. 2 label boxes and 2 text boxes with one data control.

    Change the caption of label 1 as Author_id

    Change the caption of label2 as Author name

    Clear the text boxes text property

  • 7/27/2019 AdvancedVisualBasicLab.pdf

    49/243

    Lab Excercises and Solutions

    Centre for Information Technology and Engineering, Manonmaniam Sundarnar University49

    Change the data field and data source in the property box of the text box

    Open the property window of the Data1 and change its caption as Data1 & change the

    Databasename as given below ow.

    o Open the text boxs property window and change this Data source nand Data filed property

  • 7/27/2019 AdvancedVisualBasicLab.pdf

    50/243

    Advanced Visual Basic

    Centre for Information Technology and Engineering, Manonmaniam Sundarnar University50

    Run the above program

    The output is

    Ex22 - Using RDO

    Click the start button

    Click the setting

    Open the control panel and select the ODBC Data Source

  • 7/27/2019 AdvancedVisualBasicLab.pdf

    51/243

    Lab Excercises and Solutions

    Centre for Information Technology and Engineering, Manonmaniam Sundarnar University51

  • 7/27/2019 AdvancedVisualBasicLab.pdf

    52/243

    Advanced Visual Basic

    Centre for Information Technology and Engineering, Manonmaniam Sundarnar University52

    The DSN RDOACC can be seen in the ODBC Data source administrator.

  • 7/27/2019 AdvancedVisualBasicLab.pdf

    53/243

    Lab Excercises and Solutions

    Centre for Information Technology and Engineering, Manonmaniam Sundarnar University53

    Create a standard exe with following controls ie., two text boxes and two label boxesAnd paste a MSRDC control in the form.

    Open the property window of the text box and change its Datafield and Datasource property like

    shown in the following windows.

  • 7/27/2019 AdvancedVisualBasicLab.pdf

    54/243

    Advanced Visual Basic

    Centre for Information Technology and Engineering, Manonmaniam Sundarnar University54

    Select the property window of the MSRDC1 and change the following properties ie.,

    Dat aSour ceName RDOACC

    SQL Sel ect * f r om aut hor s

    Run the program

    The out put is

    Ex 23 - Using ADO

    Open a Standard exe form

    Open a new form and paste two label boxes and two text boxes

    Clear the captions of the two text boxes

    Change the caption of lable1 as Author id

    Change the caption of label2 as Author name

    Open the property menu and click the Component option

    select the Microsoft ADO Data control 6.0

  • 7/27/2019 AdvancedVisualBasicLab.pdf

    55/243

    Lab Excercises and Solutions

    Centre for Information Technology and Engineering, Manonmaniam Sundarnar University55

    o Paste one ADODC ie., ADO Data Control in the form and select the Connectionstring

  • 7/27/2019 AdvancedVisualBasicLab.pdf

    56/243

    Advanced Visual Basic

    Centre for Information Technology and Engineering, Manonmaniam Sundarnar University56

    Click build button

    Select Microsoft jet 351 OLE DB Provider

    Select the table

  • 7/27/2019 AdvancedVisualBasicLab.pdf

    57/243

    Lab Excercises and Solutions

    Centre for Information Technology and Engineering, Manonmaniam Sundarnar University57

    Click text connection

    Click ok

    Once again click apply in the property pages then theproperty box will be changed like the following

    format.

  • 7/27/2019 AdvancedVisualBasicLab.pdf

    58/243

    Advanced Visual Basic

    Centre for Information Technology and Engineering, Manonmaniam Sundarnar University58

    Give the command type and table name in the dropdown list box and click apply in the window.

    Run the program

  • 7/27/2019 AdvancedVisualBasicLab.pdf

    59/243

    Lab Excercises and Solutions

    Centre for Information Technology and Engineering, Manonmaniam Sundarnar University59

    Ex 24 - Using ADO

    Open a form and paste 10 command buttons, two label box and two text boxes

    Change the caption label1as Employee number

    Change the caption label2 as Employee name

    Change the name of the command1 as first and caption as first

    Change the name of the command2 as next and caption as next

    Change the name of the command3 as previous and caption as previous

    Change the name of the command4 as last and caption as last

    Change the name of the command5 as add and caption as add

    Change the name of the command6 as modify and caption as modify

    Change the name of the command7 as save and caption as save

    Change the name of the command8 as delete and caption as delete

    Change the name of the command9 as clear and caption as clear

    Change the name of the command10 as exit and caption as exit

    Wr i t e the f ol l owi ng code

    Di m DB As Dat abase

    Di m RS As Recor dset

    Pri vat e Sub Add_Cl i ck()

    RS. AddNew

    CLEA

    End Sub

    Pr i vat e Sub Cl ear _Cl i ck( )

    CLEA

    End Sub

    Pr i vat e Sub Del et e_Cl i ck( )

    RS. Del ete

    CLEA

  • 7/27/2019 AdvancedVisualBasicLab.pdf

    60/243

    Advanced Visual Basic

    Centre for Information Technology and Engineering, Manonmaniam Sundarnar University60

    End Sub

    Pr i vat e Sub Exi t _Cl i ck( )

    End

    End Sub

    Pr i vat e Sub Fi r st_Cl i ck( )

    RS. MoveFi r st

    SCROLL

    End Sub

    Pr i vate Sub Form_Load( )

    Set DB = OpenDat abase( "d: \ PROGRAM FI LES\ MI CROSOFT VI SUAL

    STUDI O\ VB98\ bi bl i o. MDB")

    Set RS = DB. OpenRecordset ( "aut hor s" , dbOpenDynaset )

    End Sub

    Publ i c Sub CLEA( )

    Text 1. Text = " "

    Text 2. Text = " "End Sub

    Publ i c Sub SCROLL( )

    Text 1. Text = RS( 0)

    Text 2. Text = RS( 1)

    End Sub

    Pr i vat e Sub Last _Cl i ck( )

    RS. MoveLast

    SCROLL

    End Sub

    Pr i vat e Sub Modi f y_Cl i ck( )

    RS. Edi t

    RS(0) = Text1. Text

    RS(1) = Text2. Text

    RS. Updat e

    End Sub

    Pri vat e Sub Next _Cl i ck()

    RS. MoveNext

    I f RS. EOF Then

    RS. MoveFi r st

    End I f

    SCROLL

    End Sub

    Pr i vat e Sub Pr evi ous_Cl i ck( )

    RS. MovePr evi ousI f RS. BOF Then

    RS. MoveLast

    End I f

    SCROLL

    End Sub

    Pri vat e Sub Save_Cl i ck()

    RS(0) = Text1. Text

  • 7/27/2019 AdvancedVisualBasicLab.pdf

    61/243

    Lab Excercises and Solutions

    Centre for Information Technology and Engineering, Manonmaniam Sundarnar University61

    RS(1) = Text2. Text

    RS. Updat e

    End Sub

    Run the program

    The out put is

    Ex 25 - Creating a Data Report

    o Create a standard EXE

    o Place a command button on the form

    o Select project1 and right click it

    o Select Add -> More ActiveX Designer -> Data Environment

    The following window will be displayed

    o Open property of Connection1 and select MicroSoft Jet 3.51 OLE DB providero Click OKo Then select the Database name for displayed window

  • 7/27/2019 AdvancedVisualBasicLab.pdf

    62/243

    Advanced Visual Basic

    Centre for Information Technology and Engineering, Manonmaniam Sundarnar University62

    \

    Click the Test Connectio button

    The following window will be displayed

    click OK

    Now select the Connection1 and select the option Add Command

  • 7/27/2019 AdvancedVisualBasicLab.pdf

    63/243

    Lab Excercises and Solutions

    Centre for Information Technology and Engineering, Manonmaniam Sundarnar University63

    o Select Command1 and click its property

    o In the property window of the Command1

    o Enter the Database name in Database Object box&

    o Enter the Table name in Object Name Box

    o Click OK

    o Now Select the Project1 ->Add->DataReport

    o Now Open the property box of the DataReport1 and Enter

    o Command1 in DataMember

    o DataEnvironment1 in DataSource

    o Now Drag Command1 from the DataEnvironment1 and paste it in DataReport1

    o Now the window will look like

    Now Open the form1 command button Click Event and write the following code in it.

    Pr i vat e Sub Command1_Cl i ck( )

  • 7/27/2019 AdvancedVisualBasicLab.pdf

    64/243

    Advanced Visual Basic

    Centre for Information Technology and Engineering, Manonmaniam Sundarnar University64

    DataReport 1. show

    End Sub

    Now Run the project

    YZ

  • 7/27/2019 AdvancedVisualBasicLab.pdf

    65/243

    Lab Exercises

    Centre for Information Technology and Engineering, Manonmaniam Sundaranar University 1

    Lab Unit 1 (1 Real Time Hrs)

    Ex 1:

    Pre-Requisite:- You are suggested to take this lab session only after

    completion of Lecture 3.

    (Use If..Then..Else statement )

    1. Open a new standard EXE project2. Place a text box and a command button in the form

    3. Enter a number in the text box4. On clicking the command button, a message box is to be displayed5. The message box should display whether the number in the text box is a

    Single, Two, Three digit numbers

    Ex 2:1. Add Standard Exe project2. In this form add one text box and three command buttons.

    3. The form is designed as per the following Specifications.

    Object Property Setting

    Form Caption Display

  • 7/27/2019 AdvancedVisualBasicLab.pdf

    66/243

    Object Oriented Programming with Java

    Centre for Information Technology and Engineering, Manonmaniam Sundaranar University2

    Command

    Text

    NameCaptionName

    NameText

    Form1DisplayCommand1

    TxtResultClear the Property

    4. When we click the display button welcome message is printed in thetext box

    5. When we click the clear button the message is cleared6. When we click the Exit button the form will be closed.

    Ex 3:

    ( Use Select ...Case statement )

    Open a new standard EXE project

    Place a text box , label and a command button in the form

    # Enter a number ( 0 or 1 or 2 )in the text box

    # On clicking the command button, the messages given below should be

    displayed.

    # Gods delays are not denials ( for 0)

    # A Single drop makes an Ocean ( for 1)

    # Hardwork and success go hand-in-hand ( for 2)

    Lab - 2 ( 1 Real Time Hrs)

    Ex1:

    Pre-Requisite:- You are suggested to take this lab session only after

    completion of Lecture 4.

    1. Create a new Standard EXE project

  • 7/27/2019 AdvancedVisualBasicLab.pdf

    67/243

    Lab Exercises

    Centre for Information Technology and Engineering, Manonmaniam Sundaranar University 3

    2. Enter the Code in the Form Load event procedure

    3. During run time the caption , mouse pointer, Window State, Height andWidth properties should be changed

    EX 2:

    1. Add a new standard EXE project.2. Design your form as shown below

    3. The form is designed as per the following Specifications.

    Object Property Setting

    Form1Command1Command2

    Text1Text2

    CaptionCaptionCaption

    TextText

    Convert the DateClickExit

    Clear the PropertyClear the Property

    4. When we click the click button it will clear the date in text1 and it willconverts the date to text2.

    5. When we click the exit button it will close the form.

    Lab - 3

    Pre-Requisite:- You are suggested to take this lab session only

    after completion of Lecture4

    1. Add a new standard EXE project.

  • 7/27/2019 AdvancedVisualBasicLab.pdf

    68/243

    Object Oriented Programming with Java

    Centre for Information Technology and Engineering, Manonmaniam Sundaranar University4

    2. Design your form as shown below

    Object Property SettingForm

    Text1Text2Text3Text4Text5Text6Text7Label1

    Label2Label3Label4Label5Label6Label7Command1Command2

    CaptionNameTextTextTextTextTextTextTextCaption

    CaptionCaptionCaptionCaptionCaptionCaptionCaptionCaption

    Employees SalaryForm1Clear thePropertyClear thePropertyClear thePropertyClear theProperty

    Clear thePropertyClear thePropertyClear thePropertyEmployee NoEmployee NameBasic payHRAllowanceProvident FundGross PayNet PayClickExit

    3. We enter the Employee no, Employee Name and Basicpay.

    4. When we click the Click button the HRA, PF, GrossPay and NetPay arecalculated.

  • 7/27/2019 AdvancedVisualBasicLab.pdf

    69/243

    Lab Exercises

    Centre for Information Technology and Engineering, Manonmaniam Sundaranar University 5

    HRA is 20% of Basic pay.PF is 10% of Basic pay.GrossPay is addition of Basicpay and HRA.NetPay is GrossPay-PF.

    5. When we click the exit button the form is closed.

    Lab 4 ( 2 Real Time Hrs)

    Ex 1:

    Pre-Requisite:-You are suggested to take this lab Unit only after completion of Lecture 4.

    1. Add a new standard EXE project.2. Design your form as shown below

    3. The form is designed as per the following Specifications.

    Object Property Setting

    Form1Text1Text2Text3Text4Frame1

    Frame2Option1Option2CheckBox1CheckBox2CheckBox3Command1

    CaptionCaptionCaptionTextTextCaption

    CaptionCaptionCaptionCaptionCaptionCaptionCaption

    Bio-DataClickExitClear the PropertyClear the PropertySex

    QualificationMaleFemaleHscUndergraduatepostgraduateExit

  • 7/27/2019 AdvancedVisualBasicLab.pdf

    70/243

    Object Oriented Programming with Java

    Centre for Information Technology and Engineering, Manonmaniam Sundaranar University6

    4. When we enter the date of birth of the candidate automatically it willdisplay age of that particular person. (For using Lost Focus Event).

    5. When the control transfer to sex frame control there is only one option willbe selected.

    6. After selecting the option the control will transfer to Qualification7. In this Qualification frame we also select more then one options.8. When we click the exit button for closing the form.

    Ex 2:

    (Declaring Variable)1. Open a new standard EXE project

    2. Add four text boxes and a command button to the form

    3. Open the code window of the form

    4. Place the code Option Explicit as the first line of the declarations section ofthe form. This forces the variables to be declared before they are used.

    5. Open the event procedure for the Click event of the command button. Youcan do this by selecting the name of the command button from the objectlist on the left of the code window. Use the following statements to createthe variables for calculating area and perimeter. These statements shouldbe place at the top of the event procedure.

    6. Run the program

    Lab 5 ( 1 Real Time Hrs)

    Ex1:

    Pre-Requisite:-You are suggested to take this lab Unit only after completion of Lecture 4.

    1. Add a new standard EXE project.

  • 7/27/2019 AdvancedVisualBasicLab.pdf

    71/243

    Lab Exercises

    Centre for Information Technology and Engineering, Manonmaniam Sundaranar University 7

    2. Design your form as shown below.

    3. The form is designed as per the following Specifications.

    Object Property Setting

    Form1Text1Text2Text3Text4Label1Label2Command1

    Command2

    CaptionTextTextTextTextCaptionCaptionCaption

    Caption

    Reverse the TextClear the PropertyClear the PropertyClear the PropertyClear the PropertyEnter the DateEnter the TextDay to Year

    Reverse the Text

    4. When we click the reverse the text button it will display reverse contentof text3 in text4.

    5. When we click the day to year button it will display the year of the text1content in text2.

    6. When we click the exit button the form will close.Ex2:

    1. Open a new standard EXE project2. Design your form as shown below

  • 7/27/2019 AdvancedVisualBasicLab.pdf

    72/243

    Object Oriented Programming with Java

    Centre for Information Technology and Engineering, Manonmaniam Sundaranar University8

    3. Current Time should be displayed on the Text14. Current Date should be displayed on the Text2

    Ex 3:

    1. Open a new standard EXE project2. Design your form as shown below

    3. In the Text1 Box enter a date4. In the Text3Box enter a text5. If you click the Command Button1, Day of the Date should be displayed

    in the Text2 Box6. If you click the Command Button2, UpperCase of the text should be

    displayed in the Text4 Box

    Lab - 6 ( 2 Real Time Hrs)

    Ex 1: Pre-Requisite:- You are suggested to take this lab Unit onlyafter completion of Lecture 6.

    1. Add a new standard EXE project.2. Design your form as shown below.

    3. The form is designed as per the following Specifications.

    Object Property Setting

    Form CaptionName

    Recursive FactorialCalculation

  • 7/27/2019 AdvancedVisualBasicLab.pdf

    73/243

    Lab Exercises

    Centre for Information Technology and Engineering, Manonmaniam Sundaranar University 9

    CommandTextText

    CaptionTextText

    Form1FactorialClear PropertyClear Property

    4. When we Click the Commad1 Button, the factorial Value of Text1 will beDisplayed in the Text2.(Using Recursive Fn.)

    Ex 2:

    1. Open a new Standard EXE project

    2. Design your form as shown below

    3. Whenever the Textbox "TEXT1" gets the focus it must be cleared.

    4. The Textbox "TEXT1" should accept only numbers.

    5. The user must not be allowed to go out of the Text box "TEXT1" when it isempty

    6. The Textbox "TEXT2" must accept only alphabets (Upper case)

    7. The Textbox "TEXT3" should accept only a maximum of 8 digits and onlynumbers.

    8. "TEXT4" is to input a special allowance to the female candidates. So theuser must be allowed to enter values in it only if the candidate is a femalecandidate

  • 7/27/2019 AdvancedVisualBasicLab.pdf

    74/243

    Object Oriented Programming with Java

    Centre for Information Technology and Engineering, Manonmaniam Sundaranar University10

    9. If any of the allowances is applicable to the candidate it must be displayedin the respective label boxes.

    HRA 2500.00DA - 3000.00

    10.When the user clicks the "OK" button a confirmation message must bedisplayed in the label box "Label"

    11.When the user clicks the "Cancel" button a cancellation message must bedisplayed in the above mentioned label control and all the textboxes mustbe cleared.

    12.When the user clicks the "Exit" button stop the execution of the program.

    Lab 7 ( 2 Real Time Hrs )

    Ex 1: Pre-Requisite:-You are suggested to take this lab Unit only after completion of Lecture 6.

    1. Open a new standard EXE project.2. Design your form as shown below.

    3. The form is Designed as per the following Specifications.

    Object Property Setting

    Form1

    Label1

    List1

    CaptionNameCaptionNameName

    List Box ControlsForm1Total No.of Selected ItemLabel1List1

  • 7/27/2019 AdvancedVisualBasicLab.pdf

    75/243

    Lab Exercises

    Centre for Information Technology and Engineering, Manonmaniam Sundaranar University 11

    Combo1

    Command1

    Command2

    Text1

    Name

    Caption

    Caption

    Name

    Combo1

    Add

    Remove

    Text1

    4. If we Click Command1, the item is entered in the inputbox and added tothe List1.

    5. If we Click Command2, the selected item of the listbox will be removed.6. When we select the item in the List1, that item will be added in the

    Combo1 & displayed in the Text1.Ex 2:

    1. Open a new Standard EXE project

    2. Design your form as shown below and perform a Calculator Project ,which can able to work as like as Windows Calculator

    (Use Control Arrays)

    Lab 8 ( 2 Real Time Hrs ) .

    Ex 1:

    Pre-Requisite:- You are suggested to take this lab Unit only

    after completion of Lecture 6.

    1. Open a new standard EXE project.

  • 7/27/2019 AdvancedVisualBasicLab.pdf

    76/243

    Object Oriented Programming with Java

    Centre for Information Technology and Engineering, Manonmaniam Sundaranar University12

    2. Design your form as shown below.

    3. The form is Designed as per the following Specifications.

    Object Property Setting

    Form

    Frame

    Frame

    Label

    Label

    Label

    Label

    Label

    Label

    Label

    TextTextTextText

    ComboComboComboCommand

    Command

    CaptionNameName

    Name

    CaptionNameCaptionNameCaptionName

    CaptionNameCaptionNameCaptionNameCaptionNameNameNameNameName

    NameNameNameCaptionNameCaptionName

    List SearchForm1Frame1

    Frame2

    NameLabel1SSNLabel2American ExpressLabel3

    VisaLabel4Search By SSNLabel5Search By American #Label6Search By VisaLabel7TxtNameTxtSSNTxtAmericnTxtvisa

    CmbSSNCmbAmericanCmbVisaAdd NewCmdaddCancelCmdCancel

  • 7/27/2019 AdvancedVisualBasicLab.pdf

    77/243

    Lab Exercises

    Centre for Information Technology and Engineering, Manonmaniam Sundaranar University 13

    4. If we select the CmdAdd ,we have to enter the values in the TxtName,TxtSSN, TxtAmerican, TxtVisa .Then it contents is added to thecorresponding Combo box (CmbSSN,cmbAmerican,cmbVisa)

    5. If we select the SSN name in the CmbSSN, the corrsponding values isdisplayed in the Text box.

    Lab - 9 ( 2 Real Time Hrs)

    Ex 1:

    Pre-Requisite:- You are suggested to take this lab Unit only after

    completion of Lecture 6.

    1. Open a new standard EXE project.2. Design Your form As shown in below.

    3. The form is Designed as per the following Specifications.

    Object Property SettingForm1

    Label1

    Label2

    List1

    List2

    Command1

    Command2Command3

    Command4

    Command5

    Command6

    CaptionNameCaptionNameCaptionNameCaptionNameCaptionNameCaptionName

    CaptionNameCaptionNameCaptionNameCaptionName

    Caption

    Move List ControlForm1All ItemslblallSelected ItemsLblSelectedlstAlllist1lstSelectedlist2>CmdRightOne

    >>CmdRightAllAdd Class Module in the Form1

    5. When we select the CmdStart Button, the Caption of this button is Changedto Stop Timing,then start the Time .

    6. When we select the CmdStart Button, the Caption of this button is Changedto Start Timing,then stop the Time.

    7. When we select the CmdShow Button, the Elapsed time will be displayedin the MessageBox.

    8. When we select the CmdExit Button, to exit of the Program.

    Note : (Using ClassModule)Ex 2:

    1. Create a new standard EXE project.

  • 7/27/2019 AdvancedVisualBasicLab.pdf

    91/243

    Lab Exercises

    Centre for Information Technology and Engineering, Manonmaniam Sundaranar University 27

    2. Design your form as shown below.3. The form is Designed as per the following Specifications.

    Object Property Setting

    Form

    Command

    Command

    Command

    Text

    TextTextText

    CaptionName

    CaptionName

    CaptionName

    CaptionNameName

    NameNameName

    String Operation TestForm1

    Convert to StringCmdString

    Convert to LcapsCmdLcaps

    Convet to BinaryCmdBinaryText1

    Text2Text3Text4

    4. We have to Create CSting Class, follow this Steps In the Menu Project-

    >Add Class Module in the Form1

    5. We have to enter the Number From 1 to 9999 in the Text1

    6. When we select the CmdString Button, the value of Text1 is converted to

    the String in the Text2.7. When we select the CmdLcaps Button, the String of Text2 is converted to

    the Lcaps in the Text3.

    8. When we select the CmdBinary Button, the value of Text1 is converted to

    the Binary in the Text4.

    Lab units 18 (2 Real Time Hrs )

    Ex 1:

    Pre-Requisite:- You are suggested to take this lab session only after completionof Lecture 11.

    1. Open a New standard EXE project

    2. Design your form as shown below

  • 7/27/2019 AdvancedVisualBasicLab.pdf

    92/243

    Object Oriented Programming with Java

    Centre for Information Technology and Engineering, Manonmaniam Sundaranar University28

    3. Create a Data Source named Trading Company4. Link the data source( Trading Company) to this form. The data source can

    be got from the file Nwind.mdb in your VB folder

    Ex 2 :

    Pre-Requisite:- You are suggested to take this lab Unit only after completion ofLecture 11

    1. Create a new standard EXE project.2. Design your form as shown below.

  • 7/27/2019 AdvancedVisualBasicLab.pdf

    93/243

    Lab Exercises

    Centre for Information Technology and Engineering, Manonmaniam Sundaranar University 29

    3. The form1 is Designed as per the following Specifications.

    Object Property Setting

    Form

    Command

    ListListListListLabelLabelLabelLabelCommonDialo

    gText

    CaptionNameCaptionNameNameNameNameNameCaptionCaptionCaptionCaptionName

    Name

    DataBase StructureForm1OpenDataBaseCmdOpenList1List2List3List4TabelsSelected Tables FieldsQueriesSelected Queries definitionCommonDialog1

    Text1

    4. When we select the CmdOpen Button, the Open dialog box will bedisplayed. Then we select the MDB file, that file will be Displayed in theText1 and corresponding tables, queries will be displayed in the list1,list3

    5. If we select the tables in the List1, the corresponding fields in the table willbe displayed in the List3.

    6. If we select the tables in the List3, the corresponding queries will bedisplayed in the List4.

    Ex3:

    Pre-Requisite:- You are suggested to take this lab session only after completionof Lecture 12.

    1. Create a new form and name it as RDO form.

    2. Design the form as given below:3. Refer the Microsoft Remote Data Objects 2.0 from Project/References.

    4. Declare the variables RDO Environment, RDOConnection, RDO

    Resultset, RDO query.

    5. Register a Data Source Name (DSN).

  • 7/27/2019 AdvancedVisualBasicLab.pdf

    94/243

    Object Oriented Programming with Java

    Centre for Information Technology and Engineering, Manonmaniam Sundaranar University30

    6. To Register the DSN follow the steps as mentioned below :

    7. Start/Settings/ControlPanel/32bitODBC & select the Microsoft ODBCDriver for Oracle.

    8. Using the Create Environment, Open Connection methods create the

    environment & open the connection respectively.

    9. Use the Open Resultset method to display the records from the respective

    table in the textboxes.

    10.Perform the manipulations such as addnew, edit & update with the

    respective coding addnew, update & edit methods.

    11.Using the Create RDOQuery method try to insert a value.

    12.Find a record based on the Empno using the RDO Query.

    13.Write a code segment to call a procedure (Remote Procedure) that returns

    the summation of two numbers.

    Lab units 19 ( 2 Real Time Hrs )

    Ex 1:

    Pre-Requisite:- You are suggested to take this lab session only after completionof Lecture 13.

  • 7/27/2019 AdvancedVisualBasicLab.pdf

    95/243

    Lab Exercises

    Centre for Information Technology and Engineering, Manonmaniam Sundaranar University 31

    1. Add a New Project

    2. Design the Form as shown below3. Invoke ActiveX Data Object Library File

    Project References MS ActiveX Data Object 2.0 Establish Connection4. Open Recordset and display records in the Text boxes Perform Data

    Manipulations like Addition, Deletion, Modification Perform Navigationmethods

    5. Try using Action Queries with the help of Command Object UsingCommand Object, try executing a Remote Procedure that gives the sum oftwo numbers

    6. Add a Form7. Choose Microsoft ADO Data Control Project Components

    Microsoft ADO Data Control 6.0 (OLE DB)8. Design your Form as shown above

  • 7/27/2019 AdvancedVisualBasicLab.pdf

    96/243

    Object Oriented Programming with Java

    Centre for Information Technology and Engineering, Manonmaniam Sundaranar University32

    9. Set the following properties of ADODC1Connect StringUser NamePasswordRecord Source

    10.Set the following properties for your Text boxes to display the fieldsData SourceData field

    Invoke MS DataGrid Control 6.0 (OLEDB)11.Set the following property of MS Data Grid

    Record Source12.Now try data manipulations through the MS Data Grid, by setting the

    Design time propertiesEx 2:

    Pre-Requisite:- You are suggested to take this lab session only aftercompletion of Lecture 14.

    1. Consider a Railway database in SQL Server with three tables namelyPassenger_details,Train_Details and Train_Pass_Details with fields givenbelow

    Passenger DetailsPassenger Id, Passenger Name,Age,Sex,Train name, Class booked

    Train Details

    Train name, Train no, I class fare, II class fare, Unreserved fare, I seats,II seats

    Traiin Pass DetailsPassenger id, Coach No, seat no, Date of journey

    2. Create a project to list the passenger ids in the combobox and to list thedetails of the passenger ( Train number, seat number and ticket fare)

    3. Design your form as shown below.

  • 7/27/2019 AdvancedVisualBasicLab.pdf

    97/243

    Lab Exercises

    Centre for Information Technology and Engineering, Manonmaniam Sundaranar University 33

    Lab units 20 ( 2 Real Time Hrs )

    Ex 1:

    Pre-Requisite:-` You are suggested to take this lab Unit only after completion of Lecture 14.

    1. Create a new standard EXE project.

    2.

    Design your form as shown below.

    3. The form is Designed as per the following Specifications.

  • 7/27/2019 AdvancedVisualBasicLab.pdf

    98/243

    Object Oriented Programming with Java

    Centre for Information Technology and Engineering, Manonmaniam Sundaranar University34

    Object Property SettingForm

    ListGrid

    Command

    Command

    CaptionNameNameNameRowsColsCaptionNameCaptionName

    ADO ExamplesForm1List1Msflexgrid1204Connection.ExecuteCmdconnectionCommand.ExecuteCmdcommand

    4. When we select the Cmdconnecion Button, the CategoryName from theCategory table is Displayed in the List1. (Connect ODBC ,Table atRuntime using ADO Objects).

    5. When we select the Cmdcommand Button, theCustomerName,Invoice,Date & subtotal of invoice is Displayed in theGrid1.(Connect ODBC ,Table at Runtime using ADO Objects).

    Ex 2:

    Pre-Requisite:- You are suggested to take this lab Unit only after

    completion of Lecture 14.

    1. Create a new standard EXE project.2. Design your form as shown below.

    3. The form is Designed as per the following Specifications.

    Object Property Setting

    Form

    ADO

    CaptionNameNameConnection

    Form1Form1ADOBIBLIOBulid->provider tab->MS Jet

  • 7/27/2019 AdvancedVisualBasicLab.pdf

    99/243

    Lab Exercises

    Centre for Information Technology and Engineering, Manonmaniam Sundaranar University 35

    DataList

    String

    Record SourceNameDataResourceRowSource

    3.51 OLEDBConnection tab->biblo.mdb

    PublishersDbbiblioADOBIBLIOCompany

    4. Create a database table using Visual data manager Which containPublisher id, company name, Authur and address. Using the ADO controlview the detail of the table.

    Note :It is similar to DBList Control

    Ex 3:

    Pre-Requisite:-You are suggested to take this lab Unit only after

    completion of Lecture 14.

    1. Create a new standard EXE project.2. Design your form as shown below.

    3. The form is Designed as per the following Specifications.

    Object Property Setting

    Form

    ADO

    DataGrid

    CaptionName

    NameConnectionString

    Record SourceName

    Form1Form1

    ADOBIBLIOBulid->provider tab->MSJet 3.51 OLEDBConnection tab->biblo.mdb

    PublishersDbgrid1

  • 7/27/2019 AdvancedVisualBasicLab.pdf

    100/243

    Object Oriented Programming with Java

    Centre for Information Technology and Engineering, Manonmaniam Sundaranar University36

    DataResource ADOBIBLIO

    4. Create a database table using Visual data manager Which containPublisher id, company name, Author and address. Using the ADO controlview the detail of the table.

    Note :It is similar to DBGrid Control

    Lab units 21 ( 2 Real Time Hrs )

    Ex 1:

    Pre-Requisite:-You are suggested to take this lab session only after

    completion of Lecture 15

    1. Open a New standard EXE project

    2. Design your form as shown below

    3.

    On clicking the Picture & Application button another form should beloaded

    Ex 2

    Pre-Requisite:- You are suggested to take this lab session only aftercompletion of Lecture 16

    1. Open a new standard EXE project

  • 7/27/2019 AdvancedVisualBasicLab.pdf

    101/243

    Lab Exercises

    Centre for Information Technology and Engineering, Manonmaniam Sundaranar University 37

    2. Design your form as shown below

    3. On clicking the ADD button Item should be added on the file menu.

    4. On clicking the Item button Msgbox should be displayed.

    Lab - 22 ( 2 Real Time Hrs )

    Ex 1:

    Pre-Requisite:- You are suggested to take this lab Unit only after completion

    of Lecture 16.

    1. Open a New standard EXE project

    2. Create the pop-up menu with the following menu items Bold, Italic,

    Underline, Blue, Green, Red, Black, Exit

    3. Place a text box in the form On selecting an item in the pop-up menu the

    corresponding effect should be displayed

    EX 2 :

    Pre-Requisite:- You are suggested to take this lab Unit only after completion

    of Lecture 16.

    1. Create a new standard EXE project.

  • 7/27/2019 AdvancedVisualBasicLab.pdf

    102/243

    Object Oriented Programming with Java

    Centre for Information Technology and Engineering, Manonmaniam Sundaranar University38

    2. Design your form as shown below.

    3. In this Form, we have to create a menu as above form.4. File Menu ->It has 5 Sub Menus ie, New, Open, Save, SaveAs, Exit.5. If we Select the Open &Save Sub Menu, the Corresponding Open ,Save

    Dialog Box is Displayed.6. If we Select the Exit Sub Menu, the form will be closed.7. Edit -> It has 5 Sub Menus ie, Cut, Copy,Paste,Select All,Find.8. Process -> It has 3 Sub Menus ie, Upper Case,Lower Case,Line No.9. Customize -> It has 3 Sub Menus ie, Font,Text Color,Pen Color.

    Note :It is Similar like as Notepad bold.

    Lab - 23 ( 2 Real Time Hrs )

    Pre-Requisite:- You are suggested to take this lab session only after

    completion of Lecture 17

    1. MDI FORMOpen a new project. Add a MDI form along with two forms. Set the childProperty of forms and provide a way (MENU) to access the two formsfrom the MDI form.

    2. Ole Drag Drop Property

  • 7/27/2019 AdvancedVisualBasicLab.pdf

    103/243

    Lab Exercises

    Centre for Information Technology and Engineering, Manonmaniam Sundaranar University 39

    Define two controls that support OLEdragdrop. Set OLEdrag/drop modeto automatic, drag and drop data from one textbox to another.

    3. Drag and drop PropertyDefine two containers (picture box, frame) and three controls (commandbutton, Checkbox, picture box). Set the drag drop mode to automatic.Drag and drop the controls to different containers. Provide drag icons. Setthe dragover Effect when a control is dragged over a container.

    4. Imagelist:Place a imagelist on the form and insert some pictures to the imagelist Control.

    Give appropriate key value from the pictures.

    5. StaturBarPlace a status bar control in the MDI FORM. Add panels to the statusbar. The

    statusbar should display the time, date in separate panels. Also display the

    message in any of the panels whenever a text is dragged from one text box and

    Dropped into another text box. When a new form is opened display its name in

    any one of the panels of the status bar.

    6. ToolBar: Place a toolbar control on the form2. Add buttons to the toolbar as shown

    below. Set the Image index for each and every button.

    When the first button is pressed the text in the Text1 must be displayed in

    Bold format

    When the second button is pressed the text in the Text1 must be displayed

    in Italic format

    When the third button is pressed the text in the Text1 must be Underlined

  • 7/27/2019 AdvancedVisualBasicLab.pdf

    104/243

    Object Oriented Programming with Java

    Centre for Information Technology and Engineering, Manonmaniam Sundaranar University40

    When a number is selected from the combo1 the font size of the text box must

    changed according to the value selected

    When the last button is selected, the form Form1 must be closed.

    Ex 2:

    Pre-Requisite:- You are suggested to take this lab Unit only after completionof Lecture 17

    1. Create a new standard EXE project.2. Design your form as shown below.

    3. The form1 is Designed as per the following Specifications.

    Object Property SettingForm

    Command

    Command

    Text

    CaptionName

    CaptionNameCommandName

    Name

    Textstream object DemoForm1

    CreateCmdCreateReadCmdRead

    Text1

    4. When we select the Cmdcreate Button, to create the file is stored in theFilename.

    5. When we select the Cmdread Button, to read the file from the existing Fileis displayed in the text1.

  • 7/27/2019 AdvancedVisualBasicLab.pdf

    105/243

    Lab Exercises

    Centre for Information Technology and Engineering, Manonmaniam Sundaranar University 41

    Ex 3

    Pre-Requisite:- You are suggested to take this lab Unit only after completionof Lecture 17

    1. Create a new standard EXE project.

    2.

    In this project contains 2 forms as form1, form23. Design your form as shown below.

    4. The form2 is Designed as per the following Specifications.

    Object Property Setting

    Form

    Command

    Command

    Command

    Command

    Command

    CommonDialogText

    CaptionNameCaptionNameCaptionNameCaptionNameCaptionNameCaption

    NameNameName

    OLE Container DemoForm1Insert ObjectCmdInsertObject InfoCmdobjectCloseCmdCloseText1Open FileCmdOpenSave File

    CmdSaveCommonDialog1Text1

    5. When we Select the CmdInsert Button, the form2 is Displayed.

  • 7/27/2019 AdvancedVisualBasicLab.pdf

    106/243

    Object Oriented Programming with Java

    Centre for Information Technology and Engineering, Manonmaniam Sundaranar University42

    6. In the Form2, if we click the OptEmbedded or OptLinking Box , theCollection of Object will be Displayed in the dialog box.

    7. The form2 is Designed as per the following Specifications.

    Object Property Setting

    Form

    Command

    Command

    Frame

    Frame

    Option

    Option

    Option

    Option

    CaptionNameCaptionNameCaptionNameCaptionNameCaptionName

    CaptionNameCaptionNameCaptionNameCaptionName

    Object TypeForm1OkCmdOkCanelCmdCancelSize ModeFrame1Object TypeFrame2

    Stretch ObjectOptStretchStretch ContainerControlOptContainerEmbeddedOptEmbeddedLinkingOptLinking

    8. When we select CmdOk Button, the corresponding Selected Embedded,

    Linking Object list dialog is Displayed. then the selected object is insertedinto the Text Box.

    9. When we select the Cancel Button, to cancel the Current operation.

    Lab Units 24(2 hrs Real Time)

    Ex 1:

    Pre-Requisite:- You are suggested to take this lab session only

    after completion of Lecture 18

    1. Open a new project in Visual Basic and select the ActiveX documentEXE

    2. Click the UserDocument1 in the Project window and name it as travreq

    3. Design the form as shown below

    4. On Clicking the Print button this form must be printed

  • 7/27/2019 AdvancedVisualBasicLab.pdf

    107/243

    Lab Exercises

    Centre for Information Technology and Engineering, Manonmaniam Sundaranar University 43

    Ex 2:

    1. Create a ActiveX documents which has three command button withcaption

    i.

    students personal detail, ii. students course detail, iii. exit

    2. When students personal detail is clicked, it should take the user to thedocument which accept student name,address1,address2,city , state, pincode and the result should be saved in the text file called personal.txt.

    3. When students course detail is clicked, it should take the user to thedocument which accept student name, register number, subject, collegeand the result should be saved in the text file called course.txt.

    4. The following properties of user document1 are

    Controls Property Setting

    FormCommand

    NameCaptionName

    MainuserDocStudent PersonalDetails

  • 7/27/2019 AdvancedVisualBasicLab.pdf

    108/243

    Object Oriented Programming with Java

    Centre for Information Technology and Engineering, Manonmaniam Sundaranar University44

    Command

    Command

    CaptionNameCaptionName

    Command1Student Course DetailsCommand2ExitCommand3

    5. When we select the Command1, the personal details AciveX User Doc isDisplayed in below.

    6. When we select the Command2 ,the course details AcitceX UserDocument is displayed in below.

    Ex 3:

    Pre-Requisite:- You are suggested to take this lab session only after

    completion of Lecture 19

    Create a Data Project using NWIND (which is in the VB98 folder) database

    Ex 4:

    Pre-Requisite:- You are suggested to take this lab Unit only after completionof Lecture 20.

    1. Create a new standard EXE project.2. Design your form as shown below.

  • 7/27/2019 AdvancedVisualBasicLab.pdf

    109/243

    Lab Exercises

    Centre for Information Technology and Engineering, Manonmaniam Sundaranar University 45

    3. The form is Designed as per the following Specifications.

    Object Property Setting

    Form

    PictureFrame

    Frame

    Frame

    Frame

    Option()

    Option()Option()Check()

    Check()Check()Label

    Label

    Label

    CaptionNameNameCaptionName

    CaptionNameCaptionNameCaptionNameCaptionNameCaptionCaptionCaption

    CaptionCaptionCaptionNameCaptionNameCaptionName

    FontsForm1Picture1Font NameFrame1

    Font StyleFrame2Font ColorFrame3Font AttributesFrame4ArialOption1Times New RomanCourier NewItalic

    UnderlineStrikeoutWeightLblweightHeightLblheightWidthLblwidth

  • 7/27/2019 AdvancedVisualBasicLab.pdf

    110/243

    Object Oriented Programming with Java

    Centre for Information Technology and Engineering, Manonmaniam Sundaranar University46

    Label

    Label

    TextTextTextTextHscroll

    CaptionNameCaptionNameNameNameNameNameNameMaxMin

    CaptionLblcaptionRotationLblrotationTxtWeightTxtheightTxtwidthTxtcaptionHscroll13600

    4. When we click the Option buttons, then the Fonttype of the txtCaptionvalue will be displayed in the Picture1.

    5. When we click the Check Box, then the Fontstyle of the txtCaption value

    will be displayed in the Picture1.

    6. Enter the value of Weight ,Height & Width to the Text Box, then the valuewill be displayed in the Picture1.

    7. When we Scrolling the Hscroll1, the Text value is rotated in the Picture1.

    Ex 5:

    1. Create a new standard EXE project.

    2. Design your form as shown below.

    3. The form is Designed as per the following Specifications.

    Object Property Setting

  • 7/27/2019 AdvancedVisualBasicLab.pdf

    111/243

    Lab Exercises

    Centre for Information Technology and Engineering, Manonmaniam Sundaranar University 47

    Form

    Frame

    Label

    Label

    Label

    LabelLabelLabelCommand

    CommonDialo

    g

    CaptionNameCaptionNameCaptionNameCaptionNameCaptionNameNameNameNameCaptionNameName

    File InformationForm1File AttributesFrame1FileLabel1File AttributesLabel2File SizeLabel3LblfileLblattributeLblsizeGet File InfoCmdinfoCommonDialog1

    4. When we Click the Cmdinfo Button, the OpenDialog will be displayed.

    5. Then select filename, it will display the filesize, Attributes & Size will beDisplayed in the labels.

    Lab - 25(2 hrs Real Time)

    Ex1:

    Pre-Requisite:- You are suggested to take this lab session only aftercompletion of Lecture 20

    Create a DLL which have to reverse a string .

    Ex 2:

    Pre-Requisite:- You are suggested to take this lab Unit only

    after completion of Lecture 23.

    1. Create a new standard EXE project.

  • 7/27/2019 AdvancedVisualBasicLab.pdf

    112/243

    Object Oriented Programming with Java

    Centre for Information Technology and Engineering, Manonmaniam Sundaranar University48

    2. Design your form as shown below.

    3. The form is Designed as per the following Specifications.

    Object Property Setting

    Form

    Combo

    Command

    Command

    Command

    Command

    CaptionNameNameTextCaptionNameCaption

    NameCaptionNameCaptionName

    Web BrowserDemoForm1Combo1Combo1Show URLCmdURL

    Open HTMLFilesCmdHTMLStop BrowsingCmdStopEXITCmdexit

    4. In the Combo Box, we add the URL name.

    5. When we select the CmdURL Button, the selected URL of Combo Will be

    Displayed in the WebBrowser1.

    6. When we select the CmdHtml Button, the Open Dialog will be

    Displayed.,then we select the particular HTML files will be diaplayed in

    the WebBrowser1.

    7. When we select the CmdStop Button, Stop the current URL .

    8. When we select the CmdExit Button, to quit of the Program.

    Ex 3:

  • 7/27/2019 AdvancedVisualBasicLab.pdf

    113/243

    Lab Exercises

    Centre for Information Technology and Engineering, Manonmaniam Sundaranar University 49

    Pre-Requisite:- You are suggested to take this lab session only after

    completion of Lecture 23

    1. Create an Internet Explore project and make it online2. Design your form as shown below

    Ex 4:

    Pre-Requisite:- You are suggested to take this lab session only after

    completion of Lecture 24.

    1. Create a new DHTML application from the New Project and change the

    Name Property of the project to Personal.

    2. Double-click the Designer for DHTMLPage1 in the Project Explorer toopen it in the Form Designer.The ID property of DHTMLPage1 is set asHTMLFORM.

    3. Place the control in the Designer as shown in below

  • 7/27/2019 AdvancedVisualBasicLab.pdf

    114/243

    Object Oriented Programming with Java

    Centre for Information Technology and Engineering, Manonmaniam Sundaranar University50

    4. The details of controls to be included and their properties are given in thefollowing Table

    Objects Property Setting

    TextField

    TextArea

    TextField

    TextField

    TextField

    SubmitButton

    NameTabIndexNameTabIndexNameTabIndexNameTabIndexNameTabIndexCaption

    TxtName0txtAddr1txtCity2txtState3txtpin4Close

    Ex 5:

    Pre-Requisite:- You are suggested