MCA- III SEM - MCA3610-Prog Lab V - Visual Programming Lab Manual.pdf

Embed Size (px)

Citation preview

  • Annamalai UniversityDepartment of Computer Science and Engineering

    M.C.A - Third SemesterMCA3610 Programming Lab V- Visual Programming

    Lab Manual2014

  • List of ExercisesCycle I (Visual Basic)

    1. Interest Calculation2. Fibonacci Series3. Designing a Scientific Calculator using Control Array4. String Operations5. Matrix Operations6. Free Hand Writing7. Simple MDI Text Editor8. Creating and Updating a Database9. Designing a Digital Clock10. Horizontal and Vertical Scrolling for Changing Colors.11. Designing a Calendar12. Student Mark Sheet13. Database Applications using data control.

    Cycle II (Visual C++)14. Palindrome Checking15. Pattern Numbers using For Loops16. Minipaint application17. File Operations18. Mouse Interface19. ActiveX Control20. Message Box Display21. Creating and Using DLLs

    Lab InchargesA1 Batch Dr. A. GeethaA2 Batch Dr. P. Dhanalakshmi

  • Cycle IVisual Basic

  • INTEREST CALCULATIONEx. No: 1Aim:

    To implement a Visual Basic program to calculate the simple interest and compound

    interest.

    Procedure :1. Start2. Design the form with four text boxes and four command buttons. Display appropriate

    messages in label boxes3. Write the script in the click event on the simple interest and compound interest command

    buttons as follows:

    i) Set p=Text1. Textii) Set n=Te xt2. Textiii) Set r=Text3.Textiv) Si=(P*n*r)/100v) Ci=p*(1+r/100)^nvi) Text4. Text=Sivii) Text5.Text=Ci

    4. Stop

    Property Settings:Control Name Property ValueLabel Label1 Caption PrincipleLabel Label2 Caption Rate of interestLabel Label3 Caption Number of YearLabel Label4 Caption ResultText Box Text1 TextText Box Text2 TextText Box Text3 TextText Box Text4 TextCommand Command1 Caption Simple InterestCommand Command2 Caption Compound InterestCommand Command3 Caption ExitCommand Command3 Caption Clear

  • Form Design:

    Source Code:Dim p, r, n As IntegerPrivate Sub Command1_Click()p = Val(Text1.Text)r = Val(Text2.Text)n = Val(Text3.Text)Text4.Text = (p * r * n) / 100End SubPrivate Sub Command2_Click()p = Val(Text1.Text)r = Val(Text2.Text)n = Val(Text3.Text)Text4.Text = p * (1 + r / 100) ^ n

  • End SubPrivate Sub Command3_Click()Text1.Text = ""Text2.Text = ""Text3.Text = ""Text4.Text = ""End SubPrivate Sub Command4_Click()EndEnd Sub

    Output :

  • Result : Thus the Visual Basic program to calculate the simple interest and compound interesthas been executed successfully.

  • FIBONACCI SERIESEx. No : 2Aim:

    To implement a Visual Basic program to create Fibonacci series.

    Procedure :1. Start2. Design a form with all necessary controls.3. Write code in the click event of the compute command button to print the Fibonacci series4. Write appropriate code in the click events of exit and clear command buttons.5. StopProperty Settings:Control Name Property ValueLabel Label1 Caption Enter the numberLabel Label2 Caption ResultText Box Text1 TextList Box list1 CaptionCommand Command1 Caption ComputeCommand Command2 Caption ExitCommand Command3 Caption ClearForm Design:

  • Source Code:Private Sub Command1_Click()Dim f1, f2, f3, i As Integerf1 = -1f2 = 1n = Val(Text1.Text)For i = 1 To nf3 = f1 + f2List1.AddItem (f3)f1 = f2f2 = f3Next iEnd SubPrivate Sub Command2_Click()EndEnd SubPrivate Sub Command3_Click()Text1.Text = ""List1.clEnd Sub

  • Result : Thus the Visual Basic program to create Fibonacci series has been implemented andexecuted successfully.

  • DESIGNING A SCIENTIFIC CALCULATOR USING CONTROL ARRAYEx. No: 3Aim:

    To implement a Visual Basic program to create a scientific calculator using control arrays.

    Procedure :1. Start2. Place the command buttons and text boxes as shown in the form layout.3. Write the script in the click event on the command button4. For creating control array, create a command button named as command, copy the button

    and then paste it. Answer Yes to the question, you wish to create a control array. Thenpaste necessary buttons.

    5. Use the predefined function sin(), cos(), tan(), sqr() and log() for the operations sine,cosine, tangent, square root and logarithm.

    6. Use the user defined function fact() to calculate the factorial of a number7. Use the user defined function calculate() to perform all the arithmetic operations

    depending upon the priority in the variable pre (pre is the operation to be performedafter entering the second operand).

    8. For each click on the command button with caption 0-9, display the content in thetextbox2 with the corresponding caption value.

    9. For each click on operator button, append the contents of textbox2 to the textbox1 withcorresponding operator.

    10. After entering the second operand store/display the temporary result in textbox2.11. Stop.

    Property Settings:

    Control Name Property ValueText Box Text1 TextText Box Text2 TextCommand Command 1 Caption, Index 1, 1Command Command 2 Caption, Index 2, 2

  • Command Command 3 Caption, Index 3, 3Command Command4 Caption, Index 4, 4Command Command 5 Caption, Index 5, 5Command Command6 Caption, Index 6, 6Command Command 7 Caption, Index 7, 7Command Command 8 Caption, Index 8, 8Command Command 9 Caption, Index 9, 9Command Command 10 Caption .Command Command 11 Caption 0Command Command 12 Caption =Command Command 13 Caption +Command Command 14 Caption -Command Command 15 Caption *Command Command 16 Caption /Command Command 17 Caption x^2Command Command 18 Caption x^3Command Command 19 Caption x^4Command Command 20 Caption sqrtCommand Command 21 Caption ModCommand Command 22 Caption SinCommand Command 23 Caption CosCommand Command 24 Caption TanCommand Command 25 Caption 10^xCommand Command 26 Caption 1/xCommand Command 27 Caption x!Command Command 28 Caption PiCommand Command 29 Caption ClearCommand Command 30 Caption Exit

    Form Design:

  • Source Code:Dim a, b, d As IntegerDim c As StringPrivate Sub Command1_Click(Index As Integer)Select Case IndexCase 0:Unload MeCase 1:Text1.Text = Text1.Text & 1Case 2:Text1.Text = Text1.Text & 2Case 3:Text1.Text = Text1.Text & 3Case 4:Text1.Text = Text1.Text & 4Case 5:Text1.Text = Text1.Text & 5Case 6:Text1.Text = Text1.Text & 6Case 7:Text1.Text = Text1.Text & 7Case 8:Text1.Text = Text1.Text & 8Case 9:Text1.Text = Text1.Text & 9Case 10:Text1.Text = Text1.Text & "."Case 11:Text1.Text = Text1.Text & 0

  • Case 12:b = Val(Text1.Text)Text1.Text = ""If c = "+" Thend = a + bText1.Text = dElseIf c = "-" Thend = a - bText1.Text = dElseIf c = "*" Thend = a * bText1.Text = dElseIf c = "/" Thend = a / bText1.Text = dElseIf c = "mod" Thend = a Mod bText1.Text = dEnd IfCase 13:If Trim(Text1.Text) "" Thena = Val(Text1.Text)Text1.Text = ""c = "+"End IfCase 14:If Trim(Text1.Text) "" Thena = Val(Text1.Text)Text1.Text = ""c = "-"End IfCase 15:If Trim(Text1.Text) "" Thena = Val(Text1.Text)Text1.Text = ""c = "*"End IfCase 16:If Trim(Text1.Text) "" Thena = Val(Text1.Text)Text1.Text = ""c = "/"End IfCase 17:If Trim(Text1.Text) "" Then

  • a = Val(Text1.Text)Text1.Text = ""Text1.Text = a * aEnd IfCase 18:If Trim(Text1.Text) "" Thena = Val(Text1.Text)Text1.Text = ""Text1.Text = a * a * aEnd IfCase 19:If Trim(Text1.Text) "" Thena = Val(Text1.Text)Text1.Text = ""Text1.Text = a * a * a * aEnd IfCase 20:If Trim(Text1.Text) "" Thena = Val(Text1.Text)Text1.Text = ""Text1.Text = a ^ 0.5End IfCase 21:If Trim(Text1.Text) "" Thena = Val(Text1.Text)Text1.Text = ""c = "mod"End IfCase 22:If Trim(Text1.Text) "" Thena = Val(Text1.Text) * (3.14 / 180)Text1.Text = ""Text1.Text = Sin(a)End IfCase 23:If Trim(Text1.Text) "" Thena = Val(Text1.Text) * (3.18 / 180)Text1.Text = ""Text1.Text = Cos(a)End IfCase 24:If Trim(Text1.Text) "" Thena = Val(Text1.Text) * (3.18 / 180)Text1.Text = ""Text1.Text = Tan(a)End If

  • Case 25:If Trim(Text1.Text) "" Thena = Val(Text1.Text)Text1.Text = ""Text1.Text = 10 ^ aEnd IfCase 26:If Trim(Text1.Text) "" Thena = Val(Text1.Text)Text1.Text = ""Text1.Text = 1 / aEnd IfCase 27:If Trim(Text1.Text) "" Thena = Val(Text1.Text)Text1.Text = ""s = 1For i = 1 To ns = s * iNext iText1.Text = sEnd IfCase 28:If Trim(Text1.Text) "" Thena = Val(Text1.Text)Text1.Text = ""Text1.Text = a * 3.14End IfCase Else:MsgBox ("sorry....")End SelectEnd SubPrivate Sub Command29_Click()Text1.Text = ""End SubPrivate Sub Command30_Click()EndEnd Sub

  • Output :

    Result : Thus the Visual Basic program to create a scientific calculator has been implementedand executed successfully.

  • STRING OPERATIONSEx. No: 4Aim:

    To implement a Visual Basic program to perform string operations based on the user choice.

    Procedure :1. Start

    2. Read the string 1&string 2

    3. Get the choice from the user

    4. If Choice=Compare, Then

    Invoke StrComp ( ) and Print whether the strings are equal or unequal.

    5. Else If Choice=Concat , Then

    Use + operator to concatenate two strings and print the concatenated string.

    6. Else If Choice =Replace , Then

    Invoke Replace( ) and Print the resultant string.

    7. Else If Choice=Length , Then

    Invoke LEN( ) and Print the length of the given string.

    8. Else If Choice=Trim, Then

    Invoke Trin( ) to remove spaces in the string and Print the resultant string.

    9. Else If Choice=Reverse, Then

    Invoke StrReverse( ) to reverse the string and Print the reversed string.

    10. Else If Choice=Space, Then

  • Invoke Space( ) to add spaces in the string and Print the resultant string.

    11. Else If Choice=Conversion, Then

    Invoke StrConv( ) to convert the case of a given string and Print the converted string.

    12. Stop.

    Propery Settings:Control Name Property ValueLabel Label1 Caption String1Label Label2 Caption String2Label Label3 Caption ResultText Box Text1 TextText Box Text2 TextText Box Text3 TextCommand Command1 Caption ReplaceCommand Command2 Caption LengthCommand Command3 Caption SpaceCommand Command4 Caption ConversionCommand Command5 Caption ConcatenateCommand Command6 Caption CompareCommand Command7 Caption ReverseCommand Command8 Caption TrimCommand Command9 Caption ClearCommand Command10 Caption Exit

    Form Design:

  • Source Code:Private Sub Command1_Click()Dim a, b As Stringa = Text1.Textb = Text2.TextText3.Text = Replace(a, "a", b, 1, 1)End SubPrivate Sub Command10_Click()EndEnd SubPrivate Sub Command2_Click()Text3.Text = Len(Text1)End SubPrivate Sub Command3_Click()Dim a As Stringa = Text1.TextText3.Text = Space(5) + aEnd SubPrivate Sub Command4_Click()Dim a As Stringa = Text1.TextText3.Text = StrConv(a, 1)End SubPrivate Sub Command5_Click()Dim a As Stringa = Text1.Textb = Text2.TextText3.Text = a + bEnd Sub

  • Private Sub Command6_Click()Dim a As Stringa = Text1.Textb = Text2.TextText3.Text = StrComp(a, b)End SubPrivate Sub Command7_Click()Dim a As Stringa = Text1.TextText3.Text = StrReverse(a)End SubPrivate Sub Command8_Click()Dim a As Stringa = Text1.TextText3.Text = Trim(a)End SubPrivate Sub Command9_Click()Text1.Text = ""Text2.Text = ""Text3.Text = ""End SubOutput :

    Result : Thus the Visual Basic program to perform string operations has been implemented andexecuted successfully.

  • MATRIX OPERATIONSEx. No: 5Aim:

    To implement a Visual Basic program to perform matrix operations.

    Procedure :1. Start

    2. Design the form with 3 label boxes, 3 list boxes and 6 command buttons.

    3. Display appropriate messages in the label boxes.

    4. Write the script in the click events of the matrix addition, subtraction, multiplication and

    Inverse, clear and exit command buttons.

    6. Stop.

    Property Settings:Control Name Property ValueLabel Label1 Caption Matrix1Label Label2 Caption Matrix2Label Label3 Caption ResultText Box Text1 TextText Box Text2 TextText Box Text3 TextCommand Command1 Caption AdditionCommand Command2 Caption SubtractCommand Command3 Caption MultiplyCommand Command4 Caption InverseCommand Command5 Caption ClearCommand Command6 Caption Exit

  • Form Design:

    Source Code:Dim a(10, 10), b(10, 10), c(10, 10) As IntegerDim m, n, p, q, i, j, k As IntegerDim str As StringPrivate Sub Command1_Click()List1.ClearList2.ClearList3.Clearl1:m = InputBox("Enter m value")n = InputBox("Enter n value")p = InputBox("Enter p value")q = InputBox("Enter q value")If m p And n q Then

  • MsgBox ("Addition Operation not possible")GoTo l1End IfinainbFor i = 1 To mstr = ""For j = 1 To nc(i, j) = Val(a(i, j)) + Val(b(i, j))str = str & c(i, j) & " "Next jList3.AddItem (str)Next iEnd SubPrivate Sub ina()For i = 1 To mstr = " "For j = 1 To na(i, j) = InputBox("Enter a matrix rowwise")str = str & a(i, j) & " "Next jList1.AddItem (str)Next iEnd SubPrivate Sub inb()For i = 1 To pstr = " "For j = 1 To qb(i, j) = InputBox("Enter B matrix rowwise")str = str & b(i, j) & " "Next jList2.AddItem strNext iEnd SubPrivate Sub Command2_Click()List1.ClearList2.ClearList3.Clearl1:m = InputBox("Enter m value")n = InputBox("Enter n value")p = InputBox("Enter p value")q = InputBox("Enter q value")If m p And n q ThenMsgBox (" Sub Operation not possible")

  • GoTo l1End IfinainbFor i = 1 To mstr = ""For j = 1 To nc(i, j) = a(i, j) - b(i, j)str = str & c(i, j) & " "Next jList3.AddItem strNext iEnd SubPrivate Sub Command3_Click()List1.ClearList2.ClearList3.Clearl1:m = InputBox("Enter m value")n = InputBox("Enter n value")p = InputBox("Enter p value")q = InputBox("Enter q value")If m p And n q ThenMsgBox ("Multi operation not possible")GoTo l1:End IfinainbFor i = 1 To mstr = " "For j = 1 To qc(i, j) = 0For k = 1 To pc(i, j) = c(i, j) + a(i, k) * b(k, j)Next kstr = str & c(i, j) & " "Next jList3.AddItem strNext iEnd SubPrivate Sub Command4_Click()List1.ClearList2.ClearList3.Clear

  • Label2.Visible = FalseList2.Visible = Falsem = InputBox("Enter m value")n = InputBox("Enter n value")inaFor i = 1 To mstr = ""For j = 1 To nc(i, j) = Val(a(j, i))str = str & c(i, j) & " "Next jList3.AddItem strNext iEnd SubPrivate Sub Command5_Click()List1.ClearList2.ClearList3.ClearEnd SubPrivate Sub Command6_Click()EndEnd SubOutput :

    Result : Thus the Visual Basic program to perform matrix operations has been implemented andexecuted successfully.

  • FREEHAND DRAWINGEx. No: 6Aim:

    To implement a Visual Basic program to create a free hand drawing.

    Procedure :1. Start2. Design the form by adding a frame, 4 command buttons, 1 picture box and 1 combo

    box3. Write the script in the click events of size, color, clear and exit command buttons.4. On click and drag on the picture box lines are drawn by following mouse pointer.5. On click and drag on the frame both (picture box and frame) are moved to the mouse

    pointer direction.6. On clicking clear the contents of picture box should be cleared

    Property Settings :Control Name Property ValueCommand Command1 Caption SizeCommand Command2 Caption ColorCommand Command3 Caption ClearCommand Command4 Caption ExitPicture box Picture1Combo box Combo1

    Form Design :

  • Source Code :Dim clr As OLE_COLORDim i As IntegerPrivate Sub Command1_Click()Combo1.Visible = TrueEnd SubPrivate Sub Command2_Click()cd1.ShowColorclr = cd1.ColorEnd SubPrivate Sub Command3_Click()Picture1.ClsEnd SubPrivate Sub Command4_Click()Unload MeEnd SubPrivate Sub Form_Load()clr = vbBlackFor i = 1 To 15Combo1.AddItem (i)Next iEnd SubPrivate Sub Picture1_MouseDown(Button As Integer, Shift As Integer, x As Single, y As Single)Combo1.Visible = FalseIf Button = vbLeftButton ThenPicture1.PSet (x, y), clrPicture1.DrawWidth = Combo1.TextElseIf Button = vbRightButton ThenPicture1.DrawWidth = 1Picture1.PSet (x, y), Combo1.Text * 10End IfEnd Sub

  • Private Sub Picture1_MouseMove(Button As Integer, Shift As Integer, x As Single, y As Single)If Button = vbLeftButton ThenPicture1.PSet (x, y), clrPicture1.DrawWidth = Combo1.TextElseIf Button = vbRightButton ThenPicture1.DrawWidth = 1Picture1.Circle (x, y), Combo1.Text * 10End IfEnd SubOutput :

    Result : Thus the Visual Basic program to create a free hand drawing has been implementedand executed successfully.

  • SIMPLE MDI TEXT EDITOREx. No. 7Aim:

    To create a Visual Basic application with MDI features and text editing capabilities.

    Procedure :1. Place the label, rich text box, and combo box as shown in form layout.2. Click tools -> menu editor to open the menu editor.3. Give the required caption name in the menu editor window and use left and right

    arrow buttons to place the menu item as sub menu and use up and down arrows toarrange it in a sequence.

    4. Create three menus with lists as shown belowMenu Sub-MenuCaption Caption NameFile open open

    Save saveSave as saveasPrint printExit exit

    Edit Cut cutCopy copyPaste paste

    Format Bold boldItalic italicUnderline underlineStrikethrough Strikethrough

    5. To invoke components, click project -> components then select Microsoft rich textbox control, Microsoft common dialog box control from components window.

    6. Load the combo boxes with some font names and size. By selecting the combo boxesthe font and size of the text are altered respectively.

    7. By selecting the operations on menus the corresponding tasks should be performedusing common dialog box and clipboard events.

  • Rich textbox Form design:-

    MDI Form design:-1. Microsoft common dialog control 6.02. Microsoft Rich textbox control 6.03. Microsoft windows common control 6.0

    Create the Menu edit procedure Add image box from the left panel Create 6 image using box paint for new, open, save, cut, copy and paste

    respectively Select the image box and double click the properties present in the right pane Select images tab Click insert pictures command button Select the pictures from the desired location Click Ok Double click toolbar icon from left pane Select toolbar on form(below the menu bar of your form) Double click custom from properties(on right pane)

  • Select button tab Click insert button(6 times)and also number the image text field with

    corresponding index number Select general tab Select imagelist box Select the imagelist1 that you create before Toolbor & common dialog control Place Imagelist on MDI form Add a common dialog box and name it as comdg

    MDI Form :

    Source code:-MDI Form:-Private Sub Clear_Click()rt.ClearEnd SubPrivate Sub Copy_Click(Index As Integer)Clipboard.SetText (MDIForm1.ActiveForm.ActiveControl.SelText)End SubPrivate Sub Cut_Click()Clipboard.SetText (MDIForm1.ActiveForm.ActiveControl.SelText)MDIForm1.ActiveForm.ActiveControl.SelText = " "End Sub

  • Private Sub Exit_Click()EndEnd SubPrivate Sub MDIForm_Load()Static n As IntegerEnd SubPrivate Sub New_Click()Static n1 As Integerfilenam = " "n1 = n1 + 1Dim nf As New Form1nf.ShowMDIForm1.ActiveForm.Caption = "untitled" + Str(n1)End SubPrivate Sub open_Click()cdm1.ShowOpenfilenam = ""n1 = n1 + 1Dim nf As New Form1nf.Shownf.rt.FileName = cdm1.FileNamefilenam = cdm1.FileNameEnd SubPrivate Sub past_Click()MDIForm1.ActiveForm.ActiveControl.SelText = Clipboard.GetText()End SubPrivate Sub Save_Click()If Len(filenam) 0 ThenMDIForm1.ActiveForm.ActiveControl.SaveFile (filenam)ElseCall Saveas_ClickEnd IfEnd SubPrivate Sub Saveas_Click()cdm1.ShowSaveMDIForm1.ActiveForm.ActiveControl.SaveFile (cdm1.FileName)filenam = cdm1.FileNameEnd SubPrivate Sub Toolbar1_ButtonClick(ByVal Button As MSComctlLib.Button)

  • If (Button.Index = 1) ThenCall New_ClickElseIf (Button.Index = 2) ThenCall open_ClickElseIf (Button.Index = 3) ThenCall Save_ClickElseIf (Button.Index = 4) ThenCall Cut_ClickElseIf (Button.Index = 5) ThenCall Copy_ClickElseIf (Button.Index = 6) ThenCall past_ClickEnd IfEnd SubRich text box :-Private Sub rt_mousedown(Button As Integer, shift As Integer, x As Single, y As Single)If Button = 2 ThenPopupMenu EditEnd IfEnd Sub

    Output :

    Result : Thus a Visual Basic application has been created with MDI features and text editingcapabilities.

  • CREATING AND UPDATING A DATABASEEx. No: 8Aim:

    To create a Visual Basic application for performing basic functions in a database.

    Procedure : Create a table as follows

    Add->Ins-> Visual data manager File->New->Microsoft access->Version7.0 MDB

    Save the file

  • Right click on properties and select New table

    Enter table name Click Add field button Enter the name and select the desired type in type combo box

  • Click Ok Similarly enter all the field names and their corresponding type When finished click close

    Click Build the table

  • Click Add button

    Double click the table name Click Add and enter the corresponding fielding details and update it Similarly enter all the records Click utility option data form designer

  • Click the>>button in the middle and then click Build the form

  • Click the project option and select project1 properties to change the startup object

    Source code:-

    Private Sub cmdAdd_Click()Data1.Recordset.AddNewEnd Sub

    Private Sub cmdDelete_Click()'this may produce an error if you delete the last

  • 'record or the only record in the recordsetData1.Recordset.DeleteData1.Recordset.MoveNextEnd Sub

    Private Sub cmdRefresh_Click()'this is really only needed for multi user appsData1.RefreshEnd Sub

    Private Sub cmdUpdate_Click()Data1.UpdateRecordData1.Recordset.Bookmark = Data1.Recordset.LastModifiedEnd Sub

    Private Sub cmdClose_Click()Unload MeEnd Sub

    Private Sub Data1_Error(DataErr As Integer, Response As Integer)'This is where you would put error handling code'If you want to ignore errors, comment out the next line'If you want to trap them, add code here to handle themMsgBox "Data error event hit err:" & Error$(DataErr)Response = 0 'throw away the errorEnd Sub

    Private Sub Data1_Reposition()Screen.MousePointer = vbDefaultOn Error Resume Next'This will display the current record position'for dynasets and snapshotsData1.Caption = "Record: " & (Data1.Recordset.AbsolutePosition + 1)'for the table object you must set the index property when'the recordset gets created and use the following line'Data1.Caption = "Record: " & (Data1.Recordset.RecordCount *(Data1.Recordset.PercentPosition * 0.01)) + 1End Sub

    Private Sub Data1_Validate(Action As Integer, Save As Integer)

  • 'This is where you put validation code'This event gets called when the following actions occurSelect Case ActionCase vbDataActionMoveFirstCase vbDataActionMovePreviousCase vbDataActionMoveNextCase vbDataActionMoveLastCase vbDataActionAddNewCase vbDataActionUpdateCase vbDataActionDeleteCase vbDataActionFindCase vbDataActionBookmarkCase vbDataActionCloseEnd SelectScreen.MousePointer = vbHourglassEnd Sub

    Output :

    Result : Thus a Visual Basic application has been created to perform basic functions in adatabase.

  • DESIGNING A DIGITAL CLOCKEx. No: 9Aim:To implement a Visual Basic program to design a digital clock.

    Algorithm:1. Start2. Design the form with 1 frame, 2 label boxes, 1 command box and 1 timer control.3. Display appropriate messages in the label boxes.4. Write the script for timer control and click event of the exit command button5. Stop

    Control Name Property Value

    Label box label1 TextLabel box label2 TextCommand Command1 Caption ExitFrame Frame1 Caption Digital ClockTimer Timer1 Interval 1000

    Form Design:

  • Source code:Private Sub Command1_Click()EndEnd SubPrivate Sub Timer1_Timer()Label1.Caption = TimeLabel2.Caption = DateEnd SubOutput :

    Result : Thus a Visual Basic program to design a digital clock has been implemented and

    executed successfully.

  • HORIZONTAL AND VERTICAL SCROLLING FOR CHANGING COLORSEx. No: 10Aim:To implement a Visual Basic program to use the vertical and horizontal scroll bars forchanging colors.

    Procedure :1. Start2. Design the form with 2 vertical, 1 horizontal scroll bar, 1 shape and 10 label boxes.3. Set the properties as shown in the form layout.4. Write the script for vertical and horizontal scroll bars.5. Display appropriate messages in the label boxes.6. Stop

    Form Design:-

  • Source code:

    Dim r, g, b As Integer

    Private Sub Command1_Click()EndEnd Sub

    Private Sub HScroll1_Change()r = VScroll1.Valueg = VScroll2.Valueb = HScroll1.ValueShape1.BackColor = RGB(r, g, b)Label10.Caption = HScroll1.ValueEnd Sub

    Private Sub VScroll1_Change()r = VScroll1.Valueg = VScroll2.Valueb = HScroll1.ValueShape1.BackColor = RGB(r, g, b)Label6.Caption = VScroll1.ValueEnd Sub

    Private Sub VScroll2_Change()r = VScroll1.Valueg = VScroll2.Valueb = HScroll1.ValueShape1.BackColor = RGB(r, g, b)

  • Label8.Caption = VScroll2.ValueEnd Sub

    Output :

    Result : Thus a Visual Basic program has been implemented to use horizontal and vertical barsfor changing colors and executed successfully.

  • DESIGNING A CALENDAREx. No : 11Aim:To implement a Visual Basic program to design a calendar.

    Procedure :1. Start2. Design the form with 1 calendar control and two label boxes.3. Display appropriate messages in the Label boxes.4. Stop

    Form design:-

    Select the control as follows:Project -> components (ctrl+t) ->Select microsoft calendar control 6.0

  • Source Code:-Private Sub Timer1_Timer()Label2.Caption = DateTime.TimeEnd SubOutput :

    Result : Thus a Visual Basic program to create a calendar has been implemented and executed .

  • STUDENT MARK SHEETEx. No :12Aim:

    To implement a Visual Basic program to create a student mark sheet.

    Procedure :1. Start2. Design the form with necessary label boxes, text boxes and command buttons.3. Set the properties for all the controls.4. Write the script in the click event of the submit, marks, average, result, overall point,

    reset and exit command buttons.5. Display appropriate messages in the label boxes.6. Stop

    Form Design:

  • Source Code:-

    Dim a, b, c, p, q, r, s, u, d, h As IntegerDim avg As VariantPrivate Sub Command1_Click()a = Val(Text5.Text) + Val(Text8.Text) + Val(Text11.Text) + Val(Text14.Text) +Val(Text17.Text) + Val(Text20.Text)Text26.Text = ab = Val(Text6.Text) + Val(Text9.Text) + Val(Text12.Text) + Val(Text15.Text) +Val(Text18.Text) + Val(Text21.Text) + Val(Text24.Text)Text27.Text = bText7.Text = Val(Text5.Text) + Val(Text6.Text)p = Text7.TextIf (Text7.Text >= 90 And Text7.Text = 80 And Text7.Text = 70 And Text7.Text = 60 And Text7.Text

  • ElseIf (Text7.Text >= 55 And Text7.Text = 50 And Text7.Text
  • End IfText16.Text = Val(Text14.Text) + Val(Text15.Text)s = Text16.TextIf (Text16.Text >= 90 And Text16.Text = 80 And Text16.Text = 70 And Text16.Text = 60 And Text16.Text = 55 And Text16.Text = 50 And Text16.Text
  • Text34.Text = "A"ElseIf (Text22.Text >= 70 And Text22.Text = 60 And Text22.Text = 55 And Text22.Text = 50 And Text22.Text
  • If p < 50 Or q < 50 Or r < 50 Or s < 50 Or u < 50 Or d < 50 Or h < 50 ThenLabel39.Caption = "re appear"ElseIf (Label30.Caption >= 90 And Label30.Caption = 80 And Label30.Caption = 70 And Label30.Caption = 60 And Label30.Caption = 55 And Label30.Caption = 50 And Label30.Caption
  • Text19.Text = ""Text20.Text = ""Text21.Text = ""Text22.Text = ""Text23.Text = ""Text24.Text = ""Text25.Text = ""Text26.Text = ""Text27.Text = ""Text28.Text = ""Text29.Text = ""Text30.Text = ""Text31.Text = ""Text32.Text = ""Text33.Text = ""Text34.Text = ""Text35.Text = ""Label28.Caption = ""Label29.Caption = ""Label30.Caption = ""Label39.Caption = ""End SubPrivate Sub Command3_Click()EndEnd SubPrivate Sub Timer1_Timer()Label9.Caption = TimeLabel10.Caption = DateEnd Sub

  • Output :

    Result : Thus a Visual Basic program to create a student database has been implemented andexecuted successfully.

  • DATABASE APPLICATION USING DATA CONTROLEx. No: 13Aim:

    To implement a Visual Basic program to create a database using data control andimplement it in an application.Procedure :

    1. Start -> programs->Microsoft Visual Studio 6.0-> Microsoft Visual Basic2. Select File->New->Standard.exe. Give project name and then choose empty project

    button->finish->ok.3. Design the form with 4 label boxes, 4 text boxes and 9 command buttons.4. Display appropriate messages in the label boxes.5. Write script in the Click events of the insert, edit, delete, save, exit, first, next, previous

    and last command buttons and set the properties.6. Stop.

    Source Code :Dim db As DatabaseDim rs As RecordsetDim rs1 As RecordsetDim sql As StringPrivate Sub Command3_Click()Set rs1 = db.OpenRecordset("select count(*) from student1 where Rollno=" & Val(Text1.Text))If Text1.Text = "" ThenMsgBox "enter a valid roll number"Exit SubEnd IfIf rs1(0) = 0 ThenMsgBox ("there are no records with this roll number")

  • Exit SubEnd Ifdb.Execute ("delete from student1 where rollno=" &Val(Text1.Text))MsgBox ("record deleted")End SubPrivate Sub Command4_Click()If Command1.Enabled = False Thensql = " insert into student1 values(" &CInt(Text1.Text) & ",'" & Text2.Text & "','" & Text3.Text& "'," &CDbl(Text4.Text) & ")"MsgBoxsqldb.Execute (sql)MsgBox ("record inserted")Command1.Enabled = TrueEnd IfIf Command2.Enabled = False Thensql = "update student1 set name='" & Text2.Text & " ',address='" & Text3.Text &"',mobilenumber=" &CDbl(Text4.Text) & " where (RollNO= " &CInt(Txt_ROllNo.Text) & ")"MsgBoxsqldb.Execute (sql)MsgBox ("record updated")Command2.Enabled = TrueEnd IfEnd SubPrivate Sub Command6_Click()rs.MoveFirstShow_DataEnd SubPrivate Sub Command7_Click()

  • rs.MoveNextShow_DataEnd SubPrivate Sub Command8_Click()rs.MovePreviousShow_DataEnd SubPrivate Sub Command9_Click()rs.MoveLastShow_DataEnd SubPrivate Sub Form_Load()Set db = OpenDatabase("D:\aaa.mdb", True)Set rs = db.OpenRecordset("student", dbOpenDynaset)rs.MoveFirstEnd SubPrivate Sub Show_Data()If rs.EOF Thenrs.MoveLastEnd IfIf rs.BOF Thenrs.MoveFirstEnd IfText1.Text = rs(0)Text2.Text = rs(1)Text3.Text = rs(2)Text4.Text = rs(3)

  • End SubPrivate Sub Clear_Controls()Text1.Text = ""Text2.Text = ""Text3.Text = ""Text4.Text = ""End SubOutput :

    Result : Thus the Visual Basic program to create a database using data control has beenimplemented and executed successfully.

  • Cycle IIVisual C++

  • PALINDROME CHECKINGEx. No: 14Aim:To implement a VC++ program to find whether a given string is a palindrome or not.

    Procedure :1. Start2. Create a MFC application by selecting, File -> New -> MFC .exe -> Dialog Based -> Finish.3. Place the Static texts, edit boxes, command Buttons as shown in the form Layout.4. On clicking the palindrome Button, display whether the given string is palindrome or not.5. Stop.Property SettingsControl Name Property ValueButton button1 caption Is PalindromeButton button2 caption ExitMember Variables:Control Category Type Variable NameIDC_EDIT1 VALUE Cstring m_edit1

    Form Design :

  • Source code:-// prog13 message handlersvoid prog13::OnButton1(){CString s;UpdateData(true);s=m_edit1;s.MakeReverse();if(s==m_edit1)SetDlgItemText(IDC_EDIT2,m_edit1+"is palindrome");elseSetDlgItemText(IDC_EDIT2,m_edit1+"is not palindrome");}void prog13::OnButton2(){exit(0);}Output :

    Result : Thus a VC++ program to check whether a given string is a palindrome or not isimplemented and executed successfully.

  • PATTERN NUMBERS USING FOR LOOPSEx. No :15Aim:To implement a VC++ program to print pattern numbers.

    Procedure:1. Start2. Create a form with one list box and 2 command buttons3. Write source code for the click events of compute button to print pattern numbers

    and appropriate code for exit button.4. StopProperty SettingsControl Name Property ValueButton button1 caption ComputeButton button2 caption ExitMember Variables:Control Category Type Variable NameIDC_LIST1 Control CList m_list1

    Form Design :

  • Source code:-void prog14::OnButton1(){int i,j;CString st,str;UpdateData(true);for(i=1;i
  • str=" ";for(j=1;j
  • MINIPAINT APPLICATIONEx. No: 16Aim:To implement a VC++ program to handle menus on a window.

    Procedure:1. Start2. Create menus as follows.

  • 3. Create a window as follows.

  • 4. Write code for the created menu items.5. Stop.

    Source code:// CProg15View message handlersint s,b,p;void CProg15View::OnShapesEllipse(){s=1;Invalidate();}void CProg15View::OnShapesLine(){s=2;Invalidate();}void CProg15View::OnShapesRectangle(){s=3;Invalidate();}void CProg15View::OnColorPenRed(){p=1;Invalidate();}void CProg15View::OnColorPenGreen(){p=2;Invalidate();}void CProg15View::OnColorPenBlue(){p=3;Invalidate();}void CProg15View::OnColorBrushRed(){b=1;Invalidate();}void CProg15View::OnColorBrushGreen(){

  • b=2;Invalidate(); }void CProg15View::OnColorBrushBlue(){b=3;Invalidate();}void CProg15View::OnPaint(){

    CPaintDC dc(this); // device context for paintingCPen P;CBrush B;switch(p){case 1:

    P.CreatePen(PS_SOLID,2,RGB(255,0,0));break;

    case 2:P.CreatePen(PS_SOLID,2,RGB(0,255,0));break;

    case 3:P.CreatePen(PS_SOLID,2,RGB(0,0,255));break;

    }switch(b){case 1:

    B.CreateSolidBrush(RGB(255,0,0));break;

    case 2:B.CreateSolidBrush(RGB(0,255,0));break;

    case 3:B.CreateSolidBrush(RGB(0,0,255));break;

    }dc.SelectObject(&P);dc.SelectObject(&B);switch(s){case 1:

    dc.MoveTo(100,100);dc.LineTo(200,200);break;

  • case 2:dc.Rectangle(80,80,160,160);break;

    case 3:dc.Ellipse(30,20,80,80);break;

    }}Output :

  • Result : Thus a Visual C++ program to handle menus in a window has been implemented andexecuted successfully.

  • FILE OPERATIONSEx. No: 17Aim:To implement a Visual C++ program to copy files.

    Procedure:1. Start2. Create a MFC application by selecting, File -> New -> MFC .exe -> Dialog Based -> Finish.3. Place 2 label boxes, 2 edit boxes and 2 command buttons as shown in the form layout.4. Display appropriate messages in the label boxes.5. On clicking the copy command button, write code to copy the contents of source file to

    destination file.6. Write code for the exit command button.7. Stop.

    Property SettingsControl Name Property ValueButton button1 caption CopyButton button2 caption ExitControl Category Type Variable NameIDC_EDIT1 Value CString m_edit1IDC_EDIT2 Value CString m_edit2Form Design:

  • Source Code:// prog16 message handlersvoid prog16::OnButton1(){char szbuffer[100];UINT nACTUAL=0, pos=0;CFile myfile, myfile1;UpdateData(true);myfile.Open(m_edit1,CFile::modeReadWrite);myfile.Open(m_edit2,CFile::modeCreate|CFile::modeReadWrite);while(1){

    myfile.Seek(pos,CFile::begin);nACTUAL=myfile.Read(szbuffer,100);myfile.Write(szbuffer,100);pos=pos+nACTUAL;if(nACTUAL==0){

    MessageBox("file copied");exit(0);

    }}}void prog16::OnButton2(){exit(0);}

  • Output :

    Result : Thus a Visual C++ program to copy files has been implemented and executedsuccessfully.

  • MOUSE INTERFACEEx. No: 18Aim:To implement a VC++ program for mouse interface.

    Procedure:1. Create a MFC application by selecting, File -> New -> MFC .exe -> Dialog Based ->

    Finish.2. Place the edit box, Static Text and command buttons as shown in the form layout.3. Write code to count the number of mouse clicks by counting the mouse events.4. Stop

    Control Name Property ValueButton button1 Caption ExitEvents:OnRButtonDown(), OnLButtonDown, OnLButtonDblClk(), OnRButtonDblClk().SetDlgItemInt().Form Design :

  • Source code :int count1,count2;void prog17::OnLButtonDblClk(UINT nFlags, CPoint point){count1++;SetDlgItemInt(IDC_EDIT1,count1);

    CFormView::OnLButtonDblClk(nFlags, point);}void prog17::OnLButtonDown(UINT nFlags, CPoint point){count1++;SetDlgItemInt(IDC_EDIT1,count1);

    CFormView::OnLButtonDown(nFlags, point);}void prog17::OnRButtonDblClk(UINT nFlags, CPoint point){count2++;SetDlgItemInt(IDC_EDIT2,count2);

    CFormView::OnRButtonDblClk(nFlags, point);}void prog17::OnRButtonDown(UINT nFlags, CPoint point){

    count2++;SetDlgItemInt(IDC_EDIT2,count2);

    CFormView::OnRButtonDown(nFlags, point);}void prog17::OnButton1(){exit(0);}

  • Output :

    Result : Thus a Visual C++ program for mouse interface has been implemented and executedsuccessfully.

  • ACTIVEX CONTROLEx. No: 19Aim:To implement a VC++ program to insert an ActiveX control in an application.

    Procedure:1. Start2. Create a MFC application by selecting, File -> New -> MFC .exe -> Dialog Based ->

    Finish.3. Place the ActiveX object and buttons as shown in the form layout.4. To insert the Active X Calendar, right Click on the form -> Insert Active X Control ->

    Calendar Control 12.0.5. On clicking the OK button, display a Message box.6. Stop

    Control Name Property ValueButton button1 Caption MessageButton button2 Caption OKEvents:OnButton()Form Design:

  • Source code :oid prog18::OnButton1(){MessageBox("ActiveX controls");}void prog18::OnButton2(){exit(0);}

  • Output :

    Result : Thus a Visual C++ program to insert an ActiveX control has been implemented andexecuted successfully.

  • MESSAGE BOX DISPLAYEx. No: 20Aim:

    To implement VC++ program to create a message box.Procedure:

    1. Start2. Create a WIN32 application by selecting, File -> New -> Win32 .exe -> Finish.3. To include a new C File, file -> New -> C Source File.4. Read the free Memory Available in the system.5. Store it in a buffer.6. Display the Message box.7. Stop

    Form Design :

  • Source Code:-#include "stdafx.h"int APIENTRY WinMain(HINSTANCE hInstance,HINSTANCE hPrevInstance,LPSTRlpCmdLine, int ncmdshow){

    DWORD dwmemavail;char szbuffer[80];dwmemavail=GetFreeSpace(0);wsprintf(szbuffer,"Memory available:%lu",dwmemavail);MessageBox(NULL,szbuffer,"GLOBEL MEM",MB_OK);return 0;

    }Output :

    Result : Thus the Visual C++ program to display a message box has been implemented andexecuted successfully.

  • CREATING AND USING DLLSEx. No: 21Aim :

    To implement VC++ program to create and use DLL.

    Procedure :

    To create DLL1. Create a project MyDll from File->New, select the MFCAppWizard(dll) and the next step

    select Regular DLL using shared MFC DLL2. In the class view tab on the workspace right click on MyDll classes and choose New Class, a

    dialog will appear, now choose the class type as Generic class and type the class name asCMyClass and press OK.

    3. In the class view tab right click on CMyClass and select Add Member Function

    Function type Function Declaration

    CString SayHello(CString strName)

    4. In the File view tab on the workspace, open the Header file folder and double click on theMyClass.h and add __declspec(dllexport) infront of all functions that are used forexternal application

    5. In the File view tab on the workspace, open the MyClass.cpp from source file folder andtype the code.

    6. Compile & Build the project

    To create a new application that use the DLL.1. Create a project named TestDll from File->New , select the MFCAppwizard(exe) , selectDialog based application and accept the default values for the next step and finish it.

    2. A dialog will appear.Design the dialog window using necessary controls as follows

  • 3. Open class wizard from the view menu, click member variable tab and chooseIDC_EDIT1 and click add member variable and type as follows.

    Variable name Type Categorym_edit Value Cstring

    4. Double click the OK button on the dialog window, then the OnOk function will begenerated.

    5. In the file view tab on the work space window, open the TestDllDlg.h to includeMyClass.h and to declare object of that class and add the codes and include

    #include ..\MyDll\MyClass.h6. Select the Project->Settings->Link and in the Object/library modules enter a path to the

    DLL library file as follows...\MyDll\Debug\MyDll.lib

    7. Copy the MyDll.dll file from MyDll\Debug folder and paste it into the TestDll\Debugfolder.

    8. Build and execute the project

  • Source code//MyClass.hclassCMyClass{public:__declspec(dllexport)CStringSayHello(CStringstrName);

    __declspec(dllexport)CMyClass();__declspec(dllexport)virtual ~CMyClass();

    };//MyClass.cppCStringCMyClass::SayHello(CStringstrName){ return "HAI "+strName;}

    TESTDLL//TestDllDlg.h#include"..\MyDll\MyClass.h" classCTestDllDlg : public CDialog{public:

    CMyClassobjMyClass;CTestDllDlg(CWnd* pParent = NULL);

    };//TestDllDlg.cppvoidCTestDllDlg::OnOK( ) {

    UpdateData(true);CStringstr=objMyClass.SayHello(m_strText);AfxMessageBox(str);CDialog::OnOK();

    }

  • Output :

    Result : Thus a Visual C++ program to create and use DLL has been implemented andexecuted successfully.