[go: up one dir, main page]

0% found this document useful (0 votes)
32 views8 pages

Computer Programming

The document discusses computer programming concepts like programming languages, paradigms, and Visual Basic.NET, providing details on creating Windows form applications in Visual Basic.NET, its integrated development environment components, and basic programming structures like variables, data types, and conditional statements. It also covers common controls like labels, textboxes, buttons, and how to arrange them on a form.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
32 views8 pages

Computer Programming

The document discusses computer programming concepts like programming languages, paradigms, and Visual Basic.NET, providing details on creating Windows form applications in Visual Basic.NET, its integrated development environment components, and basic programming structures like variables, data types, and conditional statements. It also covers common controls like labels, textboxes, buttons, and how to arrange them on a form.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 8

Computer Programming

A program is a set of instructions that tells the computer what to do.


Writing programs to solve a specific problem is known as computer programming. In writing programs,
you use a special language. These languages are called programming languages. Programming
Languages are classified using programming paradigm (programming methods).

Programming Paradigm/Methods

1. Imperative Programming-defines a computation as statements that change a program state.


2. Procedural Programming-specifies a step a program much reach to take a desired state.
3. Object- Oriented Programming-uses objects, methods, and events.
4. Event-driven programming-program control flow is determined by events.

Visual Basic.Net
-Visual Basic.net is an object-oriented/event-driven programming language used to develop local based-
and web based applications.
-Can be downloaded from www.microsoft.com/vb.
-To install Visual Basic, double-click the downloaded file then follow the on-screen prompt.

Starting Visual Basic.Net


Click Start>All Programs>Visual Basic.

Creating a Windows Form Application


-A windows forms application is an application that is based on windows interface.
-To create a window forms application:
Start Visual Basic.Net.
Click File>New Project>Windows Forms Application>Type the project name>Ok.
Note: A project is a folder where your application files are saved.

Components of Visual Basic.NET Integrated Development Environment(IDE)


1. Menu bar-contains menus/commands used in managing your application.
2. Toolbars-contains commonly used commands.
3. Form designer-an area where you design your application.
-All items inside the form are called objects.
-When the form designer is not shown, click view>designer.
4. Toolbox- contains objects that can be used in designing your application.
-To add an object to your form, select an object from the toolbox then click and drag it to your form.
-When the toolbox is not shown, click view>Toolbox.
6. Solution explorer-lists the projects displayed in the current solution.
-When the solution explorer is not shown, click view>solution explorer.
7. Properties window-lists the properties of a currently selected object.
-When the properties window is not shown, click view>properties window.

Standard Controls
Form
-Foundation of all windows application.
Properties:
1. Name- a name used to refer to a form control in the code.
*use .NET NAMING CONVENTION in naming your form.
*objectPurpose+ObjectType
displaytextForm
computeForm
addForm
2. Text-changes the text displayed in the form title bar.
*To add a descriptive form title, complete the sentence
“This form allows you to__________.”
*Form title should be title capitalized.

Label
-Displays read-only text.
Properties:
1. Name- a name used to refer to a label control in the code.
2. Text-changes the label text.
Label design guide:
• Must contain one to three words.
• Should appear in one line.
• Must be typed in sentence capitalization.
• Should end with a colon.
2. Buttons
-elicits simple response
Properties
1. Name
2. Text
Design Guide:
1. Must have same height and width
2. Must be in one row or column
3. Button text must be title capitalized.

Assigning a value to a Control Property Programmatically


To assign/change the value of an object property through codes, use the following syntax:
Me.ControlName.Property=“value”
Me.ControlName.Property=value
Example:
Me.ageLabel.Text=23
Me.fnameLabel.Text=“John”
Arranging Form Controls
There are two ways to arrange form controls:
1. Vertical arrangement- information flows vertically.
2. Horizontal arrangement-information flows horizontally.

TextBox
-Accepts an input from the user.
Properties:
1. Name- a name used to refer to a textbox control in the code.
2. Text-sets/gets the textbox text.
• Textbox design guide:
*The width of the textbox depends upon the expected number of characters that will be
entered to it.
Variables and Data Types
A variable is a memory location that stores changeable value.
Naming Variables
• Begins with a letter
• Does not include spaces and punctuations.
• Must be at least 255 characters.
• Do not use reserved words as variables.

Declaring Variables
-To declare a visual basic.net variable, use the following syntax:
accessibilityCommand variableName as Data Type
Example:
dim intNum as integer
public strName as string

Scope of a Variable
1. Local variable- a variable known by one procedures.
– To create a local variable, use the dim accessibility command.
2. Global variable- a variable known by all procedures.
– To create a global variable, use the public accessibility command.

Data Types
Data Types defines the type of data that the variable will handle.

Type Stores Values Hungarian Notation

Boolea Logical values True,False bln+variableName


n blnMarried
Char One Character One character chr+variableName
chrInitials
Date Date and time information Date and time dtm+variableName
dtmBirthday
Double Floating Point Numbers Decimals dbl+variableName
dblSalary
Integer Whole Numbers Whole numbers int+variableName
Int Num
String Up to 2 billion characters Text str+ variableName
strAddress
Object Objects Obj+variableName

Mathematical Operators
-Performs calculation and computations.
-Also called arithmetic operators.

Operator Stores

^ Exponentiation
*,/ Multiplication and
Division
\ Integer Division
Mod Modulus Division
+,- Addition and Subtraction

Example:
1. Make a program that will ask two numbers and display the sum of the inputted numbers.
2. Write a program that will ask your dog’s age in years and convert it to human years. To convert dog years to human years,
multiply the inputted dog years by 15.

Activity:
1. Make a program that will asks two numbers and display the sum, difference, product , and quotient.
2. Write a program that will ask your cat age in years and convert it to human years. To convert a cat years to human years,
multiply the inputted cat years by 7.
3. Write a program that will ask your age and display how many days you have been alive.

Conditional Structure
-integrates decision making capability to your application.
-also known as conditional statements.
Relational Operators
-Compares values.
-Also known as comparison operator.

If Structure
-Executes a statement if the condition is true.
Syntax:
If condition Then
statement(s)
End If
Example:
1. Make an application that will asks a number and display its equivalent letter name.
2. Make an application that will add the two numbers if the first number is greater than the second
number.
Activity:
1. Make an application that will multiply two numbers if the second number is greater than the first
number.
If . . . Then. . . Else Structures
Executes statement or statements if the condition is true, executes another if the condition is false.
Syntax:
If condition Then
statement(s)
Else
statement(s)
End If
Example:
1. Make an application that will test if the inputted number is positive or negative.
Radio Button
Allows user to select one option from a list of options.
• Must be grouped.
• Use a maximum of six radio buttons per group.
Properties:
1. Name
2. Text
3. Checked

Checkbox
Allows user to select more than one option from a list of options.
• Must be grouped.
• Use a maximum of six checkboxes per group.
Properties:
1. Name
2. Text
3. Checked

ListBoxes
ListBoxes are used to select an item from a list of several options.
Properties:
1. Name
2. Add
3. Count
4. SelectedItem
5. SelectedIndex
6. Remove
ComboBoxes
A ComboBox is similar to a ListBox, but with some variations and some cool features.
ComboBoxes come in three styles: Simple, DropDown, and DropDownList.
1. Name
2. Add
3. Count
4. SelectedItem
5. SelectedIndex
Public Class Form1
Dim intFirstValue As Integer
6. Remove Dim intSecondValue As Integer
Dim strOperator As String

Private Sub oneButton_Click(ByVal sender As System.Object, ByVal e As


System.EventArgs) Handles oneButton.Click
Snippets: Me.displayTextBox.Text = Me.displayTextBox.Text + Me.oneButton.Text
End Sub

Private Sub twoButton_Click(ByVal sender As System.Object, ByVal e As


System.EventArgs) Handles twoButton.Click
Me.displayTextBox.Text = Me.displayTextBox.Text + Me.twoButton.Text
End Sub

Private Sub threeButton_Click(ByVal sender As System.Object, ByVal e As


System.EventArgs) Handles threeButton.Click
Me.displayTextBox.Text = Me.displayTextBox.Text + Me.threeButton.Text
End Sub

Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As


System.EventArgs) Handles MyBase.Load

End Sub

Private Sub minusButton_Click(ByVal sender As System.Object, ByVal e As


System.EventArgs) Handles minusButton.Click
intFirstValue = Val(Me.displayTextBox.Text)
strOperator = "-"
Me.displayTextBox.Clear()
End Sub

Private Sub plusButton_Click(ByVal sender As System.Object, ByVal e As


System.EventArgs) Handles plusButton.Click
intFirstValue = Val(Me.displayTextBox.Text)
strOperator = "+"
Me.displayTextBox.Clear()
End Sub

Private Sub equalsButton_Click(ByVal sender As System.Object, ByVal e As


System.EventArgs) Handles equalsButton.Click
intSecondValue = Val(Me.displayTextBox.Text)
If strOperator = "-" Then
Me.displayTextBox.Text = intFirstValue - intSecondValue
End If
If strOperator = "+" Then
Me.displayTextBox.Text = intFirstValue + intSecondValue
End If
End Sub
End Class

Public Class Form1


Private Sub Speak_Click(ByVal sender As System.Object, ByVal e As System.EventArgs)
Handles Button1.Click
Dim SAPI As Object
SAPI = CreateObject("SAPI.spvoice")
SAPI.speak(Me.TextBox1.Text)
End Sub
End Class

You might also like