You are on page 1of 7

Simpo PDF Password Remover Unregistered Version http://www.simpopdf.

com
COLLEGE OF INFORMATION TECHNOLOGY Lab 3 -Simple Programming 1 (String) OBJECTIVES OF LAB: To Understand datatypes To Understand String

Objective 1: Datatypes
Data comes in few types. VB handles 14 types of data, in which we only use about 5 of them. They are: Type String Explanation Data that holds characters, include symbols $, -, ?, *, space and etc. Example A289785 6 Suzana Bt Ibrahim 772211-99-7788 Lot 246, Jalan Air Mati Intege r Long integer Single Boolea n Holds integer value between 32768 to +32767. Holds bigge valu betwee r e n 2147483648 to + 2147483647 Holds real value. Holds data that have only two options. 44.53 1002.25 Male/Female On/Of f Yes/No 47 7556

Objective 2: String
String can be assigned into any variables, or appear as it is or input from text box. If any string should appear as it is, or being assigned to any variables, it will be put into doublequote such as Good to hear from you again! In string, the only operation can be done with it is concatenation. It is joining two or more strings to form a new string, by using a joining operator &. Building a simple form with a button 1. Open Visual Basic. Select 6.0. Select Standard EXE, and click Open.

Revised: 30/6/2004 S.G

Simpo PDF Password Remover Unregistered Version http://www.simpopdf.com


2. Click on your form. Properties Windows is now showing on the right hand side. If you cannot see this window, click View, then click Properties Window.

3. Make sure it is for your form by looking at the properties window title. Then type the following into respective row in your properties window. Form: (name ) BackColor Captio n WindowState : frmOne : Light Blue : My First Screen! : 2-Maximized

4. Click on CommandButton, and place it on the work area (frmOne). 5. See your Properties Windows on the right hand side. 6. Make sure it is for command button. Type this into appropriate setting CommandButto n (name ) Captio n Font

: cmdOne : Try Me! : Garamond Bold 14

Revised: 30/6/2004 S.G

Simpo PDF Password Remover Unregistered Version http://www.simpopdf.com

7. Then try to run this screen. Place the command button in the center of your form so it will look nice. Building a simple form with label, text, picturebox and button. String from text box. 1. Click Project on the menu bar, and click Add Form. Choose Form, and click Open. 2. Click on your form. Properties Windows is now showing on the right hand side. Type this into appropriate setting Form: (name ) BackColor Captio n WindowState : frmTwo : Light Red : My Second Screen! : 2-Maximized

3. Click on Label and place it on your work area (frmTwo). See your Properties Windows on the right hand side and type this into the setting. Label (name ) BackColor Captio n
Revised: 30/6/2004 S.G

: lblTwo : Light Green : Type your message here -->

Simpo PDF Password Remover Unregistered Version http://www.simpopdf.com


Font : Arial Bold 11 4. Click on Textbox and place it on your work area (frmTwo). See your Properties Windows on the right hand side and type this into the setting. TextBox (name ) BackColor Font Text : txtTwo : Light Green : Arial Bold 11 :-

5. Click on PictureBox and place it on your work area (frmTwo). See your Properties Windows on the right hand side and type this into the setting. PictureBox (name ) BackColor Font : picTwo : Light Green : Arial Bold 11

6. Click on CommandButton and place it on your work area (form2). See your Properties Windows on the right hand side and type this into the setting. CommandButton l (name ) Captio n Font

: cmdTwo : Proceed! : Garamond Bold 14

7. Click Project, and choose Project1 Properties. Find Startup Objects, and choose from the combo box, frmTwo. Click OK.

Revised: 30/6/2004 S.G

Simpo PDF Password Remover Unregistered Version http://www.simpopdf.com

8. Run the second screen and see what you have done so far. 9. Get back to the frmTwo. Double-click on the command button, in which you will get a page with this words: Private Sub cmdTwo_Click() End Sub 10. Notice that this refer to cmdTwo, which is the command button. cmdTwo_Click means, the command button named cmdTwo, with action Click. What happen if cmdTwo was clicked? 11. Type a few lines of codes between those two lines above, as below: Private Sub cmdTwo_Click() Dim MyWords As String MyWords = txtTwo.Text picTwo.Cls picTwo.Print MyWords End Sub Dim MyWords As String MyWords = txtTwo.Text picTwo.Cl s picTwo.Print words : Introduce a variable named words, datatype is string (text). : assign any text in textbox to variable MyWords : clear all previous text on picturebox : print text from variable MyWords into the picturebox.

12. Run this screen. Type something into your text area, and click the button.

Revised: 30/6/2004 S.G

Simpo PDF Password Remover Unregistered Version http://www.simpopdf.com


13. Back to code window. Try put a single quote at the beginning of line picTwo.Cls. Run again and see the difference. Combining two screen 1. Open your frmOne. 2. Double click on the cmdOne, to show the code area as below: Private Sub cmdOne_Click() End Sub 3. Put this line in between header and ending: frmTwo.Sho w 4. Click Project, choose Project1 Properties. Under Startup objects, change back to frmOne. Click OK and then run the program again, and see what happen. 5. Open frmTwo in form window. Insert another commandbutton, with this properties: CommandButto n (name : cmdExit ) Captio : Exit n Font : Garamond Bold 14 6. Double click on the cmdExit, and type this into the code lines: Private Sub cmdExit_Click() End End Sub 7. Save and close all your forms and project.

Revised: 30/6/2004 S.G

You might also like