58
1 ON VISUAL BASIC ?SUBMITTED BY: UDAY KUMAR ROLL NO: REGD. NO:

ON - imsumas.files.wordpress.com€¦  · Web viewMrs. Jayanti Mam . in our class. I would like to thank them whole heartedly for ... which helped me a lot in completing this assignment

  • Upload
    phamdat

  • View
    212

  • Download
    0

Embed Size (px)

Citation preview

1

ON

VISUAL BASIC

?SUBMITTED BY:UDAY KUMAR

ROLL NO:REGD. NO: B.SC (CA), PART – I SESSION: 2012 – 2015

2

ACKNOWLEDGMENT

This assignment has been developed on the basis of lectures delivered by Mrs. Jayanti Mam in our class. I would like to thank them whole heartedly for their noble guidance and superb teaching. She also encouraged me a lot while I was dealing with the assignment.

Last but not the least, My special thanks to all the Staff Members of the department, to My Friends and to My Family Members for their contributions in everything that I do and also for their uncanny ability to come up with suggestions, which helped me a lot in completing this assignment successfully.

Thanking You,

Uday Kumar

3

CERTIFICATEThis is to certify that student of B.Sc. in Comp.App(H), of Y S

Mahavidyalaya (Ranchi University) Ranchihaving Roll

number:

Regd. No.

Session 2011 – 2014 has successfully completed his assignment

on Paper – IV (B) (VISUAL BASIC).

I hereby declare that all the information made by me is true in

the best of my knowledge and I submit this assignment to the

department of “Computer Application” in the “Y S

Mahavidyalaya, Ranchi”.

Signature:-

External: Teacher-incharge

4

Department of BCA

INDEX

Sl. No.

Topic Page No.

1 Introduction of Visual basic 07-122 Timer Control 13

3 Scroll bar 14-15

4 Check box control 16-17

5 Radio Button or Option button 18-19

6 Combo Box 19-20

7 List box 21-22

8 Creation of picture box and Image box 22-24

9 Program to SUM TWO NUMBERS 2410 Program in V.B. to find the greatest no.

among two numbers.25-26

11 program in V.B. using text boxes and command buttons to perform simple arithmetic’s addition, subtraction, multiplication, division

26-29

5

12 program in V.B. to print

* * * * * * * * * ** * * * *

29-31

13 program in V.B. to print

1 2 3 4 5 6

31-32

14 program to print the number is prime or not

32-33

15 program for reverse of number in V.B. 3416 Program to generate following series in

V.B.1 , 2 , 3 , 4 , ………………………….20

35

17 Program to generate following series in V.B.2 , 4 , 6 , 8 , ………………………….n

35-36

18 Program to generate following series in V.B.1 , 8 , 27 , ………………………….125

36

19 Program to check that the given number is even or odd

37

20 Program to find the given number is palindrome ornot

37-39

21 Program to find out the FACTORIAL of any number

39-40

22 Program to create multiplication table 40

6

23 Program to find given string is PALINDROME or not

41

24 Program to SUM of ‘n’ NATURAL NUMBERS

42

25 W.A.P. to display time, date, your name, exit button text box

43

26 Program to generate the following pattern:1223334444

44

27 Program for connection with ms 45 - 48

VISUAL BASIC

7

(An Introduction)Visual Basic is one of the most popular programming languages. Microsoft has positioned it to fulfill the multiple purposes in the development. Visual Basic is designed to deploy application across the enterprise and to scale to nearly any assize needed. The ability to develop object models, database integration, server components and internet/intranet application provide and extensive range of capabilities and tools for the developer.

Visual Basic falls into a category of programming referred to as event-driven programming. Event-driven programs respond to events from the computer, such as the mouse button being pressed. The designer uses ready-made objects such as Command Buttons and Textboxes, to build user interfaces that make up the application. This approach to programming drastically reduces the amount of code required to develop a Window application.

What is Visual Basic? Visual Basic is a tool that allows you to develop windows

(Graphic User Interface - GUI) applicationsz The applications have familiar appearance to the user.

Visual Basic is event-driven, meaning code remains idle until called upon to some event (button pressing, menu selection …). Visual Basic is governed by an event processor. Nothing happens until an event is detected. Once an event is detected, the code corresponding to that event (event procedure) is executed. Program control is then returned to the event processor.

Event Processor

Event?

Basic Code Basic Code Basic Code

8

Event

procedures

The Visual Basic Program contains the following things:

The IDE

Like any other Windows application, VB consists of multiple windows, which appear at startup. The windows that are displayed when we start VB collectively that are known as the Visual Basic Integrated Development Environment (IDE).

When we first start VB all of the windows are looked together in what is called the MDI format. Here is a sample IDE screen which shows a VB project with one form on which is there are two Command Buttons.

Toolbox Code window Properties Windows

Fig: The Interactive IDE

Toolbox

9

The toolbox shows the basic controls that are available when we start a new project. The controls are added to the form to visually describe the appearance of the application. The toolbox is simply a library of controls, which we can place on our application. Each control has a set of properties, and a set of event procedures associated with it.

Fig: Toolbox

Project ExplorerThis is the window, which allows us to coordinate the parts of our program into folders for easy manipulation because all parts of the project appear in the Project Explorer arranged in a tree view. We can also add and remove items by right-clicking them with the mouse in the Project-Explorer.

10

Fig: Project Explorer

Properties WindowIt displays the properties of the currently selected form or project. Some of properties can be entered at design time within the IDE’s, while others must be entered with code while the program is running.

Fig: Properties Window

11

Form lay-out windows

Enables us to arrange the location where our forms appear on the screen. To give a form a new initial location, just we drag that form in the form layout window to hat new location.

Fig: Form Layout Window

Form Designers

Form designers are really just windows in which a particular form appears and are the main stage of our application. By default, the Standard EXE option starts with a form called Form 1. The Nameproperty should be named with the three letter’s prefix i.e. frm.This is the window provides workspace to draw different controls.

12

Fig: Form 1

Code Window

We just place the code we want to attach to an object in the code window (to open an object’s code in the code window, just double-click that object). There is two drop-down list boxes at the top of the code window: the left side lets we select the object to ad code to, and the right list lets we select the procedure to add (all the methods the object supports appear in this list).

Fig: Code Window

13

Timer Control:

Create a timer write in the timer event.

TimerCoding and Output

Fig: output for timer to show image

14

Scroll bar

Text box2 Vertical scroll bar

Text box 1 Horizontal scroll bar

A scroll bar are use to get the input or display output when we don’t care about the exact value of an object but we do care whether the change small or large.

1. Create two vertical and one horizontal scroll bar.

2. Also create three text box and three command bottom.

“RGB color combination in v.s”

i.e. Co – 255

3. Change the “name” properties of all the three scrolls as v1,h1 v2.

4. Set maximum and minimum value. Min = 0

Max=255

5. Write the following cording in the change event.

15

V1 i.e. vertical scroll bar.

Text1.text back color RGB (v1.value, h1 .value, v2.value)

6. Same coding will be written in v2 and h1 scroll bar.

7. Write in the change event of v1.

Write

Text2.text = v1.value & “,” & h1.value & “,” & v2.value “,”.

NOTE:

“Range of color is 165 out of 255”

Private sub h1 change ()

Text2.text back color = RGB (v1.value, h1.value, v2.value)

Text box 1

Code window vertical scroll bar

Horizontal scroll bar Text box 2

Scroll bar

16

Check box control

Fig: check box control

1. It is used in basically to stored logical value.

2. It is defer from option button in that regardless who many check boxesreplace on form they can also be turned on and off independently.

3. If we select a check box the value properties is true .If step true until the user deselect the box unclick of the option bottom.

Create a check box and a text box.

Write in click event of check box.

If check 1.value =1then

Text1.text= true and check1. Value

End if

Text box

Check box

17

Coding

output

18

Radio Button or Option button

Fig: option button

In option button when the user choose 1 button. All the other Button in the group of turned off for this reason any applications that uses more then 1 group of option buttons on a form must use a frame to separate the groups per pose of option button is choose from a finite list of possibilities

Coding

19

Output

Combo Box

In combo box we can add items at or in time by inpliciting value in it.But in list box we can allow any things at run time because we cannot give the spacitoenter (at design time).

20

Coding

Output

List box

21

Use list box we have fixed list of choice vb automatically acts vertical scroll bar whenever the list box is to small for all the items it Contac coding is same as the combo box.

Coding

Output

22

Creation of picture box and Image box

We can use picture box for many different content and draw the picture box. The icon for picture boxes are look like a deserve seen and reminds you that these holds graphical images.

the use of picture box has many advantage like:-

23

Picture box are memory hungry and you can more the 1 picture in same form.

Picture box holds three types of graphic:-

1. bitmap

2. icon

3. windows mega file

1. Bitmap:-

Bitmaps is a graphical image of screen. Image controls are often used for bitmap. The extension of bitfil is .BMP

2. Icon:-

Icons are supplied by VB. At list p type lists the 400or so icon supplied.

Picture box have so proportional is “true” the picture box automatically resize itself.

We can not change the original size of picture.

For drawing the picture and image follow the following step:-

1. Project menu:-

Component (List of external vender):- Microsoft window common control S.O :- Click it:-OK

Then draw a picture and icon box from coming icon.

24

The original size of image least is changed due to stretched property set Starch property “true”.

Output

PROGRAMS DEVELOPEDUSING VISUAL BASIC (IDE)

Program to SUM TWO NUMBERS:

Private Sub Form_Load ()Dim a As Integer, b as Integer, s as Integera = Input Box (“Enter the value for first number :”)b = Input Box (“Enter the value for second number :”)s = a + bMsgBox “The sum is = “&sEnd Sub

OUTPUTEnter the value for first number: 5Enter the value for second number: 8The sum is = 13

25

\* Program in V.B. to find the greatest no. among two numbers.

Private Sub Command1_Click ()

Dim a, b as integer

a = Val (text1.text)

b = Val (text2.text)

If a>b then

text3.text = a

Else

text3.text = b

End if

Level

button

Text button

Command button

26

End sub

OUTPUT:-

If

First number = 22

Second number = 33

Greater number is:-

Result= 33

\* program in V.B. using text boxes and command buttons to

perform simple arithmetic’s addition, subtraction, multiplication,

division *\

Private Sub Command1_Click ()

Dim a, b as Integer

a = Val (Text1.Text)

b = Val (Text2.Text)

Text3.Text = a + b

End Sub

Private Sub Command2_Click ()

Dim a, b as Integer

a = Val (Text1.Text)

27

b = Val (Text2.Text)

Text3.Text = a - b

End Sub

Private Sub Command3_Click ()

Dim a, b as Integer

a = Val (Text1.Text)

b = Val (Text2.Text)

Text3.Text = a * b

End Sub

Private Sub Command4_Click ()

Dim a, b as Integer

a = Val (Text1.Text)

b = Val (Text2.Text)

Text3.Text = a / b

End Sub

OUT PUT:-

Enter first number = 12

Enter second number = 6

Result – ADD = 18

SUB = 6

MULT = 72

28

DIV = 2

29

\* program in V.B. to print

*

* *

* * *

* * * *

* * * * * *\

30

Private Sub Command1_Click ()

Dim i, j, k as Integer

For i = 1 To 5

For k = 5 to i Step -1

Print " ";

Next k

Print "*";

Print " ";

Next j

Print

Next i

End Sub

31

OUTPUT:-

*

* *

* * *

* * * *

* * * * *

\* program in V.B. to print

1

2 3

4 5 6 *\

Private Sub Command1_Click ()

Dim a, b as Integer

C = 1

For a = 1 To 5

For b = 1 To a

Print c;

32

C = c+1

Next b

Print

Next a

End Sub

OUT PUT:-

1

2 3

4 5 6

\* program to print the number is prime or not *\

Private Sub Command1_Click ()

Dim n, a, f as Integer

n = Val (text1.Text)

a = 2

33

f = 0

Do While (a < n)

If (n Mod a = 0) Then

text2.Text = Number Is Not prime

f = 1

End If

Exit Do

Loop

If (f = 0) Then

text2.Text = "prime"

End If

End Sub

OUTPUT:-

If

Enter number = 31

Number is prime

Else

Enter number = 66

Number is not prime

\* program for reverse of number in V.B. *\

34

Private Sub Command1_Click ()

Dim rev, rev, and nas Integer

n = Val (Text1.Text)

Rev = 0

While (n > 0)

Rev n Mod 10

Rev = rev * 10 + rev

n = n \ 10

Text2.Text = rev

End Sub

OUTPUT:-

Enter the number = 12Result = 21

\* Program to generate following series in V.B.1 , 2 , 3 , 4 , ………………………….20 *\

35

Private Sub Command1_Click ()

Dim i, sum As Integer

Sum = 0

i = 1

Do While (i <= 20)

Sum = sum + i

i = i + 1

Loop

text1.Text = sum

End Sub

\* Program to generate following series in V.B.2 , 4 , 6 , 8 , ………………………….n *\

Private Sub Command1_Click ()

Dim n, i, sum As Integer

n = Input Box ("enter limit")

Sum = 0

i = 2

Do While (n >= i)

i = i + 2

36

Loop

text1.Text = sum

End Sub

\* Program to generate following series in V.B.1,8,27 ………………………..125 *\

Private Sub Command1_Click ()

Dim i, sum As Integer

i = 1

Sum = 0

Do While (i <= 5)

Sum = sum + (i * i * i)

i = i + 1

Loop

text1.Text = sum

End Sub

\* Program to check that the given number is even or odd *\

Private Sub Command1_Click ()

37

Dim n, flag As Integer

Flag = 0

n = Val (text1.Text)

Do While (n > 0)

If (n Mod 2 = 0) Then

Flag = 1

Exit Do

End If

Loop

If (flag = 1) Then

text2.Text = "number is even"

Else

text2.Text = "odd number"

End Sub

\* Program to find the given number is palindrome or not *\

38

Private Sub Form_Load()

Dim palin, r, s, a As an Integer

s = 0

a = Input Box (“Enter any number to check whether it is palindrome or not :”)

Palin = a

While a<>0

r = a Mod 10

s = s * 10 + r

a = a / 10

Wend

If s = palin Then

MsgBox “It is a palindrome”,,” Checking Palindrome”

39

Else

MsgBox “Not a Palindrome”, “Checking Palindrome”

End If

End Sub

OUTPUT:Enter any number to check whether it is palindrome or not: 12321

It is Palindrome

Enter any number to check whether it is palindrome or not: 12345

Not a Palindrome

\* Program to find out the FACTORIAL of any number *\

40

Private Sub Form_Load ()

Dim fact As Integer, i As Integer, n As Integer

Fact = 1

i = 1

n = Input Box (“Enter any number :”)

For i=1 to n

Fact = fact * i

Next i

MsgBox “The FACTORIAL is =” &fact

End Sub

OUTPUT:

Enter any number: 5

The FACTORIAL is = 120

\* Program to create multiplication table *\

Private Sub Command1_Click ()

Dim i, n As Integer

n = Input Box ("enter a number")

For i = 1 To 10

r = n * i

41

Debug. Print n; "*"; i; "="; r

Next

End Sub

\* Program to find given string is PALINDROME or not *\

Private Sub Form_ Load ()

Dim s1 As String, s2 As String, n As String

Dim l as Integer, i as Integer

Show

n = Input Box (“Enter any String: “)

l = Len (n)

For i = 1 to l

If (StrComp (Mid (n, i, l), Mid (n, 1, l)) <>0) Then

Print (“Not PALINDROME”)

Exit Sub

End If

l = l – 1

Next i

Print (“PALINDROME”)

End Sub

OUTPUT:Enter any String: Madam

PALINDROME

42

Enter any String: SHOBHAN

Not PALINDROME

\* Program to SUM of ‘n’ NATURAL NUMBERS *\

Private Sub Form_ Load ()

Dim n As Integer, sum As Integer, i As Integer

Sum = 0

n = Input Box (“Enter the numbers up-to which the sum of natural numbers is to be

generated :”)

For i = 1 to n

Sum = sum + i

Next i

MsgBox “The sum of natural numbers = “&sum

End Sub

OUTPUT:

Enter the numbers up-to which the sum of natural numbers is to be generated: 5

The sum of natural numbers = 14

43

W.A.P. to display time, date, your name, exit button text box?

Fig: Form layout

Code is as follows = >

Private Sub Command1_Click ()Text1=”Chandan_Splendid”End sub

Private Sub Command2_Click ()Text1= TimeEnd sub

Private Sub Command3_Click ()Text1= DateEnd sub

Private Sub Command4_Click ()EndEnd sub

44

Program to generate the following pattern:

1223334444------------------

Private Sub Form_ Load ()Dim i, j, n as Integersn = Input Box (“Enter any Number: “)For i = 1 to nFor j = 1 to iDebug. Print j;Next jDebug. PrintNext iEnd Sub

Output

1223334444--------------------------

45

\*Connection with ms-access in v.b*\

PROCESS

Add in Visual data manager file New M.A.

Select bob property Data bass window Dialog Version 7.0 mdb

Right click

New table Name of table Add file Dialog box open or close

OK

46

Build table Data base window Table double click or table right click

Add button click Open

Student

Name

Roll

Address

47

48

Tool box Data control Properties Data base name

Data source select Data 1 Record and Source table name

Output:-