You are on page 1of 19

1.

Development of an application to create arithmetic calculator Code Option Explicit Dim prev_num Dim curr_num Dim sign Private Sub cmdCos_Click() lblDisplay.Caption = Cos(Val(lblDisplay.Caption)) End Sub Private Sub cmdCqrt_Click() lblDisplay.Caption = Val(lblDisplay.Caption) ^ (1/3) End Sub Private Sub cmdEqual_Click() If sign = "pow" And prev_num <> "" And lblDisplay.Caption <> "" Then lblDisplay.Caption = prev_num ^ lblDisplay.Caption End If End Sub Private Sub cmdExp_Click() lblDisplay.Caption = Exp(Val(lblDisplay.Caption)) End Sub Private Sub cmdFive_Click() If lblDisplay.Caption = "" Or lblDisplay.Caption = "0" Then lblDisplay.Caption = "5" ElseIf lblDisplay.Caption <> "" Then lblDisplay.Caption = lblDisplay.Caption & "5" End If End Sub Private Sub cmdFour_Click()

If lblDisplay.Caption = "" Or lblDisplay.Caption = "0" Then lblDisplay.Caption = "4" ElseIf lblDisplay.Caption <> "" Then lblDisplay.Caption = lblDisplay.Caption & "4" End If End Sub Private Sub cmdHeight_Click() If lblDisplay.Caption = "" Or lblDisplay.Caption = "0" Then lblDisplay.Caption = "8" ElseIf lblDisplay.Caption <> "" Then lblDisplay.Caption = lblDisplay.Caption & "8" End If End Sub Private Sub cmdLn_Click() lblDisplay.Caption = Log(Val(lblDisplay.Caption)) / Log(Exp(1)) End Sub Private Sub cmdLog_Click() lblDisplay.Caption = Log(Val(lblDisplay.Caption)) End Sub Private Sub cmdNine_Click() If lblDisplay.Caption = "" Or lblDisplay.Caption = "0" Then lblDisplay.Caption = "9" ElseIf lblDisplay.Caption <> "" Then lblDisplay.Caption = lblDisplay.Caption & "9" End If End Sub Private Sub cmdOne_Click() If lblDisplay.Caption = "" Or lblDisplay.Caption = "0" Then lblDisplay.Caption = "1" ElseIf lblDisplay.Caption <> "" Then lblDisplay.Caption = lblDisplay.Caption & "1" End If End Sub

Private Sub cmdPoint_Click() If lblDisplay.Caption <> "" Then lblDisplay.Caption = lblDisplay.Caption & "." End If End Sub Private Sub cmdPower_Click() sign = "pow" If prev_num = "" Then prev_num = Val(lblDisplay.Caption) lblDisplay.Caption = "0" ElseIf curr_num = "" Then curr_num = Val(lblDisplay.Caption) lblDisplay.Caption = prev_num ^ curr_num End If End Sub Private Sub cmdSeven_Click() If lblDisplay.Caption = "" Or lblDisplay.Caption = "0" Then lblDisplay.Caption = "7" ElseIf lblDisplay.Caption <> "" Then lblDisplay.Caption = lblDisplay.Caption & "7" End If End Sub Private Sub cmdSin_Click() lblDisplay.Caption = Sin(Val(lblDisplay.Caption)) End Sub Private Sub cmdSix_Click() If lblDisplay.Caption = "" Or lblDisplay.Caption = "0" Then lblDisplay.Caption = "6" ElseIf lblDisplay.Caption <> "" Then lblDisplay.Caption = lblDisplay.Caption & "6" End If End Sub

Private Sub cmdSquare_Click() lblDisplay.Caption = Val(lblDisplay.Caption) ^ 2 End Sub Private Sub cmdTan_Click() lblDisplay.Caption = Tan(Val(lblDisplay.Caption)) End Sub Private Sub cmdThree_Click() If lblDisplay.Caption = "" Or lblDisplay.Caption = "0" Then lblDisplay.Caption = "3" ElseIf lblDisplay.Caption <> "" Then lblDisplay.Caption = lblDisplay.Caption & "3" End If End Sub Private Sub cmdTwo_Click() If lblDisplay.Caption = "" Or lblDisplay.Caption = "0" Then lblDisplay.Caption = "2" ElseIf lblDisplay.Caption <> "" Then lblDisplay.Caption = lblDisplay.Caption & "2" End If End Sub Private Sub cmdZero_Click() If lblDisplay.Caption = "" Or lblDisplay.Caption = "0" Then lblDisplay.Caption = cmdZero.Caption ElseIf lblDisplay.Caption <> "" And lblDisplay.Caption <> "0" Then lblDisplay.Caption = lblDisplay.Caption & "0" End If End Sub Private Sub Command1_Click() lblDisplay.Caption = "0" curr_num = "" prev_num = "" End Sub Interface showing the cube root of 8

2. Design an application using menus to manipulation on string like changing upper case, lower case, left move, right move, changing font style, color, size and so on. Code Private ForeColors(0 To 3) As Long Option Explicit Private Sub Label1_Click() End Sub Private Sub mnuBold_Click() rtBox2.Text = rtBox1.Text rtBox2.Font.Bold = True End Sub Private Sub mnuItalic_Click() rtBox2.Text = rtBox1.Text rtBox2.Font.Italic = True End Sub Private Sub mnuLower_Click() rtBox2.Text = LCase(rtBox1.Text) End Sub

Private Sub mnuNormal_Click() rtBox2.Text = rtBox1.Text rtBox2.Font.Bold = False rtBox2.Font.Italic = False End Sub

Private Sub mnuSize_Click() rtBox2.Text = rtBox1.Text rtBox2.Font.Size = 20 End Sub Private Sub mnuUpper_Click() rtBox2.Text = UCase(rtBox1.Text) End Sub Private Sub rtBox1_Change() End Sub Interface

3. Develop an application to display text Hello at any place the left mouse button clicked. Code Option Explicit Private Sub Form_MouseDown(Button As Integer, Shift As Integer, X As Single, Y As Single) If Button = 1 Then Form1.Print "Hello" End If End Sub Interface

4. Develop an application using data control to design inventory control fields like supplier number, supplier name, address, quantity, price and total prices Database design

Interface design

5. Prepare electricity bill using ado control fields like customer number, customer name, previous reading, current reading, units, amount.

Code Option Explicit Private Sub cmdCalculate_Click() Dim units units = Val(txtCurrReading.Text) - Val(txtPrevReading) lblUnits.Caption = units & " KW" lblAmount = units * 15 & " Frw" End Sub Private Sub cmdClear_Click()

txtNumber.Text = "" txtName.Text = "" txtPrevReading.Text = "" txtCurrReading.Text = "" lblUnits.Caption = "" lblAmount.Caption = "" End Sub Private Sub Form_Load() txtName.Enabled = False txtPrevReading.Enabled = False txtCurrReading.Enabled = False cmdCalculate.Enabled = False End Sub Private Sub txtCurrReading_Change() If txtCurrReading = "" Then cmdCalculate.Enabled = False Else cmdCalculate.Enabled = True End If End Sub Private Sub txtName_Change() If txtName = "" Then txtPrevReading.Enabled = False txtPrevReading.Text = "" txtCurrReading.Enabled = False txtCurrReading.Text = "" cmdCalculate.Enabled = False Else txtPrevReading.Enabled = True End If End Sub Private Sub txtNumber_Change() If txtNumber = "" Then txtName.Enabled = False txtName.Text = "" txtPrevReading.Enabled = False txtPrevReading.Text = "" txtCurrReading.Enabled = False txtCurrReading.Text = ""

cmdCalculate.Enabled = False Else txtName.Enabled = True End If End Sub Private Sub txtPrevReading_Change() If txtPrevReading = "" Then txtCurrReading.Enabled = False txtCurrReading.Text = "" cmdCalculate.Enabled = False Else txtCurrReading.Enabled = True End If End Sub Interface

6. Write a menu driven program to Crete Telephone Directory Maintenance Report Field Details: Custno Integer Customer Number Custname Text(25) Customer Name Doorno Text(5) Door Number Street Text(25) Name of the street City Text(10) Name of the City Pincode Integer Pincode Phno Integer Phone Number Area Text(20) Area

Code Option Explicit Dim op Private Sub mnuDelete_Click() Data1.Recordset.Delete Data1.Refresh End Sub Private Sub mnuEdit_Click() op = "e" Data1.Recordset.Edit End Sub Private Sub mnuNew_Click() op = "n" Data1.Recordset.AddNew End Sub Private Sub mnuSave_Click() If op = "n" Then Data1.Recordset.Fields("customernr") = Val(Text1.Text) Data1.Recordset.Fields("customername") = Text2.Text Data1.Recordset.Fields("doornr") = Text3.Text Data1.Recordset.Fields("street") = Text4.Text Data1.Recordset.Fields("city") = Text5.Text Data1.Recordset.Fields("pincode") = Val(Text6.Text) Data1.Recordset.Fields("area") = Text7.Text Data1.Recordset.Fields("phonenr") = Val(Text8.Text) Data1.Refresh ElseIf op = "e" Then Data1.Recordset.Update Data1.Refresh End If End Sub Interface

7. Develop an application using two tabstrips defined by the following specifications (i) On Clicking tabstrip1, a Combobox having the list of all trains departing form Chennai is to be listed (ii) After the user selects the train of his choice from the ComboBox, and clicks tabstrip2, details of the selected train such as departure time, first class fare, second class fare and unreserved class fare should be displayed in the Text Box. Also place four labels to depict the train details and a control array of four textboxes. Controls Tabstrip Tabstrip ComboBox Property Tabs(Caption) Tabs(Caption) List Settings Train List Train Details Bangalore Mail, Chennai Mail, Howrath Mail, Allepey Express

Code Private Sub cmbTrainsList_Change() End Sub Private Sub Form_Load() Text1(0).Visible = False Text1(1).Visible = False Text1(2).Visible = False Text1(3).Visible = False Label2.Visible = False Label3.Visible = False Label4.Visible = False Label5.Visible = False cmbTrainsList.Visible = False Data1.Visible = False End Sub Private Sub SSTab1_Click(PreviousTab As Integer) cmbTrainsList.Visible = True End Sub

Private Sub SSTab2_Click(PreviousTab As Integer) Text1(0).Visible = True Text1(1).Visible = True Text1(2).Visible = True Text1(3).Visible = True Label2.Visible = True Label3.Visible = True Label4.Visible = True Label5.Visible = True If cmbTrainsList.Text <> "" Then Data1.RecordSource = "select * from traindetails where trainName='" & cmbTrainsList.Text & "'" Data1.Refresh End If End Sub

Interface

8. Hjhjjhj 9. Write a clipboard program that uses cut, copy and paste operations and contains a TextBox, ComboBox, List Box and Picture Box. 10. Create an user document which has two command buttons with captions (i) Accept Train Details (ii) Accept Passenger Details. When Accept Train Details is clicked, it should take the user to the document which accepts the following details: (i) Train No (ii) Train Name (iii) Destination Point (iv) Departure Time and the results should be saved in a text file called Traindetails.txt When Accept Passenger Details is clicked, it should take the user to the document which accepts the following details: (i) Passenger Name (ii) Train Name (iii) Sex (iv) Age (v) Address (vi) Classs and the results should be saved in a text file called passsdetails.txt

Code of two command buttons on User document form Private Sub cmdAcceptPassenger_Click() frmPassenger.Show End Sub

Private Sub cmdAcceptTrain_Click() frmTrain.Show End Sub Code to create Traindetails.txt file Private Sub cmdDone_Click() Dim fileName As String Dim fs As FileSystemObject Dim ts As TextStream fileName = "C:\Users\mm\Desktop\vbassignment\Q10\Traindetails.txt" Set fs = New FileSystemObject If Not fs.FileExists(fileName) Then fs.CreateTextFile (fileName) Set ts = fs.OpenTextFile(fileName, ForAppending, True) ts.Write txtTrainNumber.Text ts.Write " " & txtTrainName.Text ts.Write " " & txtDepartureTime.Text ts.Write " " & txtDestinationPoint.Text ts.WriteLine "" ts.Close End If

Set ts = Nothing Set fs = Nothing End Sub Code to create passsdetails.txt file Private Sub cmdDone_Click() Dim fileName As String Dim fs As FileSystemObject Dim ts As TextStream fileName = "C:\Users\mm\Desktop\vbassignment\Q10\Traindetails.txt" Set fs = New FileSystemObject

If Not fs.FileExists(fileName) Then fs.CreateTextFile (fileName) Set ts = fs.OpenTextFile(fileName, ForAppending, True) ts.Write txtTrainNumber.Text ts.Write " " & txtTrainName.Text ts.Write " " & txtDepartureTime.Text ts.Write " " & txtDestinationPoint.Text ts.WriteLine "" ts.Close End If

Set ts = Nothing Set fs = Nothing End Sub Interfaces: 1. User document

2. Accept trains details Form

3. Created file, with trains details after Done button is clicked (Traindetails.txt)

4. Accept passengers details Form

5. Created file, with passengers details after Done button is clicked (passsdetails.txt)