Вы находитесь на странице: 1из 23

Visual Basic Program

Start Programs Microsoft visual studio 6.0 Microsoft visual basic 6.0

A
F4 F5

Label = caption Properties window Program Run Text Box

ab

Text Box = Text Command Button Command = Caption Form 1 x Enter a value Text Box Enter b value
add

Command

Label Right click view code

Command 1 x

x
-

Form command1_click () Private sub 1

Text3.text = val(text1.text) + val(text2.text)


Enter a value

End subEnter b value


Output:

The value of a+b is

2 40 52 Add 92

Biggest value Command1 Private sub command1_click () Form 1

-x If val(text1.text) > val(text2.text) then


Text3.text = a is big Enter a value Else Text3.text = b is big Enter b value End if End sub
40 Bi 52 g

B is big

Command1 Private sub command1_click () If val(text1.text) < val(text2.text) then Text3.text = a is small Else
Form 1

-x

Enter a value

Output:

Text3.text = b is small End if End sub

Enter b value

40 52 Small

a is small

FOR LOOP Command1

Form 1

-x

Click

Private sub command1_click () For i=1 to 4 step 1 Print i Next i End sub
Form 1

Output:

1 2

Cli ck
4 9 16 25 36 4321 4321 4321 4321 4321

Out puts: 11 22 33 44 55 -5 -4 -3 -2 -1 12 24 36 48 60

3 4

DOUBLE LOOP Command1 Private sub command1_click () For i=1 to 5 step 1 For j=1 to 4 step 1 Print j; Next j Print Next i End sub Outputs: 3 6 9 12 3 6 9 12 3 6 9 12 -3 -2 -1 0 1 2 -3 -2 -1 0 1 2 -3 -2 -1 0 1 2 4 9 16 25 36 4 9 16 25 36 4 9 16 25 36 * * * ** ***** *****
1234 1234 1234 1234 Form 1

Output:

-x

Click

3 6 9 12

-3 -2 -1 0 1 2

4 9 16 25 36

*****

INNER LOOP Private sub command1_click () For i=-1 to -5 step -1 For j=-3 to i step 1 Print j; Next j Print Next i End sub Outputs: 10 10 8 10 8 6 10 8 6 4 10 8 6 4 2 10 8 6 4 2 0 10 8 6 4 2 0 -2 10 8 6 4 2 0 -2 -4 -3 -2 -3
Form 1

Output:

-x
-5 -4 -3 -2 -1 -5 -4 -3 -2 -5 -4 -3 -5 -4 -5

Click

-3 -2 -1 0 1 2 3 4 -3 -2 -1 0 1 2 3 -3 -2 -1 0 1 2 -3 -2 -1 0 1 -3 -2 -1 0 -3 -2 -1 49

4 9 16 4 9 16 25 4 9 16 25 36 4 9 16 25 36 49 64 4 9 16 25 36 49 64 81 4 9 16 25 36 49 64 81 100

Option Button Command1 Private sub command1_click () If option1.value then


BOLD ITALIC UNTERLINE CLICK TCDS COMPUTER

Label1. Font Bold = True Else If option2.value then Label1. Font Italic = True Else If option3.value then Label1. Underline = True End if End if End if End sub

OUTPUT:
Form1

TCDS COMPUTER EDUCATION


BOLD ITALIC UNTERLINE

CLICK

Form1 TCDS COMPUTER EDUCATION Strikethuru Font Name Font Color

Font Size Private sub command1_click () If option1.value then Label1.Font strikethuru = True Else If option2.value then Label1.Font Name = Arial Else If option3.value then Label1.Fore Color = vb red Else If option4.value then Label1.Font Size = True Else End if End if End if End if End sub
Strikethuru Font Name Font Color Font Size

OUTPUT:

TCDS COMPUTER EDUCATION

CLICK

Check Box

THE BEST SYSTEMS


BOLD ITALIC UNTERLINE

Label Box

Private sub command1_click () If check1.value then Label1.Font Bold = True Else If check2.value then Label1.Font Italic = True Else If check3.value then Label1.Font Underline = True Else End if End if End if End sub OUTPUT:

Font Bold

TCDS COMPUTER EDUCATION

Font Italic Font Underline

CLICK

Form1 Total Km from Salem Total Rs from Salem Chennai


CLIC K

Kovai

Trichy

Private sub command1_click ()

If option1.value = True then Text1.text = 125 km Text2.text = Rs 180 Else If option2.value = True then Text1.text = 452 km Text2.text = Rs 280 Else If option3.value = True then Text1.text = 75 km Text2.text = Rs 80 End if End if End if End sub
Chennai Kovai Trichy Total Rs from salem 180 Rs CLICK Form1 125 km

Total km from salem

Line program
Line 0 - Transparent 1 Solid 2Form1

Dash

3 Dot 4 Dash Dot 5 Dash-Dot-Dot 6 Inside Solid

Form1 Transpare X nt

Solid Dash Dot

Dash-Dot
Command1

Dash Dot Dot

Inside Solid

Private sub command1_click () Line1.Border style = 0 End sub Private sub command2_click () Line1.Border style = 1 End sub Private sub command3_click () Line1.Border style = 2 End sub Private sub command4_click () Line1.Border style = 3 End sub Private sub command5_click () Line1.Border style = 4 End sub Private sub command6_click () Line1.Border style = 5

End sub Private sub command7_click () Line1.Border style = 6 End sub

10

OUTPUT:

Form1 X

Transpare nt Dash-Dot

Solid

Dash

Dot

Dash Dot Dot

Inside Solid

Shape
0 Rectangle 1 Square 2 Oval
From1 X -

3 Circle 4 Rounded rectangle

Rectangl e Circle
Command1

Square r.rectang le

Oval r.square

5 Rounded Square

Private sub command1_click () Shape1.shape = 0

End sub Private sub command2_click () Shape1.shape = 1 End sub Private sub command3_click () Shape1.shape = 2 End sub Private sub command4_click () Shape1.shape = 3 End sub Private sub command5_click () Shape1.shape = 4 End sub Private sub command6 _click () Shape1.shape = 5 End sub OUTPUT:

11

From1 X

Rectangl e Circle
Timer
3

Square r.rectang le

Oval r.square

1 2 2

Form1 Private sub Timer1_click () If form1.caption = cchinna then Form1.caption = saravanan Else Form1.caption = cchinna End if End sub Private sub Timer2_timer () Label1.caption = Time End sub List Box
9
1 2 2 1 2 2

12

(interval-100)

cchinna (or) saravanan

10:50:

List Box1 List Box2

Text Box1 Text Box2

Command 1 Command 3

Command 2 Command 4

Private sub command1_click () List1. AddItem Karthik List1. AddItem Durai List1. AddItem Yuvaraj List1. AddItem Kannan List1. AddItem Prakash End sub OUTPUT:
Karthik durai Yuvaraj kannan

mani

Private sub command2_click () Durai


mani

List1. AddItem Text1. Text List2. AddItem Text1. Text End sub

13

List 1 Add

Private sub command3_click () List2. AddItem List1. Text End sub

Text 1 to List1 List 2 Remove

List 1 to List 2

Private sub command4_click () List2. RemoveItem List2. List Index End sub Combo Box

Combo Box1 Combo Box2

Text Box1 Text Box2

Command 1 Command 3

Command 2 Command 4

Private sub command1_click () Combo1. AddItem Karthik Combo1. AddItem Durai OUTPUT:

Combo1. AddItem Yuvaraj Karthik Combo1. AddItem Kannan durai Combo1. AddItem Prakash Yuvaraj End sub
kannan

Mani

Private sub command2_click () Durai Combo1. AddItem Text1. Text mani Combo2. AddItem Text1. Text

End sub

14

Combo 1 Add

Private sub command3_click () Combo2. AddItem Combo1. Text Combo 1 to End sub Combo 2 Private sub command4_click () Combo2. RemoveItem Combo2. List Index End sub Scroll Bar Text Box

Text 1 to Combo 1 Combo 2 Remove

500

Vscroll

250

Hscroll

Large change = 1000 Max = 2000 Min = 50 Small Change = 200

Max = 5500 Min = 10 Large change = 2500 Small change = 30

Private sub HScroll_ change () Text2. Text = HScroll. Value End sub

Private sub VScroll_ change () Text1. Text = VScroll. Value End sub

15

Drive List Box Dir List Box File List Box C: (System) C: \ Program Files Microsoft Visual Studio VB 98 Template Wizards Coding: Private sub Dir1_ change () File1. Path = Drive1. Path End sub Private sub Drive1_ change () Dir1.Path = Drive1. Drive End sub

16

Frame Total km from

Total Rs from

From Salem To Salem Chennai Chennai Kovai CLICK Kovai

Option Button Private sub command1_click () If option1. Value = True and Option5. Value then Text1. Text = 250km Text1. Text = Rs.135 Else If option1. Value = True and Option6. Value then Text1. Text = 165km Text1. Text = Rs.85 Else

Frame

17

If option2. Value = True and Option4. Value then Text1. Text = 250km Text1. Text = Rs.135 Else If option2. Value = True and Option6. Value then Text1. Text = 325km Text1. Text = Rs.432 Else If option3. Value = True and Option4. Value then Text1. Text = 165km Text1. Text = Rs.85 Else If option3. Value = True and Option5. Value then Text1. Text = 325km Text1. Text = Rs.432 End if End if End if End if End if End if End sub

Private sub option1_click ()

If option1. Enabled = True then Option4. Enabled = False Option5. Enabled = True Option6. Enabled = True End if End sub Private sub option2_click () If option2. Enabled = True then Option4. Enabled = True Option5. Enabled = False Option6. Enabled = True End if End Private sub option3_click () If option3. Enabled = True then Option4. Enabled = True Option5. Enabled = True Option6. Enabled = False End if End sub

18

MDI Form X Forms

Right click Menu Editor MENU EDITOR Caption Index Help Context ID Forms Name Menu forms O

19

Next Forms .Form1 .Form2 .Form3 .Form4 Caption Form1 Name optform1 Caption Form2 Name optform2 Private sub optform1_click () Form1. Show End sub

Insert

Delete

Private sub optform2_click () Form2. Show End sub Private sub optform3_ click () Form3. Show End sub Private Sub optform4_click () Form4. Show End sub

CALCULATOR Calculator Label

Text Box

20

1 4 7 0

2 5 8

3 6 9 +

.
/

End

cls

Dim i as integer Dim op as string Private sub command1_click () Text1. Text = Text1. Text + 1 End sub Private sub command2_click () Text1. Text = Text1. Text + 2 End sub Private sub command3_click () Text1. Text = Text1. Text + 3 End sub Private sub command4_click () Text1. Text = Text1. Text + 4 End sub Private sub command5_click () Text1. Text = Text1. Text + 5 End sub

Private sub command6_click () Text1. Text = Text1. Text + 6 End sub Private sub command7_click () Text1. Text = Text1. Text + 7 End sub Private sub command8_click () Text1. Text = Text1. Text + 8 End sub Private sub command9_click () Text1. Text = Text1. Text + 9 End sub Private sub command10_click () Text1. Text = Text1. Text + 0 End sub

21

Private sub command11_click () Text1. Text = Text1. Text + . End sub Private sub command12_click () Op = + i = Text1. Text Text1. Text = blank space

End sub Private sub command13_ click () Op = - i = Text1. Text Text1. Text = End sub Private sub command14_ click () Op = / i = Text1. Text Text1. Text = End sub Private sub command15_ click () Op = * i = Text1. Text Text1. Text = End sub Private sub command16_click () If op = + then Text1.Text = val (Text1.Text) + i End if If op = - then Text1.Text = val (Text1.Text) - i End if If op = / then Text1.Text = val (Text1.Text) / i

22

End if If op = * then Text1.Text = val (Text1.Text) * i End if Private sub command17_click () Text1.Text = End sub Private sub command18_ click () End End sub

23

End of List

Вам также может понравиться