VB Lectures Part 1
VB Lectures Part 1
FORCE CALCULATOR
LECTURE
In this topic, students will create a simple calculator that solve for the Force using Visual Basic.
First is to design the Form. Design the form like the figure below.
Steps
1. Add two (2) Textbox, Four (4) Label and one (1) Button to your form. You can get these objects
from your Toolbox. Simply drag your object to your Form.
2. Change the properties of each Objects including the Form. Below is the list of properties to be
changed.
On Text Property
Name Values
Label1 Mass
Label2 Acceleration
Label3 Force =
Label4 0
Button1 Calculate
Form1 Force Calculator
On Name Property
Name Change Name to
Textbox1 txtMass
Textbox2 txtAcc
Label4 lblForce
Button1 btnCalc
Properties on Form1
Properties Values
ShowIcon False
MaximizedBox False
FormBorderStyles FixedSingle
StartPosition CenterScreen
1|Page
COLLEGE OF ENGINEERING AND TECHNOLOGY
Computer Fundamentals and Programming 1 (A111L)
Prepared by: Engr. Michael B. Tomas
3. Double Click the button to go to Code Window then type the Code below.
m = txtMass.Text
a = txtAcc.Text
F = m * a
lblForce.Text = F
End Sub
End Class
4. All Done, Click the Start button to try your program
2|Page
COLLEGE OF ENGINEERING AND TECHNOLOGY
Computer Fundamentals and Programming 1 (A111L)
Prepared by: Engr. Michael B. Tomas
ACTIVITY 1
Create a calculator for Quadratic Equations.
3|Page
COLLEGE OF ENGINEERING AND TECHNOLOGY
Computer Fundamentals and Programming 1 (A111L)
Prepared by: Engr. Michael B. Tomas
LOGIN WINDOW
LECTURE
VB Object Properties
1. Open a New Project on Visual Studio
2. Double Click the Form. (Do not create or add any objects)
3. Type the code below
Code
Public Class Form1
Dim txtPass As New TextBox
Private Sub Form1_Load(sender As Object, e As EventArgs) Handles MyBase.Load
Controls.Add(txtPass)
Controls.Add(lblPass)
Controls.Add(btnPass)
lblPass.Text = "Password"
lblPass.Location = New Point(30, 30)
lblPass.Font = New Font("Arial", 18, FontStyle.Regular)
lblPass.Size = New Size(150, 40)
btnPass.Text = "Login"
btnPass.Location = New Point(200, 90)
btnPass.Font = New Font("Arial", 18, FontStyle.Regular)
btnPass.Size = New Size(150, 40)
4|Page
COLLEGE OF ENGINEERING AND TECHNOLOGY
Computer Fundamentals and Programming 1 (A111L)
Prepared by: Engr. Michael B. Tomas
ACTIVITY 2
Label sequence using button. The form has two (2) labels and one (1) button. When the button
clicked, the two labels alternately will appear and disappear.
5|Page
COLLEGE OF ENGINEERING AND TECHNOLOGY
Computer Fundamentals and Programming 1 (A111L)
Prepared by: Engr. Michael B. Tomas
RESISTANCE CALCULATOR
(Includes Error, Comments, If, and Select Case. Using Combobox)
ACTIVITY 3
Create a Calculator for Total Resistance and Total Current in Series and Parallel
6|Page
COLLEGE OF ENGINEERING AND TECHNOLOGY
Computer Fundamentals and Programming 1 (A111L)
Prepared by: Engr. Michael B. Tomas
LECTURE
Design the Form
Design a form like the picture below. The form has Four (4) Textbox, Eight (8) Labels, One (1)
Combobox and One (1) Button.
Rename the following objects.
7|Page
COLLEGE OF ENGINEERING AND TECHNOLOGY
Computer Fundamentals and Programming 1 (A111L)
Prepared by: Engr. Michael B. Tomas
R1 = txtR1.Text
R2 = txtR2.Text
R3 = txtR3.Text
Vt = txtVt.Text
End Sub
End Class
8|Page
COLLEGE OF ENGINEERING AND TECHNOLOGY
Computer Fundamentals and Programming 1 (A111L)
Prepared by: Engr. Michael B. Tomas
R1 = txtR1.Text
R2 = txtR2.Text
R3 = txtR3.Text
Vt = txtVt.Text
End Sub
End Class
9|Page