You are on page 1of 20

CONTROL STRUCTURE TESTING: 1.

while Private Sub cmd_close_Click() Unload Me End End Sub Private Sub cmd_load_Click() f1 = "E:\ACADEMIC\LAB\VII SEM\XCS366Programs\Control Structure Testing\while.txt" Open f1 For Input As #1 Do Until EOF(1) Line Input #1, Data txt_text.Text = txt_text.Text + Data + vbNewLine Loop Close #1 cmd_test.Enabled = True cmd_load.Enabled = False End Sub Software Lab I\Additional Lab

Private Sub cmd_test_Click() flag1 = 0 flag2 = 0 f1 = "E:\ACADEMIC\LAB\VII SEM\XCS366- Software Lab - I\Additional Lab Programs\Control Structure Testing\while.txt" Open f1 For Input As #1 Do Until EOF(1) Line Input #1, Data If Mid(Data, 1, 2) = "Do" Then flag1 = 1 MsgBox "'Do' keyword is Present" If Mid(Data, 4, 5) = "While" Then MsgBox "'While' keyword is present" Else MsgBox "'While' keyword is missing" End If If Mid(Data, 10, 1) = "0" Or Mid(Data, 10, 1) = "1" Or Mid(Data, 10, 1) = "2" Or Mid(Data, 10, 1) = "3" Or Mid(Data, 10, 1) = "4" Or Mid(Data, 10, 1) = "5" Or Mid(Data, 10, 1) = "6" Or Mid(Data, 10, 1) = "7" Or Mid(Data, 10, 1) = "8" Or Mid(Data, 10, 1) = "9" Then MsgBox "Enter Valid Variable name in left hand side of expression" Else MsgBox "Variable " & (Mid(Data, 10, 1)) & " is present" End If

If Mid(Data, 12, 1) = "=" Or Mid(Data, 12, 2) = "<>" Or Mid(Data, 12, 1) = "<" Or Mid(Data, 12, 1) = ">" Or Mid(Data, 12, 2) = "<=" Or Mid(Data, 12, 2) = ">=" Then MsgBox "Operator " & (Mid(Data, 12, 2)) & " is present" Else MsgBox "Enter valid relational Operator" End If End If If Mid(Data, 1, 4) = "Loop" Then flag2 = 1 End If Loop If flag1 = 0 Then MsgBox "'Do' keyword is missing" If flag2 = 1 Then MsgBox "'Loop' keyword is present" Else MsgBox "'Loop' keyword is missing" End If Close #1 End Sub Private Sub Form_Activate() cmd_test.Enabled = False cmd_load.Enabled = True End Sub

2. dowhile Private Sub cmd_close_Click() Unload Me End End Sub Private Sub cmd_load_Click() f1 = "E:\ACADEMIC\LAB\VII SEM\XCS366- Software Programs\Control Structure Testing\do_while.txt" Open f1 For Input As #1 Do Until EOF(1) Line Input #1, Data txt_text.Text = txt_text.Text + Data + vbNewLine Loop Close #1 cmd_test.Enabled = True cmd_load.Enabled = False End Sub Lab I\Additional Lab

Private Sub cmd_test_Click() flag1 = 0 flag2 = 0 f1 = "E:\ACADEMIC\LAB\VII SEM\XCS366- Software Lab - I\Additional Lab Programs\Control Structure Testing\do_while.txt" Open f1 For Input As #1 Do Until EOF(1) Line Input #1, Data If Mid(Data, 1, 2) = "Do" Then flag1 = 1 MsgBox "'Do' keyword is present" End If If Mid(Data, 1, 4) = "Loop" Then flag2 = 1 MsgBox "'Loop' keyword is present" If Mid(Data, 6, 5) = "While" Then MsgBox "'While' keyword is present" Else MsgBox "'While' keyword is missing" End If If Mid(Data, 12, 1) = "0" Or Mid(Data, 12, 1) = "1" Or Mid(Data, 12, 1) = "2" Or Mid(Data, 12, 1) = "3" Or Mid(Data, 12, 1) = "4" Or Mid(Data, 12, 1) = "5" Or Mid(Data, 12, 1) = "6" Or Mid(Data, 12, 1) = "7" Or Mid(Data, 12, 1) = "8" Or Mid(Data, 12, 1) = "9" Then MsgBox "Enter Valid Variable name in left hand side of expression" Else

MsgBox "Variable " & (Mid(Data, 12, 1)) & " is present" End If If Mid(Data, 14, 1) = "=" Or Mid(Data, 14, 2) = "<>" Or Mid(Data, 14, 1) = "<" Or Mid(Data, 14, 1) = ">" Or Mid(Data, 14, 2) = "<=" Or Mid(Data, 14, 2) = ">=" Then MsgBox "Operator " & (Mid(Data, 14, 2)) & " is present" Else MsgBox "Enter valid relational Operator" End If End If Loop If flag1 = 0 Then MsgBox "'Do' keyword is missing" If flag2 = 0 Then MsgBox "'Loop' keyword is missing" Close #1 End Sub Private Sub Form_Activate() cmd_test.Enabled = False cmd_load.Enabled = True End Sub

3. selectcase Private Sub cmd_close_Click() Unload Me End End Sub Private Sub cmd_load_Click() f1 = "E:\ACADEMIC\LAB\VII SEM\XCS366- Software Programs\Control Structure Testing\select_case.txt" Open f1 For Input As #1 Do Until EOF(1) Line Input #1, Data txt_text.Text = txt_text.Text + Data + vbNewLine Loop Close #1 cmd_test.Enabled = True cmd_load.Enabled = False End Sub Private Sub cmd_test_Click() flag1 = 0 flag2 = 0 f1 = "E:\ACADEMIC\LAB\VII SEM\XCS366- Software Programs\Control Structure Testing\select_case.txt" Open f1 For Input As #1 Do Until EOF(1) Line Input #1, Data If Mid(Data, 1, 6) = "Select" Then flag1 = 1 MsgBox "'Select' keyword is Present" If Mid(Data, 8, 4) = "Case" Then MsgBox "'Case' keyword is present" Else MsgBox "'Case' keyword is missing" End If End If If Mid(Data, 1, 10) = "End Select" Then flag2 = 1 End If Loop If flag1 = 0 Then MsgBox "'Select' keyword is missing" If flag2 = 1 Then MsgBox "'End Select' keyword is present" Else Lab I\Additional Lab

Lab

I\Additional

Lab

MsgBox "'End Select' keyword is missing" End If Close #1 End Sub Private Sub Form_Activate() cmd_test.Enabled = False cmd_load.Enabled = True End Sub

BLACKBOX TESTING: 4.Password Validation Dim pwd As String Dim result As String Private Sub reset() Data1.Recordset.AddNew Data1.Recordset.Fields(0) = txt_username.Text Data1.Recordset.Fields(1) = txt_password.Text Data1.Recordset.Fields(2) = result Data1.Recordset.Update txt_username.Text = "" txt_password.Text = "" End Sub Private Sub cmd_report_Click() DataReport1.Refresh DataReport1.Show End Sub Private Sub cmd_validate_Click() Dim valid As Boolean valid = True pwd = txt_password.Text If Len(pwd) < 6 Then flag = 1 result = "Password Invalid. Must have atleast 6 characters" MsgBox result Call reset Exit Sub Else For I = 1 To Len(pwd) asciivalue = Asc(Mid(pwd, I, 1)) If (asciivalue < 65 Or asciivalue > 90) And (asciivalue < 97 Or asciivalue > 122) And (asciivalue < 48 Or asciivalue > 57) Then valid = False Next I End If If valid = False Then result = "Password Invalid. Special characters not allowed" MsgBox result Call reset Else result = "Password Accepted" MsgBox result

Call reset End If End Sub

PATH TESTING: 5. Odd/Even Private Sub cmd_check_Click() On Error GoTo s Number = Val(txt_input.Text) lbl_path.Caption = "Path: " lbl_path.Caption = lbl_path.Caption + "1->" If Number Mod 2 = 0 Then lbl_path.Caption = lbl_path.Caption + "2->" txt_result.Text = "Even" lbl_path.Caption = lbl_path.Caption + "3" Else lbl_path.Caption = lbl_path.Caption + "4->" txt_result.Text = "Odd" lbl_path.Caption = lbl_path.Caption + "5" End If lbl_testcase.Caption = "Test Case Pass" Call Insert Exit Sub s: lbl_testcase.Caption = "Test Case Fails" Call Insert End Sub Private Sub Insert() Data1.Recordset.AddNew Data1.Recordset.Fields(0) = txt_input.Text Data1.Recordset.Fields(1) = txt_result.Text Data1.Recordset.Fields(2) = lbl_path.Caption Data1.Recordset.Fields(3) = lbl_testcase.Caption Data1.Recordset.Update End Sub Private Sub cmd_clear_Click() txt_input.Text = "" txt_result.Text = "" End Sub Private Sub cmd_report_Click() DataReport1.Refresh DataReport1.Show End Sub Private Sub Form_Activate()

rtb_code.LoadFile ("E:\ACADEMIC\LAB\VII SEM\XCS366- Software Lab - I\Additional Lab Programs\Path Testing-Odd or Even\OddorEven.txt") End Sub

6. Prime or Not Private Sub cmd_check_Click() Dim number As Integer Dim prime As Boolean On Error GoTo s number = Val(txt_input.Text) prime = True lbl_path.Caption = "Path: " lbl_path.Caption = lbl_path.Caption + "1->" If number = 1 Then lbl_path.Caption = lbl_path.Caption + "2->" txt_result.Text = "Neither Prime Nor Composite" lbl_path.Caption = lbl_path.Caption + "3" ElseIf number = 2 Then lbl_path.Caption = lbl_path.Caption + "4->" txt_result.Text = "Prime" lbl_path.Caption = lbl_path.Caption + "5" Else lbl_path.Caption = lbl_path.Caption + "6->" For i = 2 To number / 2 lbl_path.Caption = lbl_path.Caption + "7->" If number Mod i = 0 Then lbl_path.Caption = lbl_path.Caption + "8->" prime = False lbl_path.Caption = lbl_path.Caption + "9->" End If Next i If prime = True Then lbl_path.Caption = lbl_path.Caption + "10->" txt_result.Text = "Prime" lbl_path.Caption = lbl_path.Caption + "11" Else lbl_path.Caption = lbl_path.Caption + "12->" txt_result.Text = "Not Prime" lbl_path.Caption = lbl_path.Caption + "13" End If End If lbl_testcase.Caption = "Test Case Pass" Call Insert Exit Sub s: lbl_testcase.Caption = "Test Case Fails" Call Insert End Sub

Private Sub Insert() Data1.Recordset.AddNew Data1.Recordset.Fields(0) = txt_input.Text Data1.Recordset.Fields(1) = txt_result.Text Data1.Recordset.Fields(2) = lbl_path.Caption Data1.Recordset.Fields(3) = lbl_testcase.Caption Data1.Recordset.Update End Sub Private Sub cmd_clear_Click() txt_input.Text = "" txt_result.Text = "" End Sub Private Sub cmd_report_Click() DataReport1.Refresh DataReport1.Show End Sub Private Sub Form_Activate() rtb_code.LoadFile ("E:\ACADEMIC\LAB\VII SEM\XCS366- Software Lab - I\Additional Lab Programs\Path Testing-Prime or Not\PrimeorNot.txt") End Sub

7. To add an element in an array Dim arraysize As Integer Dim a(20) As Integer Private Sub cmd_add_Click() On Error GoTo s n = Val(txt_input.Text) lbl_path.Caption = "Path: " lbl_path.Caption = lbl_path.Caption + "1->" If arraysize = 20 Then lbl_path.Caption = lbl_path.Caption + "2->" MsgBox "No more element can be added" lbl_path.Caption = lbl_path.Caption + "3" Else lbl_path.Caption = lbl_path.Caption + "4->" a(arraysize) = n lbl_path.Caption = lbl_path.Caption + "5->" lst_array.AddItem n lbl_path.Caption = lbl_path.Caption + "6->" arraysize = arraysize + 1 lbl_path.Caption = lbl_path.Caption + "7->" txt_input.Text = "" lbl_path.Caption = lbl_path.Caption + "8->" MsgBox "Array Size: " & arraysize lbl_path.Caption = lbl_path.Caption + "9" End If lbl_testcase.Caption = "Test Case Pass" Call Reset Exit Sub s: lbl_testcase.Caption = "Test Case Fails" Call Reset End Sub Private Sub Reset() Data1.Recordset.AddNew Data1.Recordset.Fields(0) = lbl_path.Caption Data1.Recordset.Fields(1) = arraysize Data1.Recordset.Fields(2) = lbl_testcase.Caption Data1.Recordset.Update End Sub Private Sub cmd_report_Click() DataReport1.Refresh

DataReport1.Show End Sub Private Sub Form_Activate() arraysize = 0 rtb_code.LoadFile ("E:\ACADEMIC\LAB\VII SEM\XCS366- Software Lab - I\Additional Lab Programs\Path Testing-Add an element in an array\AddElement.txt") End Sub

You might also like