Visual Basic is a Microsoft programming language. Visual Basic programs are created in an Integrated development Environment (IDE). The IDE allows the programmer to create, run and debug visual basic programs conveniently .IDE is allow a programmer to create working programs in a fraction of the time that it would normally take to code programs without using IDE. We discuss the visual Basic IDE. The process of rapidly creating an application is typically referred to as Rapid Application Development (RAD). Visual Basic is the world’s most widely used RAD language.VISUAL BASIC is very creative programming part of beginner.Visual Basic (VB) is a programming language and environment developed by Microsoft. Originally designed to make programming accessible to beginners, it provides a graphical interface and powerful tools for building Windows applications. With Visual Basic, programmers can create software that takes advantage of Windows’ graphical interface, making it ideal for creating user-friendly applications. Visual Basic is part of Microsoft’s Visual Studio suite and is especially popular in enterprise environments for developing business applications.
History and Evolution of Visual Basic
Visual Basic was introduced in 1991, built upon the BASIC programming language. It quickly became popular because of its simplicity and ease of use. Over the years, it evolved with several major releases, each bringing more sophisticated tools and features. In 2002, Microsoft released Visual Basic .NET (VB.NET), which fundamentally changed the language by integrating it into the .NET framework. VB.NET added modern object-oriented features and expanded the language’s capabilities, making it suitable for web, cloud, and mobile applications.
Key Features of Visual Basic
Visual Basic One of the reasons for Visual Basic’s popularity is its drag-and-drop environment, where developers can create graphical user interfaces (GUIs) visually. Instead of writing complex code, they can drag controls such as buttons, text boxes, and labels directly onto the form. This ease of GUI design is highly beneficial for rapid application development (RAD), as it speeds up the software creation process. Another key feature is Visual Basic’s Event-Driven Programming, where code responds to events like button clicks, mouse movements, and keystrokes, which is essential for creating interactive applications.
Visual Basic also includes an extensive library of pre-built functions and objects. For instance, it has built-in support for databases, file handling, and network communication, allowing developers to create complex applications without extensive additional libraries.
Uses of Visual Basic
Visual Basic is commonly used in business settings, where it serves to build custom applications for tasks such as data management, inventory tracking, and customer relationship management. Its compatibility with Microsoft Office products, such as Excel and Access, makes it a favorite for automating business processes. Furthermore, Visual Basic is often employed to build prototypes of applications before they are developed in more robust programming languages.
Visual Basic in the Modern Context
Visual Basic While newer programming languages have become popular, Visual Basic still has a place in modern development. VB.NET remains widely used within enterprise environments due to its ease of integration with other Microsoft technologies and its stability for long-term projects. With the .NET framework, VB can be used to create applications that run on various platforms, including web applications.
In conclusion, Visual Basic is a user-friendly, versatile language that has evolved to remain relevant over the years. Its simplicity, combined with the powerful features of VB.NET, keeps it viable for both beginners and experienced programmers. For businesses looking to automate tasks or build custom applications, Visual Basic remains a practical choice.
Visual Basic is drive from the BASIC Programming language. Visual Basic is a distinctly different language providing powerful features such as graphical user interfaces, event handing, access to win 32 API, object-oriented features, error handing, structured programming, and much more.
History of Visual Basic
Visual basic devolved from BASIC (Beginner’s All-symbolic Instruction code). BASIC was developed in the mid-1960 s by professor’s john Kemeny and Thomas Kurtz of Dartmouth college as a language for writing simple programs. Basic’s primary purpose was to help people learn how to program.Visual Basic is a Microsoft programming language.
The widespread use of Basic with various types of computers (sometimes called hard0w language. With a development of the Microsoft Windows graphical user interface (GUI) in the late 1980s and the early 1990s, the natural evolution of Basic was Visual Basic, which was created by Microsoft Corporation in 1991.
Until Visual Basic appeared, developing Microsoft Windows-based applications was a difficult and cumbersome process. Visual Basic greatly simplifies Windows application development. Science 1991 six versions have been released, with the latest – Visual Basic 6 – appearing in September 1998.Visual Basic is a Microsoft programming language.
Introduction
Visual Basic’s is Integrated Development Environment (IDE) allows the programmer to create, run and debug Windows programs in one application (e.g., Visual Basic Program)without the need to open additional programs (i.e., a program to create the program, a program the executes the program, a program that debugs the program, etc.). In this chapter, we over view the Visual Basic IDE features and discuss how to create and execute a simple Visual Basic is a Microsoft programming language.
Visual Basic Question:
Question 1.What is full form of VB?
Question 2.What is shortcut keys of Properties in Visual Basic?
Question 3.What is shortcut keys of Coding in Visual Basic?
Question 4.What is shortcut keys of Run in Visual Basic?
Question 5. How many default controls are available in Visual Basic?
Question 6.What is shortcut keys of Exit in Visual Basic?
Visual Basic 6.0 Tools:
ToolBox:
Label:
The label control is used to display text. It is also used to label other controls. The end user cannot edit the label text.
TextBox:
The Text box control contains characters. End-users can edit the characters contained in the TextBox.
CommandButton:
The CommandButton control is simply a button that we see in our daily-use software. When the end-user clicks the CommandButton, the program behaves according to the code assigned in the CommandButton.
Option Button:
This control enables the end-user to select one among several options. Only one option button among others in a group can be on at the same time. You can name an option using the Caption property.
CheckBox:
The CheckBox control is used to make a yes/no or true-false selection. You can check more than one CheckBox at the same time that let you make multiple choices. You can label this control using the Caption property.
VscrollBar & HscrollBar:
VscrollBar and HscrollBar controls let you create Vertical scroll bar and Horizontal scroll bar respectively.
Frame:
The Frame control is used as a container of other controls. This is also used to group different controls especially in Option Button controls when you wish to select more than one option. The Caption property associated with it is useful to label the frame.
ListBox & ComboBox:
The ListBox control contains a number of items. The user can select one or more items from the list.
The comboBox control has the feature of ListBox and TextBox. This control does not support multiple selections.
DriveListBox, DirListBox & FileListBox:
These controls are often used together to perform file related tasks like opening or selecting files that are stored in the secondary memory.
Timer:
The Timer control is not visible on the form when you run the program. It is used to execute lines of code repeatedly at specific intervals.
The Data Control:
The Data control is used for database programming.
Common Properties in VB6:
In this lesson, you’ll learn about the common properties used in VB6.
BackColor and ForeColor:
The BackColor property sets the background color of an object while the ForeColor property changes the foreground color used to display text. You can set these properties either from Properties Window or you may wish to set in run-time.
PROJECT 1: VISUAL BASIC PROGRAMMING LANGUAGE (First & Last Name)
Design Part:
Property Part(F4)
Coding Part (F7)
Private Sub Command1_Click()
Label4.Caption = Text1.Text + ” ” + Text2.Text
End Sub
Private Sub Command2_Click()
Text1.Text = ” “
Text2.Text = ” “
Label4.Caption = ” “
Text1.SetFocus
End Sub
Run / Display Project (F5)
PROJECT 2: VISUAL BASIC PROGRAMMING LANGUAGE (Mini Calculation)
Design Part:
Property Part(F4)
Coding Part (F7)
Private Sub Command1_Click()
Label4.Caption = Val(Text1.Text) + Val(Text2.Text)
End Sub
Private Sub Command2_Click()
Label4.Caption = Val(Text1.Text) – Val(Text2.Text)
End Sub
Private Sub Command3_Click()
Label4.Caption = Val(Text1.Text) * Val(Text2.Text)
End Sub
Private Sub Command4_Click()
Label4.Caption = Val(Text1.Text) / Val(Text2.Text)
End Sub
Private Sub Command5_Click()
Label4.Caption = Val(Text1.Text) ^ 2
End Sub
Private Sub Command6_Click()
Label4.Caption = Val(Text1.Text) ^ (1 / 2)
End Sub
Private Sub Command7_Click()
Text1.Text = ” “
Text2.Text = ” “
Label4.Caption = ” “
Text1.SetFocus
End Sub
Private Sub Command8_Click()
End
End Sub
Run / Display Project (F5)
PROJECT 3:VISUAL BASIC PROGRAMMING LANGUAGE Font Formate)
Design Part:
Property Part(F4)
Coding Part (F7)
Private Sub Option1_Click()
Text1.ForeColor = vbRed
End Sub
Private Sub Option2_Click()
Text1.ForeColor = vbGreen
End Sub
Private Sub Option3_Click()
Text1.ForeColor = vbBlue
End Sub
Private Sub Check1_Click()
If Check1.Value = 1 Then
Text1.FontBold = True
Else
Text1.FontBold = False
End If
End Sub
Private Sub Check2_Click()
If Check2.Value = 1 Then
Text1.FontItalic = True
Else
Text1.FontItalic = False
End If
End Sub
Private Sub Check3_Click()
If Check3.Value = 1 Then
Text1.FontUnderline = True
Else
Text1.FontUnderline = False
End If
End Sub
Private Sub List1_Click()
If List1.ListIndex = 0 Then
Text1.FontSize = “8”
ElseIf List1.ListIndex = 1 Then
Text1.FontSize = “12”
ElseIf List1.ListIndex = 2 Then
Text1.FontSize = “16”
ElseIf List1.ListIndex = 3 Then
Text1.FontSize = “20”
ElseIf List1.ListIndex = 4 Then
Text1.FontSize = “40”
ElseIf List1.ListIndex = 5 Then
Text1.FontSize = “80”
End If
End Sub
Private Sub List2_Click()
If List2.ListIndex = 0 Then
Text1.FontName = “arial”
ElseIf List2.ListIndex = 1 Then
Text1.FontName = “monotype corsiva”
ElseIf List2.ListIndex = 2 Then
Text1.FontName = “times new roman”
ElseIf List2.ListIndex = 3 Then
Text1.FontName = “arial black”
End If
End Sub
Run / Display Project (F5)
PROJECT 4: VISUAL BASIC PROGRAMMING LANGUAGE (Country & Capital)
Design Part:
Property Part(F4)
Coding Part (F7)
Private Sub List1_Click()
If List1.ListIndex = 0 Then
Label3.Caption = “New Delhi”
ElseIf List1.ListIndex = 1 Then
Label3.Caption = “Islamabad”
ElseIf List1.ListIndex = 2 Then
Label3.Caption = “Dhaka”
ElseIf List1.ListIndex = 3 Then
Label3.Caption = “Sri Jayawardenpura Kotte”
ElseIf List1.ListIndex = 4 Then
Label3.Caption = “Beijing”
ElseIf List1.ListIndex = 5 Then
Label3.Caption = “London”
ElseIf List1.ListIndex = 6 Then
Label3.Caption = “Kathmandu”
ElseIf List1.ListIndex = 7 Then
Label3.Caption = “Thimpu”
ElseIf List1.ListIndex = 8 Then
Label3.Caption = “Canberra”
End If
End Sub
Run / Display Project (F5)
PROJECT 5: VISUAL BASIC PROGRAMMING LANGUAGE (Change Shape)
Design Part:
Property Part(F4)
Coding Part (F7)
Private Sub Command1_Click()
Shape1.Shape = 0
End Sub
Private Sub Command2_Click()
Shape1.Shape = 1
End Sub
Private Sub Command3_Click()
Shape1.Shape = 2
End Sub
Private Sub Command4_Click()
Shape1.Shape = 3
End Sub
Private Sub Command5_Click()
Shape1.Shape = 4
End Sub
Private Sub Command6_Click()
Shape1.Shape = 5
End Sub
Run / Display Project (F5)
PROJECT 6:VISUAL BASIC PROGRAMMING LANGUAGE (Calculate Result)
Design Part:
Property Part(F4)
Coding Part (F7)
Double Click on Blank Form & Select General Option ()
Dim S1,S2, S3, Tot, Avg As Single
Dim gr As String
Private Sub Command1_Click()
S1 = Val(Text2.Text)
S2 = Val(Text3.Text)
S3 = Val(Text4.Text)
TOT = S1 + S2 + S3
Label8.Caption = TOT
AVG = TOT / 3
Label9.Caption = AVG
If AVG > 100 Then
GR = “INVALID”
ElseIf AVG = 100 Then
GR = “EXCELLENT”
ElseIf AVG >= 80 Then
GR = “VERY GOOD”
ElseIf AVG >= 70 Then
GR = “GOOD”
ElseIf AVG >= 50 Then
GR = “FAIR”
ElseIf AVG >= 40 Then
GR = “PASS”
Else
GR = “FAIL”
End If
Label10.Caption = GR
End Sub
Private Sub Command2_Click()
Text1.Text = “”
Text2.Text = “”
Text3.Text = “”
Text4.Text = “”
Label8.Caption = “”
Label9.Caption = “”
Label10.Caption = “”
Text1.SetFocus
End Sub
Private Sub Command3_Click()
End
End Sub
Run / Display Project (F5)
PROJECT 7: VISUAL BASIC PROGRAMMING LANGUAGE (Be Verb)
Design Part:
Property Part(F4)
Coding Part (F7)
Private Sub Command1_Click()
Label5.Caption = Text1.Text + ” ” + Text2.Text + ” ” + Text3.Text
End Sub
Private Sub Command2_Click()
Text1.Text = ” “
Text2.Text = ” “
Text3.Text = ” “
Label5.Caption = ” “
Text1.SetFocus
End Sub
Private Sub Command3_Click()
End
End Sub
Run / Display Project (F5)
PROJECT 8: VISUAL BASIC PROGRAMMING LANGUAGE (Slide Show )
Design Part:
Property Part(F4)
Coding Part (F7)
Dim X As Integer-(Double click on blank form then select general)
Private Sub Timer1_Timer()
Dim A, B, C As Integer
A = Rnd() * 255
B = Rnd() * 255
C = Rnd() * 255
Me.BackColor = RGB(A, B, C)
If X = 0 Then
Image1.Picture = LoadPicture(“D:\LABONI DITA S2 PROJECT\ONE.JPG”)
X = X + 1
ElseIf X = 1 Then
Image1.Picture = LoadPicture(“D:\LABONI DITA S2 PROJECT\TWO.JPG”)
X = X + 1
ElseIf X = 2 Then
Image1.Picture = LoadPicture(“D:\LABONI DITA S2 PROJECT\THREE.JPG”)
X = X + 1
ElseIf X = 3 Then
Image1.Picture = LoadPicture(“D:\LABONI DITA S2 PROJECT\FOUR.JPG”)
X = X + 1
ElseIf X = 4 Then
Image1.Picture = LoadPicture(“D:\LABONI DITA S2 PROJECT\FIVE.JPG”)
X = 0
End If
End Sub
Run / Display Project (F5)
PROJECT 9: VISUAL BASIC PROGRAMMING LANGUAGE (Change Font Style)
Design Part:
Property Part(F4)
Coding Part (F7)
Private Sub Command1_Click()
Text3.Text = “HELLO MR.” + ” ” + Text1.Text + ” ” + “YOUR ADDRESS IS” + ” ” + Text2.Text
End Sub
Private Sub Command2_Click()
If Check1.Value Then
Text3.FontBold = True
Else
Text3.FontBold = False
End If
If Check2.Value Then
Text3.FontItalic = True
Else
Text3.FontItalic = False
End If
If Check3.Value Then
Text3.FontUnderline = True
Else
Text3.FontUnderline = False
End If
End Sub
Run / Display Project (F5)
Project 10. VISUAL BASIC PROGRAMMING LANGUAGE (Odd Number & Even Number)
Design Part:
Property Part(F4)
Coding Part (F7)
Private Sub Command1_Click()
If Text1.Text Mod 2 = 0 Then
Label3.Caption = “EVEN NUMBER”
Else
Label3.Caption = “ODD NUMBER”
End If
If Text1.Text > 70 Then
Label3.Caption = “THE LIMIT NO. IS OVERFLOW”
End If
End Sub
Private Sub Command2_Click()
Text1.Text = ” “
Label3.Caption = ” “
Text1.SetFocus
End Sub
Private Sub Timer1_Timer()
Dim X, Y, Z As Integer
X = Rnd() * 255
Y = Rnd() * 255
Z = Rnd() * 255
Me.BackColor = RGB(X, Y, Z)
Label4.Caption = Date
Label5.Caption = Time
End Sub
Run / Display Project (F5)
Project 11. VISUAL BASIC PROGRAMMING LANGUAGE (Traffic Signal)
Design Part:
Property Part(F4)
Coding Part (F7)
Private Sub Timer1_Timer()
Dim A, B, C As Integer
A = Rnd() * 255
B = Rnd() * 255
C = Rnd() * 255
Me.BackColor = RGB(A, B, C)
If I = 0 Then
Shape1.FillColor = vbRed
Shape2.FillColor = vbBlack
Shape3.FillColor = vbBlack
I = I + 1
ElseIf I = 1 Then
Shape1.FillColor = vbBlack
Shape2.FillColor = vbGreen
Shape3.FillColor = vbBlack
I = I + 1
ElseIf I = 2 Then
Shape1.FillColor = vbBlack
Shape2.FillColor = vbBlack
Shape3.FillColor = vbYellow
I = 0
End If
Label1.Caption = Time
End Sub
Run / Display Project (F5)
Project 12. VISUAL BASIC PROGRAMMING LANGUAGE (City_Tempareture)
Design Part:
Property Part(F4)
Coding Part (F7)
Double click on blank form then select general()
Dim CITY_TEMP As New Collection
Private Sub Command1_Click()
CITY = InputBox(“WHAT CITY?”)
TEMP = CITY_TEMP.Item(CITY)
MsgBox TEMP
Exit Sub
MsgBox “THIS CITY WAS NOT FOUND IN OUR CATALOGE”
End Sub
Private Sub Command2_Click()
CITY = Text1.Text
TEMP = Text2.Text
CITY_TEMP.Add TEMP, CITY
End Sub
Private Sub Command3_Click()
CITY = Text1.Text
CITY_TEMP.Remove CITY
Text1.Text = ” “
Text2.Text = ” “
Text3.Text = ” “
End Sub
Private Sub Command4_Click()
Text3.Text = CITY_TEMP.Count
End Sub
Private Sub Command5_Click()
For Each I In CIT_TEMP
MsgBox (I)
Next
End Sub
Private Sub Form_Load()
CITY_TEMP.Add 32, “LUCKNOW”
CITY_TEMP.Add 34, “MATHURA”
CITY_TEMP.Add 35, “VARANASI”
CITY_TEMP.Add 24, “MUMBAI”
CITY_TEMP.Add 40, “JAIPUR”
CITY_TEMP.Add 42, “JABALPUR”
End Sub
Run / Display Project (F5)
Project 13. VISUAL BASIC PROGRAMMING LANGUAGE (Pan Card Application)
Design Part:
Property Part(F4)
Coding Part (F7)
Private Sub CMDCANCEL_Click()
answer = MsgBox(“Do you want to close application?”, vbExclamation + vbYesNo, “Confirm”)
If answer = vbYes Then
End
Else
MsgBox “action canceled”, vbInformation, “confrim”
End If
End Sub
Private Sub CMDREGISTER_Click()
If TXTNAME = “” Then
MsgBox “Please enter your name”, vbExclamation
TXTNAME.SetFocus
Exit Sub
End If
If CBODAY.ListIndex = -1 Then
MsgBox “please select a day from the list”, vbExclamation
CBODAY.SetFocus
Exit Sub
End If
If CBOMONTH.ListIndex = -1 Then
MsgBox “please select any month from the list”, vbExclamation
CBOMONTH.SetFocus
Exit Sub
End If
If CBOYEAR.ListIndex = -1 Then
MsgBox “please select any year from the list”, vbExclamation
CBOYEAR.SetFocus
Exit Sub
End If
If CBOGENDER.ListIndex = -1 Then
MsgBox “please select any gender from the list”, vbExclamation
CBOGENDER.SetFocus
Exit Sub
End If
If TXTEMAIL.Text = “” Then
MsgBox “please enter your email-id”, vbExclamation
TXTEMAIL.SetFocus
Exit Sub
End If
If TXTEMAILAGAIN.Text = “” Then
MsgBox “Please Re-enter your Email address “, vbExclamation
TXTEMAILAGAIN.SetFocus
Exit Sub
End If
If TXTEMAIL.Text <> TXTEMAILAGIN.Text Then
MsgBox “Email address mismatch!!!”, vbExclamation
TXTEMAIL.SetFocus
Exit Sub
End If
If CBOCOUNTRY.ListIndex = -1 Then
MsgBox “please select any country from the list”, vbExclamation
CBOCOUNTRY.SetFocus
Exit Sub
End If
MsgBox “Name – ” + TXTNAME + Chr(13) + “Birthday – ” + CBODAY.Text + ” ” + CBOMONTH.Text + CBOYEAR.Text + Chr(13) + “Gender – ” + CBOGENDER.Text + Chr(13) + “Email address – ” + TXTEMAIL.Text + Chr(13) + “Country-” + CBOCOUNTRY.Text, vbInformation, “Pancard verification successful !!!”
End
End Sub
Private Sub Form_Load()
CBOGENDER.AddItem “Male”
CBOGENDER.AddItem “Female”
CBOCOUNTRY.AddItem “Eglangnd”
CBOCOUNTRY.AddItem “USA”
CBOCOUNTRY.AddItem “France”
CBOCOUNTRY.AddItem “India”
CBOCOUNTRY.AddItem “Germany”
CBOCOUNTRY.AddItem “China”
CBOCOUNTRY.AddItem “Japan”
CBOCOUNTRY.AddItem “Bangladesh”
For d = 1 To 31
CBODAY.AddItem Str(d)
d = Val(d)
Next d
CBOMONTH.AddItem “January”
CBOMONTH.AddItem “February”
CBOMONTH.AddItem “March”
CBOMONTH.AddItem “April”
CBOMONTH.AddItem “May”
CBOMONTH.AddItem “June”
CBOMONTH.AddItem “July”
CBOMONTH.AddItem “August”
CBOMONTH.AddItem “September”
CBOMONTH.AddItem “Octbor”
CBOMONTH.AddItem “November”
CBOMONTH.AddItem “December”
For y = 1947 To 2024
CBOYEAR.AddItem Str(y)
y = Val(y)
Next y
End Sub
Run / Display Project (F5)
Project 14. VISUAL BASIC PROGRAMMING LANGUAGE (Find Out Largest Number Part-1)
Design Part:
Property Part(F4)
Coding Part (F7)
Private Sub Command1_Click()
A = Val(Text1.Text)
B = Val(Text2.Text)
C = Val(Text3.Text)
If A > B Then
If A > C Then
Label6.Caption = Text1.Text
Else
Label6.Caption = Text3.Text
End If
Else
If B > C Then
Label6.Caption = Text2.Text
Else
Label6.Caption = Text3.Text
End If
End If
End Sub
Private Sub Command2_Click()
Label6.Caption = ” “
Text1.Text = ” “
Text2.Text = ” “
Text3.Text = ” “
Text1.SetFocus
End Sub
Private Sub Command3_Click()
D = MsgBox(“DO YOU WANT TO QUIT?”, vbExclamation + vbYesNo, “CONFRIM”)
If D = vbYes Then
End
Else
MsgBox “ACTION CANCELED”, vbInformation, “CONFRIM”
End If
End Sub
Private Sub Timer1_Timer()
Dim X, Y, Z As Integer
X = Rnd() * 255
Y = Rnd() * 255
Z = Rnd() * 255
Me.BackColor = RGB(X, Y, Z)
End Sub
Run / Display Project (F5)
Project 15. VISUAL BASIC PROGRAMMING LANGUAGE (Find Out Largest Number Part-2)
Design Part:
Property Part(F4)
Coding Part (F7)
Private Sub Command1_Click()
If Val(Text1.Text) > Val(Text2.Text) Then
Label5.Caption = Text1.Text
ElseIf Val(Text1.Text) < Val(Text2.Text) Then
Label5.Caption = Text2.Text
ElseIf Val(Text1.Text) = Val(Text2.Text) Then
Label5.Caption = Text2.Text
End If
End Sub
Private Sub Command2_Click()
Label5.Caption = ” “
Text1.Text = ” “
Text2.Text = ” “
Text1.SetFocus
End Sub
Private Sub Timer1_Timer()
Dim X, Y, Z As Integer
X = Rnd() * 255
Y = Rnd() * 255
Z = Rnd() * 255
Me.BackColor = RGB(X, Y, Z)
Label6.Caption = Date
Label7.Caption = Time
End Sub
Run / Display Project (F5)
Project 16. VISUAL BASIC PROGRAMMING LANGUAGE (Calendar)
Design Part:
Property Part(F4)
Coding Part (F7)
Option Explicit –(Double Click on Blank Form Then Select General)
Private Sub TIMEDISPLAY_Timer()
Dim TODAY As Variant
TODAY = Now
LBLDAY.Caption = Format(TODAY, “DDDD”)
LBLMONTH.Caption = Format(TODAY, “MMMM”)
LBLYEAR.Caption = Format(TODAY, “YYYY”)
LBLNUMBER.Caption = Format(TODAY, “D”)
LBLTIME.Caption = Format(TODAY, “H:MM:SS AMPM”)
End Sub
Run / Display Project (F5)
Project 17. VISUAL BASIC PROGRAMMING LANGUAGE (Multiple Choice Question)
Design Part:
Property Part(F4)
Coding Part (F7)
Private Sub Command1_Click()
Text1.Text = marks
MARK = 0
End Sub
Private Sub Option1_Click()
If Option1.Value = True Then
marks = marks + 5
End If
End Sub
Private Sub Option10_Click()
If Option10.Value = True Then
marks = marks + 0
End If
End Sub
Private Sub Option11_Click()
If Option11.Value = True Then
marks = marks + 0
End If
End Sub
Private Sub Option12_Click()
If Option12.Value = True Then
marks = marks + 0
End If
End Sub
Private Sub Option2_Click()
If Option2.Value = True Then
marks = marks + 0
End If
End Sub
Private Sub Option3_Click()
If Option3.Value = True Then
marks = marks + 0
End If
End Sub
Private Sub Option4_Click()
If Option4.Value = True Then
marks = marks + 0
End If
End Sub
Private Sub Option5_Click()
If Option5.Value = True Then
marks = marks + 0
End If
End Sub
Private Sub Option6_Click()
If Option6.Value = True Then
marks = marks + 5
End If
End Sub
Private Sub Option7_Click()
If Option7.Value = True Then
marks = marks + 0
End If
End Sub
Private Sub Option8_Click()
If Option8.Value = True Then
marks = marks + 0
End If
End Sub
Private Sub Option9_Click()
If Option9.Value = True Then
marks = marks + 5
End If
End Sub
Private Sub Timer1_Timer()
Dim X As Integer
X = Label5.Caption
X = X + 1
If X > 30 Then
Option1.Enabled = False
Option2.Enabled = False
Option3.Enabled = False
Option4.Enabled = False
Option5.Enabled = False
Option6.Enabled = False
Option7.Enabled = False
Option8.Enabled = False
Option9.Enabled = False
Option10.Enabled = False
Option11.Enabled = False
Option12.Enabled = False
End If
Label5 = Format(X, “00”)
Dim S, U, B As Integer
S = Rnd() * 255
U = Rnd() * 255
B = Rnd() * 255
Me.BackColor = RGB(S, U, B)
End Sub
Project -> Add Module -> Open -> Public Marks As Byte
Run / Display Project (F5)
Project 18. VISUAL BASIC PROGRAMMING LANGUAGE (Change Case & Font Size)
Design Part:
Property Part(F4)
Coding Part (F7)
Private Sub Form_Load()
Dim I As Integer
List1.AddItem “TIMES NEW ROMAN”
List1.AddItem “ARIAL”
List1.AddItem “MONOTYPE CORSIVA”
List1.AddItem “ROMAN”
List1.AddItem “TAFFY”””
List1.AddItem “CASTELLAR”
For I = 8 To 30 Step 2
List2.AddItem I
Next I
List3.AddItem “REGULAR”
List3.AddItem “BOLD”
List3.AddItem “ITALIC”
List3.AddItem “BOLDITALIC”
End Sub
Private Sub List1_Click()
SAMPLETEXT.FontName = List1.Text
End Sub
Private Sub List2_Click()
SAMPLETEXT.FontSize = List2.Text
End Sub
Private Sub List3_Click()
If List3.Text = “BOLD” Then
SAMPLETEXT.FontBold = True
ElseIf List3.Text = “ITALIC” Then
SAMPLETEXT.FontItalic = True
ElseIf List3.Text = “BOLDITALIC” Then
SAMPLETEXT.FontBold = True
SAMPLETEXT.FontItalic = True
ElseIf List3.Text = “REGULAR” Then
SAMPLETEXT.FontBold = False
SAMPLETEXT.FontItalic = False
Else
SAMPLETEXT.FontBold = False
SAMPLETEXT.FontItalic = False
End If
End Sub
Private Sub LOWERCASE_Click()
If LOWERCASE.Value = 1 Then
SAMPLETEXT.Caption = LCase(SAMPLETEXT.Caption)
Else
SAMPLETEXT.Caption = “SAMPLETEXT”
End If
End Sub
Private Sub STRIKETHROUGH_Click()
If STRIKETHROUGH.Value = 1 Then
SAMPLETEXT.FontStrikethru = True
Else
SAMPLETEXT.FontStrikethru = False
End If
End Sub
Private Sub UNDERLINE_Click()
If UNDERLINE.Value = 1 Then
SAMPLETEXT.FontUnderline = True
Else
SAMPLETEXT.FontUnderline = False
End If
End Sub
Private Sub UPPERCASE_Click()
If UPPERCASE.Value = 1 Then
SAMPLETEXT.Caption = UCase(SAMPLETEXT.Caption)
Else
SAMPLETEXT.Caption = “SAMPLETEXT”
End If
End Sub
Run / Display Project (F5)
Project 19. VISUAL BASIC PROGRAMMING LANGUAGE (Color Change & Effect)
Design Part:
Property Part(F4)
Coding Part (F7)
Private Sub HScroll1_Change()
Me.BackColor = RGB(Me.HScroll1.Value, Me.HScroll2.Value, Me.HScroll3.Value)
Me.Label4.Caption = (Me.HScroll1.Value / 255) * 100 & “%”
End Sub
Private Sub HScroll2_Change()
Me.BackColor = RGB(Me.HScroll1.Value, Me.HScroll2.Value, Me.HScroll3.Value)
Me.Label5.Caption = (Me.HScroll2.Value / 255) * 100 & “%”
End Sub
Private Sub HScroll3_Change()
Me.BackColor = RGB(Me.HScroll1.Value, Me.HScroll2.Value, Me.HScroll3.Value)
Me.Label6.Caption = (Me.HScroll3.Value / 255) * 100 & “%”
End Sub
Run / Display Project (F5)
Project 20. VISUAL BASIC PROGRAMMING LANGUAGE (Search Vowel)
Design Part:
Property Part(F4)
Coding Part (F7)
Private Sub Command1_Click()
Dim STR1, STR2 As String
Dim VCOUNT, I, STR1LEN As Integer
VCOUNT = 0
STR1 = Text1.Text
STR1LEN = Len(STR1)
STR1 = UCase(STR1)
For I = 1 To STR1LEN
STR2 = Mid(STR1, I, 1)
If STR2 = “A” Or STR2 = “E” Or STR2 = “I” Or STR2 = “O” Or STR2 = “U” Then
VCOUNT = VCOUNT + 1
End If
Next I
Text2.Text = VCOUNT
End Sub
Run / Display Project (F5)
Project 21. VISUAL BASIC PROGRAMMING LANGUAGE (User Name & Password Part-1)
Design Part:
Property Part(F4)
Coding Part (F7)
(Double click on blank form then select general)
Dim Username As String
Dim Password As Integer
Dim Counter As Integer
Private Sub Command1_Click()
USERNAME = “LABONI”
PASSWORD = “8327”
Dim USER, PASS As String
USER = Text1.Text
PASS = Text2.Text
If USERNAME = USER And PASSWORD = PASS Then
MsgBox (“YOU ARE LOGGED IN”)
Else
MsgBox (“TRY AGAIN”)
COUNTER = COUNTER + 1
End If
If COUNTER = 3 Then
MsgBox (“YOUR ACCOUT IS BLOCKED”)
Unload Me
End If
End Sub
Run / Display Project (F5)
Project 22. VISUAL BASIC PROGRAMMING LANGUAGE (User Name & Password Part-2)
Design Part:
Property Part(F4)
Coding Part (F7)
Private Sub Command1_Click()
Dim USERNAME, PASSWORD As String
USERNAME = “LABONI”
PASSWORD = “1234”
If Text1.Text = “” Or Text2.Text = “” Then
MsgBox “PLEASE ENTER YOUR USERNAME AND PASSWORD”, vbExclamation
Text1.SetFocus
Exit Sub
End If
If Text1.Text = USERNAME And Text2.Text = PASSWORD Then
MsgBox (“SIGN IN SUCESSFUL”)
FORM2.Show
Me.Hide
ElseIf Text1.Text = USERNAME Or Text2.Text <> PASSWORD Then
MsgBox (“WRONG PASSWORD! SIGN IN FAILED”)
Text1.SetFocus
ElseIf Text1.Text <> USERNAME Or Text2.Text = PASSWORD Then
MsgBox (“WRONG USERNAME! SIGN IN FAILED”)
Text1.SetFocus
End If
End Sub
Run / Display Project (F5)
Project 23. VISUAL BASIC PROGRAMMING LANGUAGE (Drive Change)
Design Part:
Property Part(F4)
Coding Part (F7)
Private Sub Dir1_Change()
File1.Path = Dir1.Path
End Sub
Private Sub Drive1_Change()
Dir1.Path = Drive1.Drive
End Sub
Private Sub File1_Click()
If Right(File1.Path, 1) = “1” Then
F = File1.Path + File.FileName
Else
F = File1.Path + “/” + File1.FileName
End If
Image1.Picture = LoadPicture(F)
End Sub
Run / Display Project (F5)
Project 23. VISUAL BASIC PROGRAMMING LANGUAGE (Calculator)
Design Part:
Double click on blank form then select general()
Option Explicit
Dim N1, N2, RES As Single
Dim FL As Integer
Dim Control As Object
Private Sub Command1_Click(Index As Integer)
If FL = 5 Then
Label1.Caption = Command1(Index).Caption
FL = 0
Else
Label1.Caption = Label1.Caption + Command1(Index).Caption
End If
End Sub
Private Sub Command2_Click()
N1 = Val(Label1.Caption)
FL = 1
Label1.Caption = ” “
End Sub
Private Sub Command3_Click()
N1 = Val(Label1.Caption)
FL = 2
Label1.Caption = ” “
End Sub
Private Sub Command4_Click()
N1 = Val(Label1.Caption)
FL = 3
Label1.Caption = ” “
End Sub
Private Sub Command5_Click()
N1 = Val(Label1.Caption)
FL = 4
Label1.Caption = ” “
End Sub
Private Sub Command6_Click()
N2 = Val(Label1.Caption)
If FL = 1 Then
RES = N1 + N2
ElseIf FL = 2 Then
RES = N1 – N2
ElseIf FL = 3 Then
RES = N1 * N2
ElseIf FL = 4 Then
RES = N1 / N2
End If
FL = 5
Label1.Caption = RES
End Sub
Private Sub Command7_Click()
Label1.Caption = Sqr(Label1.Caption)
FL = 5
End Sub
Private Sub Command8_Click()
Label1.Caption = 1 / Val(Label1.Caption)
FL = 5
End Sub
Private Sub Command9_Click()
For Each Control In Form1
If TypeOf Control Is CommandButton Then
Control.Enabled = True
End If
Next
Command9.Enabled = False
End Sub
Private Sub Command10_Click()
For Each Control In Form1
If TypeOf Control Is CommandButton Then
Control.Enabled = False
End If
Next
Command9.Enabled = True
End Sub