You are on page 1of 36

1 Shah Abdul Latif University Khairpur (mir s), Sindh Department of Computer Science

INTRODUCTION TO VISUAL PROGRAMMING


Lab # 1
Objective: The objective is to review the basics of Visual programming. Theory Visual Basic (Business All-purpose Symbolic Instruction Code) is a tool that allows you to develop Windows (Graphic User Interface - GUI) applications.

How to open Visual Basic 6.0 Step 1: First click on start menu. Step 2: Click on All programs. Step 3: Microsoft Visual Basic 6.0 after that click on visual basic 6.0.

Visual Basic

2 Shah Abdul Latif University Khairpur (mir s), Sindh Department of Computer Science Visual Basic will open

New Project

Visual Basic

3 Shah Abdul Latif University Khairpur (mir s), Sindh Department of Computer Science

You must select/open Standard.Exe according to the above figure

Now, you can design a program by adding some tools like button, comobox, textbox, label etc. Program: 1 Write a program that display the message box of your name. Solution: Running a simple VB Program in Visual Basic 6.0 Step 1. First of all you have to select a form1. Step 2. Now, select a button from toolbox and draw on the form1 that button. Step 3. Now change the caption of form1 and button1, Form1 = MessageBox

Visual Basic

4 Shah Abdul Latif University Khairpur (mir s), Sindh Department of Computer Science Button1 = MessageBox

Step 4. Now, double click on button for code.

Step 5. After the code writing, you can run this program. For running program you must click on start button,

Step 6: During executation

Visual Basic

5 Shah Abdul Latif University Khairpur (mir s), Sindh Department of Computer Science

Step 7: To stop the program now you click on End button,

Program 2: Write a program that add to numbers and display the answer. Solution Step 1: Select Form1. Step2: Add two textboxes (text box1 and text box2). Step 3: Add three labels First for (Enter first value), second(Enter second value) and third (Answer). Step 4: Place a button also change the name property into Calculate.

Visual Basic

6 Shah Abdul Latif University Khairpur (mir s), Sindh Department of Computer Science

Step 5: Now double click on button calculate to write code,

Program 3: Write a program in which we input a number and that display it square. Solution Step 1: Select form1. Step 2: Add a label for Enter number for finding the square. Step 3: Add a text box in which you write any number. Step 4: Add two buttons by name of Exit and Calculate.

Visual Basic

7 Shah Abdul Latif University Khairpur (mir s), Sindh Department of Computer Science

Step 5: Now double click on the calculate button for code and exit button.

Program 4: Write code for cube according to the program 3. Solution: Step 1: Select form1. Step 2: Add a label for Enter number for finding the cube of give number. Step 3: Add two text boxes in which you write any number and other text box for display answer. Step 4: Add two buttons by name of Clear (both text boxes clear) and Calculate.

Visual Basic

8 Shah Abdul Latif University Khairpur (mir s), Sindh Department of Computer Science

Step 5: Now double click on the calculate button for code and clear button.

Program 5: Write a program in which you enter your marks and that display the Percentage and grade. Solution: Step 1: Select form1. Step 2: Add two labels for Enter your marks and Enter total marks for finding the Percentage. Step 3: Add two text boxes in which you write your marks and total marks. Step 4: Add a buttons by name Check.

Visual Basic

9 Shah Abdul Latif University Khairpur (mir s), Sindh Department of Computer Science

Step 5: Now double click on the check button for finding percentage.

Lab # 2
Objective: The object is to understand the concept the if-statement.
Theory THE if STATEMENT: To make a decision in simplest way in Visual Basic program is to use the If Then statement. Program 6: Write a program which compares two numbers, which number is greater/ less. Solution: Step 1: Select form1. Step 2: Add two labels for Enter first number and Enter second number for comparing numbers. Visual Basic

10 Shah Abdul Latif University Khairpur (mir s), Sindh Department of Computer Science Step 3: Add two text boxes in which you write numbers. Step 4: Add a buttons by name compare.

Step 5: Now double click on the compare button for the code.

Program 7: Write a program that get user name and password and show the next form. Solution Step 1: Select form1 and form2 Step 2: Add two labels for User name and Password in form1. Step 3: Add two text boxes in which you write name and Password.

Visual Basic

11 Shah Abdul Latif University Khairpur (mir s), Sindh Department of Computer Science Step 4: Add a buttons by name Sing in.

Form2 Step 5: Add a picture box then select a picture. Step 6: Add a button Log out that exit the program.

Step 7. Now double click on the Sign in button of form1 for code.

Visual Basic

12 Shah Abdul Latif University Khairpur (mir s), Sindh Department of Computer Science

Lab # 3
Objective: The object is to understand the concept of Select case statement.
Theory SELECT CASE STATEMENT: It is more flexible and a clearer format. Program 8: Write a program that get marks from user and give output in Grade/Pass and fail. Solution: Step 1: Select form1. Step 2: Add a labels for Enter your marks for Grade. Step 3: Add a text box for input the marks. Step 4: Add a buttons by name Check.

Visual Basic

13 Shah Abdul Latif University Khairpur (mir s), Sindh Department of Computer Science

Step 5: Now double click on the check button for the code.

Lab # 4
Objective: The object is to understand the concept of Loops.
Theory Loop: It is a program that repeat certain number times the statement. For Loop: The for loop execute the section of program a fixed number of times. Program 9: By using loop create a program that displays number from 1 to 10. Solution Visual Basic

14 Shah Abdul Latif University Khairpur (mir s), Sindh Department of Computer Science Step 1: Select form1. Step 2: Add a buttons by name Click Here

Step 3: Now double click on the button click here.

Program 10: By using For loop create a program that get base number and power from user and displays the power of a number. Solution: Step 1: Select form1. Step 2: Add two labels for Enter base and Power for finding power of a number. Step 3: Add two text boxes for input of numbers.

Visual Basic

15 Shah Abdul Latif University Khairpur (mir s), Sindh Department of Computer Science Step 4: Add two buttons one for clear text boxes and next for calculate the power.

Step 5: Now write the code,

Program 11: By using while loop create a program that get a number from user and displays the power of a number. Solution Step 1: Select form1. Step 2: Add a label for Enter number. Step 3: Add text boxes for input of number. Step 4: Add a buttons for finding square.

Visual Basic

16 Shah Abdul Latif University Khairpur (mir s), Sindh Department of Computer Science

Step 5: Now write the code,

Program 12: Create a program that displays odd and even numbers. Solution Step 1: Select form1. Step 4: Add two buttons Odd and Even, to print these numbers on form.

Visual Basic

17 Shah Abdul Latif University Khairpur (mir s), Sindh Department of Computer Science

Step 3: Write the code for odd and even number using for loop,

Program 13: Create a table by using loop. Solution Step 1: Select form1. Step 2: Add a label for Enter number for which you want to display the table. Step 3: Add text boxes for input of number. Step 4: Add a list box for displaying the result of table. Step 5: Add a buttons click here. Visual Basic

18 Shah Abdul Latif University Khairpur (mir s), Sindh Department of Computer Science

Step 6: Now write the code for the table,

Program 14: Create a program to display 10 time hello world! Message by using do-while loop. Solution Step 1: Select form1. Step 2: Add a buttons for display hello 10 times by using while loop.

Visual Basic

19 Shah Abdul Latif University Khairpur (mir s), Sindh Department of Computer Science

Step 3: Now write the code,

Program 15: Write a program for bold text and Italic font using check boxes. Solution Step 1: Select form1. Step 2: Add a text box for input some text. Step 3: Add two check boxes first for font bold and other for font italic.

Visual Basic

20 Shah Abdul Latif University Khairpur (mir s), Sindh Department of Computer Science

Step 4: Now write the code of that program,

Program 16: Write a program that display time, date, month, year and day. Solution Step 1: Select form1. Step 2: Add five labels for (day, time, date, month and year).

Visual Basic

21 Shah Abdul Latif University Khairpur (mir s), Sindh Department of Computer Science

Step 3: Write the code of the program,

Program 17: By using check boxes write a program that display time, date, month, year and day. Solution Step 1: Select form1. Step 2: Add five labels for display (month, year, hour, minutes and seconds). Step 3: Add five check boxes (month, year, hour, minutes and seconds). Step 4: Add a button OK.

Visual Basic

22 Shah Abdul Latif University Khairpur (mir s), Sindh Department of Computer Science

Step 5: Write the following code for the program,

Program 18. Write a program that get input (in input box) from user and give answer.

Visual Basic

23 Shah Abdul Latif University Khairpur (mir s), Sindh Department of Computer Science

Code

Program 19. By using list box, write a program that get input (name), and perform add, remove, clear and font (Bold, italic and underline).

Visual Basic

24 Shah Abdul Latif University Khairpur (mir s), Sindh Department of Computer Science

Code

Visual Basic

25 Shah Abdul Latif University Khairpur (mir s), Sindh Department of Computer Science Program 20: Create a program that show all types dialog boxes, like (OK only, Ok cancel, Yes No, Error, Exclamation, Information, try again etc).

Code

Visual Basic

26 Shah Abdul Latif University Khairpur (mir s), Sindh Department of Computer Science

Program 21: By using Array write a program that gets input box user and display these number with their position.

Code Visual Basic

27 Shah Abdul Latif University Khairpur (mir s), Sindh Department of Computer Science

Strings Program 22. Write a program that gets strings from user and concatenate the strings. Solution Step 1: Select form1. Step 2: Add two text boxes for input some text. Step 3: Add a button which concatenate both text boxes text. Step 4: Add two labels for display the concatenated result of text.

Step 5: Now write the code for the program,

Visual Basic

28 Shah Abdul Latif University Khairpur (mir s), Sindh Department of Computer Science

Program 23. Write a program in you use like keyword which show the difference like True/False. Solution Step 1: Select form1. Step 2: Add a button for Like Demo.

Step 3: Write the code for the program,

Visual Basic

29 Shah Abdul Latif University Khairpur (mir s), Sindh Department of Computer Science

Program 24. Write a program that in that works like a windows explorer, by using drives, folders, files and pictures, also show file s location. Solution

Code

Visual Basic

30 Shah Abdul Latif University Khairpur (mir s), Sindh Department of Computer Science

Graphics Program 25. Write a program that show a pixel point on the form.

Code

Visual Basic

31 Shah Abdul Latif University Khairpur (mir s), Sindh Department of Computer Science Program 26. Write a program that print line, that gets input using two text boxes first(get border style from 0 to 6) and second (get border width).

Code

Program 27: Write a program that display graphics shapes (line, circle and rectangle).

Visual Basic

32 Shah Abdul Latif University Khairpur (mir s), Sindh Department of Computer Science

Code

Program 28: Write a program that tells us the Location of button. Solution

Visual Basic

33 Shah Abdul Latif University Khairpur (mir s), Sindh Department of Computer Science

Code

Program 29: Write a program that displays the size (Height and width) of form. Solution

Visual Basic

34 Shah Abdul Latif University Khairpur (mir s), Sindh Department of Computer Science

Code

Program 30: write a program that draw a graphical picture of circle with different styles. Solution Step 1: Select form1. Step 2: Add a picture box. Step 3: Add three text boxes for input of number. Step 4: Add two buttons for (Draw picture and remove the picture). Step 5: Add a check box for Auto Draw picture.

Visual Basic

35 Shah Abdul Latif University Khairpur (mir s), Sindh Department of Computer Science

Step 6: Now write the code for the program,

Visual Basic

36 Shah Abdul Latif University Khairpur (mir s), Sindh Department of Computer Science

Visual Basic