Module 1-3 - VB Express
Module 1-3 - VB Express
MODULE 1
INTRODUCTION TO PROGRAMMING
1.
Name of Module
: Introduction to programming
2.
Learning Outcomes
3.
4.
Module Summary
a. Understand the definition of programming language. b. Understand the phases of Program Development.
Introduction to programming
1. What is programming? Programming refers to the act of instructing the computer to do something for us with the help of programming language.
2. What is a programming language? A Programming Language is a set of rules that provides a way of telling the computer what operation to perform (according to Capron and Johnson,2004)
3. What programming languages are available? Before looking at a specific programming language, we need to know the levels of programming languages. Language is said to be lower or higher depending on how close they are to the language the computer itself uses or to the language people use (more English-likehigh). These programming languages are generally divided into five levels or generations :a. b. c. d. e. Machine Language Assembly Language High-Level Language Very High-Level Language Natural Language
The following are the descriptions of each level of programming language :Level of language Machine Language Descriptions Ultimately the computer understands only binary number-strings of 0s and 1s. Programs that are written in these 0s and 1s represent the on and off electrical states of computer. All other languages must be translated into machine language before executing instructions. This programming language is considered very low level. This language use mnemonic codes, abbreviations that are easy to remember such as : A for add, C for compare, MP for multiply and so on.
Assembly Language
High-Level Language
For this language, programmers no longer need to have detailed knowledge of computer hardware to produce a programme. This language is closer to human language compare to the machine language.
Often known as fourth generation language(4 GLs). This programming language is an improvement of high-level language.
This programming language is also called the fifth generation language. This language is similar to the natural spoken or written English Language. The natural language translates human instructions into code that the computer can understand and execute.
Natural Language
4. Examples of Programming Languages. Examples of programming languages are :a. BASIC b. COBOL c. PASCAL d. C e. FORTRAN f. VISUAL BASIC
g. C++ h. JAVA
Lets look at samples of each interface for the programming languages :a) Example of C programming taken from (http://encyclopedia.laborlawtalk.com/wiki/images/thumb/5/5c/500px-Qbasic.png time) 11.20/16.6.2006.
f)
Lets look at the descriptions of each main phase in program development: 1. Problem Analysis What is problem analysis? You need to identify the problem before developing a program. Lets imagine that you are a programmer. As a programmer, you are contacted because your services are needed. You meet with users from the client organization to analyze the problem, or you meet with a systems analyst who outlines the project. Specifically, the task of defining the problem consists of identifying what it is you know (input-given data), and what it is you want to obtain (output-the result). Eventually, you produce a written agreement that, among other things, specifies the kind of input, processing, and output required. This is not a simple process.
2. Program Design In this phase, you will do the following tasks : Plan the solution to the problem (think about how will you solve the problem) Choose the interface (think about how will your program look like)
3. Coding So now you are ready to write the code of the program that you have planned. You need to express your solution in a programming language. The normal process you will go through is to translate the logic from the flowchart or pseudocode-or some other tool-to a programming language. The following are examples of both tools: a) Example of a flow chart
10
As we have already noted, a programming language is a set of rules that provides a way of instructing the computer what operations to perform. There are many programming languages: BASIC, COBOL, Pascal, FORTRAN, and C are some examples. You may find yourself working with one or more of these. However in this module, we will either produce a program using Microsoft VB-express or Just BASIC v1.01. Although programming languages operate grammatically, somewhat like the English language, they are much more precise. To get your program to work, you have to follow exactly the rules-the syntax-of the language you are using. Of course, using the language correctly is no guarantee that your program will work, any more than speaking grammatically correct English means you know what you are talking about. The point is that correct use of the language is the required first step. Then your coded program must be keyed, probably using a terminal or personal computer, in a form the computer can understand. One more note here: Programmers usually use a text editor, which is somewhat like a word processing program, to create a file that contains the program. However, as a beginner, you will probably want to write your program code on paper first.
4. Testing and Debugging The fourth phase is to test and debug your program. Why do you need to test? The imperfections of the world are still with us, so most programmers get used to the idea that their newly written programs probably have a few errors. This is a bit discouraging at first, since programmers tend to be precise, careful, detail-oriented people who take pride in their work. Still, there are many opportunities to introduce mistakes into programs, and you, just as those who have gone before you, will probably find several of them.
11
Why debug? You need to debug to improve your program. Debug is a term used extensively in programming. Debugging means detecting, locating, and correcting bugs (mistakes), usually done by running the program. These bugs are logic errors, such as telling a computer to repeat an operation but not telling it how to stop repeating. In this phase you run the program using test data that you devise. You must plan the test data carefully to make sure you test every part of the program. How do you debug? You can carry out debugging by running the program. The following are examples of debugging for Visual Basic Express and Just BASIC. a) debugging button in Visual Basic Express
12
5. Documentation Documentation is important when programming. Documenting is an ongoing, necessary process, although, as many programmers are, you may be eager to pursue more exciting computer-centered activities. What is documentation? Documentation is a written detailed description of the programming cycle and specific facts about the program. Typical program documentation materials include the origin and nature of the problem, a brief narrative description of the program, logic tools such as flowcharts and pseudocode, data-record descriptions, program listings, and testing results. Comments in the program itself are also considered an essential part of documentation. Many programmers document as they code. In a broader sense, program documentation can be part of the documentation for an entire system. The wise programmer continues to document the program throughout its design, development, and testing. Documentation is needed to supplement human memory and to help organize program planning. Also, documentation is critical to communicate with others who have an interest in the program, especially other programmers who may be part of a programming team. Written documentation is needed in computer industry so that those who come after you can make any necessary modifications in the program or track down any errors that you missed.
13
MODULE 2
14
1. Name of module
2. Learning Outcomes
: The students should be able to :a. State the features of the programming tools. b. Identify the visual development environment of programming tool : Toolbar Toolbox c. Create object using toolbox : Label Button Textbox Picture box
4. Module Summary
: At the end of the module, students should be able to develop a simple programme.
15
Free download Created standalone Window programmes are royalty free. Full tutorial and various examples of programmes are provided online. Large online community. Uses Graphical User Interface (GUI). Uses drag and drop interface designer. Interactive development environment. Easy to carry out debugging.
3. What will you produce using Microsoft Visual Basic Express 2005? It is hoped that at the end of this lesson, you will be able to produce a simple programme that consists of your biodata. In your programme you will learn how to create a programme that has your photo, your particulars and how to create a user log in that uses password. In doing so, you will experience using simple coding in Microsoft Visual Basic Express 2005.
16
2. To create new project, select File New Project Window Form Screen will be displayed
17
18
5. Form1 (shown below) developing form appears where you can draw your application.
6. Click ToolBox on the left side of the screen and all the control will be displayed. Then Click All Windows Forms
19
(Windows Position)
20
8. Click TextBox
9. Drag and drop the TextBox at the position as shown below ( Form1).
TextBox
21
10. To resize Textbox , click and drag the TextBox as shown below.
(resize)
(move )
11. Create another three TextBox by repeating step 8 and 9. 12. Click Label in order to create four new labels.
Label
22
PictureBox
23
Button
24
18. Click File from the menu bar and select Save al to save your project. (Name : MyBiodata). Then, click Save in Save Project popup box.
25
19. From the Windows Properties, set properties for the Form, TextBox, Label, PictureBox and Button. Then, rename them according to the table below.
Windows Properties
Controls
CONTROL BOX Form1 Label1 Label2 Label3 Label4 TextBox1 TextBox2 TextBox3 TextBox4 Button1 PictureBox1
CONTROL Text Name Text Text Text Text Name Name Name Name Multiline Name Text Image
DEFAULT Form1 Form1 Label1 Label2 Label3 Label4 TextBox1 TextBox2 TextBox3 TextBox4 False Button1 Button1 (none)
RENAME MyBiodata frmBiodata Name Sex ICNum Address txtName txtSex txtICNum txtAdd True btnExit Exit Refer page 27
26
27
23. Now, choose an image from sample pictures folder (eg : water lilies). Click Open then click OK.
24. In order to place the water lilies picture in the picture box, you need to click (Picturebox Tasks) and change the size mode to StrecthImage
28
25. Next, set properties for the Form MyBiodata :CONTROL BOX frmBiodata txtName txtSex txtICNum txtAdd Text Text Text Text CONTROL Backcolour INFORMATION browse colour (choose colour) CHOO KENG FOOK MALE 951031-10-1668 55, JALAN UBI, 42100 KLANG
26. Your form should now look like this and to view the coding, double click the Exit Button to enter code mode.
29
27. In the Exit button code mode, type Application.Exit() as shown below.
28. To Run the programme, click at the menu bar or press (F5) and the window below will be displayed.
30
30. To add a new window form : On the right frame, right click at MyBiodata project. Choose Add and click Windows Form.
Click here
31. Now, your windows form will look like this. Choose the Windows Form templates and name the form (eg : frmLogin). Then, click Add.
31
33. Create two TextBox, two Label, one PictureBox and two Button.as shown below.
32
34. Set properties of the Form, two TextBox, two Labels, one PictureBox and one Button CONTROL BOX frmLogin Label1 Label2 TextBox1 TextBox2 Button1 Button2 PictureBox1 CONTROL Text Name Backcolour Text Text Name Name Passwordchar MaxLength Name Text Name Text Image DEFAULT frmLogin frmLogin browse colour (choose colour) Label1 Label2 TextBox1 TextBox2 32767 Button1 Button1 Button2 Button2 browse image RENAME
33
36. To view the coding, double click the Cancel Button and type Me.Close() in the code mode.
34
38. To view the coding, double click the OK Button and type the content in the box. If txtName.Text = "CHOO" And txtPw.Text = "123" Then frmBiodata.Show() Me.Hide() Else MessageBox.Show("Incorrect username or password, please try again") End if
39. On the Menu Bar, click Project and choose MyBiodata Properties.
35
40. MyBiodata Properties form will be displayed. Go to Startup form then click drop down menu and choose frmLogin.
43. To test the program, type name CHOO and type Password 123. Then click OK.
36
MODULE 3
37
1. Name of module:
2. Learning Outcomes:
The students should be able to :a. Declare variables String Integer Double b. Write code for a simple programme.
a. Definition of programme and programming language. b. Able to identify the visual development environment of programming tool. c. Able to create object using toolbox.
4. Module Summary:
At the end of the module, students should be able to develop a simple programme.
38
Declaring Variables
The keyword Dim is use to declare Variables. (Eg : Dim name as string, Dim balance as double, Dim days as integer)
39
3. Change the properties of the Control Box based on the following table. CONTROL BOX CONTROL Name Text BackColor Name Text Name Text Name Text Name Text Name Text Name Text AutoSize Name Name Name Name ReadOnly Name Text Name Text Name Text Image DEFAULT Form 1 Text browse colour (Choose colour) Label1 Label1 Label2 Label2 Label3 Label3 Label4 Label4 Label5 Label5 Label6 Label6 True TextBox1 TextBox2 TextBox3 Textbox4 False Button1 Button1 Button2 Button2 Button3 Button3 browse image (Choose image) RENAME frmSaving My Savings
Form 1
Label 1 Label 2 Label 3 Label 4 Label 5 Label 6 TextBox1 TextBox2 TextBox3 TextBox4 Button 1 Button 2 Button 3 PictureBox1
lblTitle HOW MUCH CAN I SAVE ? lblName Name lblBalance Balance Per Day (RM) lblDays Days lblTotal Total (RM) lblNotice False txtName txtBalance txtDays txtTotal True btnCount COUNT btnReset RESET btnExit EXIT
40
5. To save the application, click File and select Save all. 6. To view the coding, double click anywhere on the form. Public Class frmSaving Dim Name As String Dim Balance As Double Dim Days As Integer Dim Total As Double
Private Sub frmSaving_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load End Sub End Class 7. Click on the tab Form1.vb[Design]*.
Click here
8. Double click on COUNT button and type the following :Private Sub btnCount_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnCount.Click Name = (txtName.Text) Balance = Val(txtBalance.Text) Type the following syntax Days = Val(txtDays.Text) Total = Balance * Days txtTotal.Text = Total lblNotice.Text = Name & " your total saving for " & days & " days is RM " & total End Sub
41
9. Click on the Form1.vb[Design]* tab as in step 7. 10. Double click on RESET button and type the following. Private Sub btnReset_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnReset.Click txtName.Text = " " txtBalance.Text = " " txtDays.Text = " " txtTotal.Text = " " End Sub
11. Click on the Form1.vb[Design]* tab as in step 7. 12. Double click on EXIT button and type Me.Close() 13. To save the application, click File and select Save all 14. To Run program, click / (F5) and frmSaving window will be displayed.
42
15. To test the program, type :Name Balance Per Day (RM) Days and click COUNT. : Choo : 124.35 :3
43