Monday, February 23, 2015

Write a visual basic program for stopwatch

Write a visual basic program for stopwatch:-

Design Window:-


Code:-

Dim starttime As Date
Dim s As Date
Private Sub Reset_Click()
Timer1.Enabled = False
starttime = Now
Timer1.Enabled = True
End Sub

Private Sub Start_Click()
starttime = Now
Timer1.Enabled = True
End Sub

Private Sub Stop_Click()
Timer1.Enabled = False
Label1.Caption = ""
End Sub
Private Sub Form_Load()
Timer1.Enabled = False
End Sub

Private Sub Pause_Click()
If Pause.Caption = "Pause" Then
Timer1.Enabled = False
s1 = Label1.Caption
Pause.Caption = "Play"
End If
If Pause.Caption = "Play" Then
    Label1.Caption = s1
    Timer1.Enabled = True
End If
End Sub

Private Sub Timer1_Timer()
Label1.Caption = Format$(Now - starttime, "hh:mm:ss:ms")
End Sub

============================================
OUTPUT



Write a visual program to calculate average using runtime textbox

Write a visual program to calculate average using runtime text-box
Design window:-

Code:

Dim t1 As TextBox
Dim t2 As TextBox
Dim t3 As TextBox
Dim t4 As TextBox
Dim a As Integer
Dim b As Integer
Dim c As Integer

Private Sub cmdClear_Click()
t1.Text = ""
t2.Text = ""
t3.Text = ""
t4.Text = ""
t1.SetFocus
End Sub

Private Sub cmdDisplay_Click()
 a = Val(t1.Text)
 b = Val(t2.Text)
 c = Val(t3.Text)
 t4.Text = (a + b + c) / 3
End Sub

Private Sub cmdExit_Click()
Unload Me
End Sub
Private Sub Form_Activate()
    Set t1 = Controls.Add("VB.TextBox", "t1")
    t1.Visible = True
    t1.Height = 600
    t1.Width = 2200
    t1.Top = 100
    t1.Left = 3200
    t1.SetFocus
           
    Set t2 = Controls.Add("VB.TextBox", "t2")
    t2.Visible = True
    t2.Height = 600
    t2.Width = 2200
    t2.Top = 800
    t2.Left = 3200
       
    Set t3 = Controls.Add("VB.TextBox", "t3")
    t3.Visible = True
    t3.Height = 600
    t3.Width = 2200
    t3.Top = 1500
    t3.Left = 3200
       
    Set t4 = Controls.Add("VB.TextBox", "t4")
    t4.Visible = True
    t4.Height = 600
    t4.Width = 2200
    t4.Top = 2200
    t4.Left = 3200
End Sub

=============================================
OUTPUT


Write a Visual Basic program to implement the find and replace dialogue box for text-box

Design an application in Visual Basic to implement the find and replace dialogue box for text-box control with multiple line of text with 3 option buttons and check boxes

Design window of form:-

Code:-
Dim txt As String
Dim s, l, r As Integer
Private Sub Check1_Click(Index As Integer)
    If Check1(0).Value = 1 Then
        Text1.Font.Bold = True
    Else
        Text1.Font.Bold = False
    End If
    If Check1(1).Value = 1 Then
        Text1.Font.Italic = True
    Else
        Text1.Font.Italic = False
    End If
    If Check1(2).Value = 1 Then
        Text1.Font.Underline = True
    Else
        Text1.Font.Underline = False
    End If
End Sub

Private Sub cmdClear_Click()
Option1(0).Value = False
Option2(1).Value = False
Option3(2).Value = False

Check1(0).Value = 0
Check2(1).Value = 0
Check3(2).Value = 0
End Sub

Private Sub cmdExit_Click()
Unload Me
End Sub

Private Sub cmdFind_Click()
txt = InputBox("enter Text to find")
l = Len(txt)
r = InStr(1, Text1.Text, txt, vbTextCompare)
Text1.SelStart = r - 1
Text1.SelLength = l
End Sub

Private Sub cmdFindNext_Click()
If r <> Len(Text1.Text) Then
    r = InStr(r + 1, Text1.Text, txt, vbTextCompare)
    Text1.SelStart = r - 1
    Text1.SelLength = l
Else
    MsgBox "No more Text", vbInformation, "Find"
End If
End Sub

Private Sub cmdReplace_Click()
txt1 = InputBox("Enter text to replace")
Text1.Text = Replace(Text1.Text, txt, txt1)

End Sub

Private Sub Form_Load()
Text1.Text = "Design an application in VB to implement the find and replace dialogue " & _
            "box for textbox control with multiple line of text with 3 option buttons and check boxes and"
End Sub

Private Sub Option1_Click(Index As Integer)
If Option1(0).Value = True Then
    Text1.Font.Name = "Arial"
ElseIf Option1(1).Value = True Then
    Text1.Font.Name = "Arial Black"
Else
    Text1.Font.Name = "Times New Roman"
End If
End Sub


=================================================
OUTPUT


Write a Visual Basic Program to make customer Survey and with their name and then display the survey result.

Write a Visual Basic Program to make customer Survey and  with their name and then display the survey result.
------------------------------------------------------------------------------------------
Design Window:-
 First Form :-

Second form:-

Code;-
Dim Excellent As Integer
Dim Satisfactory As Integer
Dim Average As Integer
Dim Bad As Integer
Dim Total As Integer

Private Sub cmdContinue_Click()
If optExcellent.Value Then
    Excellent = Excellent + 1
ElseIf optSatisfactory.Value Then
    Satisfactory = Satisfactory + 1
ElseIf optAverage.Value Then
    Average = Average + 1
Else
    Bad = Bad + 1
End If
txtName.Text = ""
optExcellent.Value = False
optSatisfactory.Value = False
optAverage.Value = False
optBad.Value = False
txtName.SetFocus
End Sub

Private Sub cmdQuit_Click()
Total = Excellent + Satisfactory + Average + Bad
With frmServeyResult
    .lblExcellent = Excellent
    .lblSatisfactory = Satisfactory
    .lblAverage = Average
    .lblBad = Bad
    .lblExcellentPer = Format((Excellent / Total) * 100, "#0.00")
    .lblSatisfactoryPer = Format((Satisfactory / Total) * 100, "#0.00")
    .lblAveragePer = Format((Average / Total) * 100, "#0.00")
    .lblBadPer = Format((Bad / Total) * 100, "#0.00")
End With
frmServeyResult.Show
Unload Me
End Sub

========================================
OUTPUT
After entry of six customers response of first form survey result is:-



Write a Visual Basic program to find the mouse position on screen and number click made by user on screen.

Write a Visual Basic program to find the mouse position on screen and number click that is Left, Right and Double made by user on screen form .

First Design Form Window (mousepose.frm):-


Second Design Form Window (summary.frm):-

Code:- for first form

Dim cnt As Integer
Dim cnt1 As Integer
Dim cnt2 As Integer

Private Sub Command1_Click()
Form2.Show
Form2.Text1.Text = cnt
Form2.Text2.Text = cnt1
Form2.Text3.Text = cnt2
End Sub

Private Sub Form_DblClick()
cnt2 = cnt2 + 1
LblDblClick.Caption = cnt2
End Sub

Private Sub Form_MouseDown(Button As Integer, Shift As Integer, X As Single, Y As Single)
If Button = vbLeftButton Then
    cnt = cnt + 1
    LblLeftClick.Caption = cnt
End If
If Button = vbRightButton Then
    cnt1 = cnt1 + 1
    LblRightClick.Caption = cnt1
End If

End Sub

Private Sub Form_MouseMove(Button As Integer, Shift As Integer, X As Single, Y As Single)
Dim strpos As String
Dim xpos As Integer
Dim ypos As Integer

xpos = X
ypos = Y
strpos = "x : " & xpos & "   y : " & ypos
Label1.Caption = strpos
End Sub

Private Sub form_load()
cnt = 0
cnt1 = 0
End Sub

Private Sub LblRightClick_Click()

End Sub



------------------------


Code for Second form summary form:-
Design Window:-

Private Sub Command2_Click()
Unload Me
End Sub
============================================
OUTPUT




Second Output of Summary :-




Write a Visual Basic program to calculate Sum of the Even digits of a given number.

 Write a Visual Basic program to calculate Sum of the Even digits of a given number.
Designing window :-
Take the following tools form toolbox in form.




Code:-

Private Sub cmdClear_Click()
Text1.Text = ""
Text2.Text = ""
Text1.SetFocus
End Sub

Private Sub cmdSum_Click()
    n = Val(Text1.Text)
    While n > 0
        r = n Mod 10
        n = n \ 10
        If r Mod 2 = 0 Then
            s = s + r
        End If
        Text2.Text = s
    Wend
End Sub

Private Sub cmFxit_Click()
Unload Me
End Sub

Private Sub Form_Activate()
Text1.SetFocus
End Sub

===================================
OUTPUT



Write a visual Basic Program to show tool bar

Designing Window :-
First step right click on toolbox and add components it will show components popup window from it on control tab add Microsoft Windows Common Controls 6.0 (SP6) click on check box of selected items only and then click on OK button .It will show more tools like tool bar and image list on toolbox take it on form window and write the below code in coding window.


                            Fig :- Design View of program for taking tool bar on form


Code:-

Private Sub Form_Load()
Toolbar1.ImageList = ImageList1
Dim b1 As Button
Set b1 = Toolbar1.Buttons.Add
b1.Style = tbrDefault
b1.Caption = "New"
b1.Image = 1

Dim b2 As Button
Set b2 = Toolbar1.Buttons.Add
b2.Style = tbrDefault
b2.Caption = "Open"
b2.Image = 2

Dim b3 As Button
Set b3 = Toolbar1.Buttons.Add
b3.Style = tbrDefault
b3.Caption = "Save"
b3.Image = 3

Dim b4 As Button
Set b4 = Toolbar1.Buttons.Add
b4.Style = tbrDefault
b4.Caption = "Copy"
b4.Image = 4

Dim b5 As Button
Set b5 = Toolbar1.Buttons.Add
b5.Style = tbrDefault
b5.Caption = "Paste"
b5.Image = 5
End Sub


=============================================
OUTPUT


What is Next JS?

 What is Next JS? Next.js is a powerful React framework developed by Vercel that simplifies building modern web applications. Its key featur...