• No results found

Visual Basic 6.0

N/A
N/A
Protected

Academic year: 2022

Share "Visual Basic 6.0"

Copied!
40
0
0

Loading.... (view fulltext now)

Full text

(1)

Notes of

Visual Basic 6.0

By

S. K. Sharma

(2)

Option Button:

• It is Used only as a group of buttons. When the user selects one of them the others are deselected automatically.

• All other properties of this control are similar to those in form and command button where they are fully discussed which are caption, font, enabled, backcolor and visible beside an important property which is value that takes true or false and it used with if statement.

• The option button usually takes click event.

(3)

Example: Design a form with three option buttons "

red ", " green " and " blue " such that when we click

on options the color of the form colored by red,

green and blue respectively.

(4)

Private Sub Option1_Click() Form1.BackColor = vbGreen End Sub

Private Sub Option2_Click() Form1.BackColor = vbBlue End Sub

Private Sub Option3_Click() Form1.BackColor = vbRed End Sub

(5)

Check box:

• Any number of check boxes can be used on a form.

• They work independently.

• Its Property value could be changed in design

stage manually, or in running stage by code.

(6)

Example: Design a form with one text box and three check boxes such that when click on boxes the following is done: change typing to bold, italic,

underline.

(7)

Private Sub Check1_Click()

Text1.FontBold = Check1.Value End Sub

Private Sub Check2_Click()

Text1.FontItalic = Check2.Value End Sub

Private Sub Check3_Click()

Text1.FontUnderline = Check3.Value End Sub

(8)

Run stage:

(9)

Exercise: Design a form shown below:

On clicking the Buy Items button, message box will show the total amount to be paid for purchasing the above items.

(10)

Timer

Timer returns the time in millisecond. It may be used to measure execution time of code (program efficiency).

Property name Objective and code

interval To repeat the code according to event. It takes an

integer values (0-65535) and measured in millisecond

enabled Enabled =true or false

(11)

Ex: design electronic clock to display the time in seconds.

Private Sub Timer1_Timer() Label1.Caption = Time

End Sub

(12)

Example: Design a form to display “Computer Science" such that when click on command button

"start" the color of " Computer Science " changed randomly every second.

Timer1

interval 1000

enabled false

Label1

Caption Computer Science

Command1

caption Click Me

(13)

Private Sub Command1_Click() Timer1.Enabled = True

End Sub

Private Sub Timer1_Timer() t = Rnd * 15

Label1.ForeColor = QBColor(CInt(t)) End Sub

Run stage:

When click on command button “CLICK ME” the color of the font will be changed every second randomly in integer no. (0-15).

Note: the function (Cint) used to convert to integer no.

And (Rnd) used to generate a random no. in a range (0-1)

(14)

Exercise: Design a form as below to show the

current time and date

(15)

Input - Output boxes

There are two types of dialog boxes which are:

 input box and

 message box.

The first is used to input variable and the second to output variable or message. Both needs code and appear at run time.

(16)

a) Inputbox

• Inputbox used to input value or characters for one variable from keyboard at running stage.

• This box needs a code in code sheet and could be written in any event or command

X=inputbox(" prompt or remark", "title")

(17)

Example: Enter value of x using inputbox

Private Sub Form_Load()

X=Inputbox("enter value of x", "calculation") End Sub

(18)

Message box

It is used to output a message to the user (at running stage) the code needed could be written in code sheet and in any event or command.

The available icons for message box:

Structure value Icon

vbcritical 16

vbquestion 32

vbexclamation 48

vbinformation 64

(19)

The available commands for message box:

Structure value Command

Vbokonly 0 Ok

Vbokcancel 1 Ok, Cancel

vbAbortRetryIgnor 2 Abort, Retry, Ignore

vbYesNoCancel 3 Yes, No, Cancel

vbYesNo 4 Yes, No

vbRetryCancel 5 Retry, Cancel

(20)

For example if we write the following statement then a message box will be appear as shown below

MsgBox "please close your program", 16, "Error"

or

MsgBox "please close your program", vbcritical, "Error"

(21)

Example: show what appear after running the following statement

MsgBox "are you sure you want to delete this file", 32 + 4,

"delete"

or

MsgBox "are you sure you want to delete this file",vbQuestion+vbYesNo,"delete"

(22)

Example: write a program to move the text (excellent) from textbox to message box and change the color of the text after click on command button (display).

Text1: text="excellent"

Command1: caption=" Click”

Private Sub Command1_Click() MsgBox (Text1.Text)

Text1.BackColor = QBColor(9) Text1.Text = " "

End Sub

(23)

Or

we can write the following code:

Private Sub Command1_Click() X= Text1.Text

MsgBox (X)

Text1.BackColor = QBColor(9) Text1.Text = " "

End Sub

(24)

Exercises

 Design a form contains specific title such that when we click on command1 the color of the font will change and we click on command2 the size of the font will be change.

 Design a form contains shape and command buttons

"what is this" such that when click on the command button the name of this shape appears in message box.

 Enter a text in label1 such that this text copied to label2 after click on command button "copy" and delete from label2 after click on command button "delete".

(25)

Design a form contain command button such that when we click on command, form2 will be appear and form1 will be disappear.

Design a form "at run stage" the title of form1 will be change to "visual basic" and the back color of form1 will change too.

Design a form with two shapes, red and blue ,write code to replace the color every between two shapes.

Design a form contain list box and two command buttons:

1- add: to add the element to the list from input box 2- delete: to delete the list elements

(26)

More Exercises

1. Design a form in VB as shown below and

calculate the total and average.

(27)

2. Design a form as shown below and generate the

result on clicking the generate result button.

(28)

3. Design a form as shown below which transfers list

box item to combo box on clicking the transfer to

combo button.

(29)

4. Design a form as shown below and which shows

the temperature conversion on clicking the

respective buttons.

(30)

5. Design a Application form which takes the following information as shown on the form below:

When you click on submit button, a message box will show on the screen which contain “Name”, “Sex”,

“Qualification”, “Post applied for” and “hobbies”.(e.g.

“Hello Mr. ABC, (male/female), Your Qualification is BA, Your hobby is Reading, You have applied for the post of Teacher” )

(31)

6. Design a form in which there are various options as listed below. When you select any option, the

corresponding image should be display in the image box and also show the details related to the image on clicking the Show Details button.

(32)

7. Design a form shown below which represents the movement of items from one list box to another, add new item to the current list box and also perform delete operation on the lists.

(33)

8. Design a form shown below in which there are various planets and satellites’ name in the list box.

When we select any item, its corresponding item will appear in the image and also its related information on clicking on About button.

(34)

9. Design a form as shown below which represent an objective quiz as below.

(35)
(36)

10. Design a form as below:

The above form displays the different options for shapes as above. When you select any option, the corresponding shape will display on the form. Also change the width of the border of the shapes by using vertical scroll bar.

(37)

11. Design a form as below

In the above form, when we click on font button, the frame font options will display which contains different font formatting options. When you apply these option on the text enter in the box, its result will appear in the Preview Option

(38)
(39)
(40)

References

Related documents

1 Short-Beam Strength of Polymer Matrix Composites ASTM D 2344M 2 Tensile Properties of Polymer Matrix Composites ASTM D 3039M 3 Flexural Properties of Unreinforced

Figure: Typical creep curve of strain versus time at constant load and constant elevated temperature. The minimum creep rate Δe/ Δt is the slope of the linear segment in the

 Aquatic ecology is the study of water based ecosystems..  They are an area of water, in

MANNITOL, a straight- chain alchohol, a white water- soluble crystelline powder, is another product which can be extracted from brown algae. This can be utilised as a sub- stitute

Short note, Viva voce 4 Identify lepra reactions based on clinical features S SH Y Bedside clinic OSCE 5 Describe the complications of lepra reactions K KH Y

4.2.4 Electric energy consumption: Test results versus type-approval values The weighted electric energy consumption (EC AC,weighted ) stated in the CoC is the utility-

❖ Small-scale integration (SSI) describes ICs that have up to ten equivalent gate circuits on a single chip, and they include basic gates and flip-flops.. ❖ Medium-scale

In this scenario, the consumer meets their demand from the PV system (PV2C), battery (B2C), and the grid (G2C). S d 3, PV-BESS-Grid: This scenario includes the PV system, battery,