VB6.0 – 04 - Advanced Objects
An introductory course.

Presented by Charley Jones, Manpower Professional,
Course WebPage: www.crjones.com/vb

Review:

So far we’ve covered:

Objects Nouns Car, Form, Button

Properties Adjectives Car.Color, Form.Left, Button.Caption

Methods Actions Car.Drive, Form.Move, Button.Hide

Events Trigger Form_Load(), Button_Clicked()

Application Holds data on our project. App.Title, App.Version

Forms Basic display unit in VB. Form.Caption

CommandButton Allows action on form. Button.Caption

TextBox Accepts / displays input. Text1.Text

Labels Label1.Caption
Listboxes List1.AddItem(), List1.Clear(), List1.ListCount,

List1.List(X), List1.Selected(X), List1.Style

ComboBoxes Combo1.Text

CheckBoxes Checkbox1.Value = 1/0

RadioButtons Option1.Value = True/False

Frames Frame1.Caption

Scrollbars Hscroll1.Value

Timers Timer1.Interval, Timer1_Tick()

Modal Forms myForm.Show vbModal

Modless Froms myForm.Show / myForm.Show vbModeless

The class challenges last time were:



This week, we’re continuing our look at the basic toolbar:

Line Object

Used to draw a line on a form

Line.BorderWidth Width of Line

Line.BorderStyle 1=Solid, 2=Dashed, 3=Dot, 4=DashDot…

Line.X1 Line.Y1 Left Top of Line.

Line.X2 Line.Y2 Bottom Right of Line.

Shape Object

Used to draw shapes on the form.

Shape1.BorderStyle 1=Solid, 2=Dashed, 3=Dot, 4=DashDot…

Shape1.Shape 0=Rectangle, 1=Square, 2=Oval, 3=Circle…

Picture Object

Used to display (and create) images on form.

Not as fast as Image object, a little more greedy and slow.

You can draw directly in a Picture Control.

Picture1.Line (0,0) – (500,1000) Draw line for 0,0 to 500,1000

Picture1.Cicle (1000,1000), 500 Draw circle with radius 500 at 1000,1000

Picture1.Cls Clear Screen

Picture1.Picture = LoadPicture("C:\Program Files\Microsoft Visual Studio\

Common\Graphics\Bitmaps\Assorted\Beany.bmp")

Image Object

Used to display images (bitmaps, icons) on form.

Faster than Picture object, not as many options.

Image1.Picture = LoadPicture("C:\Program Files\Microsoft Visual Studio\

Common\Graphics\Bitmaps\Assorted\Beany.bmp")

Image1.Left = Image1.Left = 100

Image1.Hide

Image1.Picture = Nothing

You can also directly draw on form:

Form1.Line (0,0) – (500,1000)

Form1.Cicle (1000,1000), 500

Form1.Cls


And now for something completely different:

A mini file browser using:

DriveListBox,

Drive1.Drive Current Drive

DirectoryListBox,

Dir1.Path Current Path on Drive


FileListBox.

File1.FileName Selected Filename

File1.Path Path to list

File1.Pattern Pattern to list *.*

*.DOC;*.XLS

Making it work, the Change event.

Double click on the drive List box.
Notice that you’re in the code at: Drive1_Change

The change event fires every time there’s a change in the object.

So, when the Drive Changes, let’s change the path of the Directory List Box:

Private Sub Drive1_Change()

Dir1.Path = Drive1.Drive

End Sub


And let’s cascade that change to the FileListBox.

Whenever the directory is changed (by Drive1 or by clicking)

the Dir1_Change event fires.

Private Sub Dir1_Change()

File1.Path = Dir1.Path

End Sub

Exercises:

Now that we’ve got some new controls under our belt,

Let’s try them out in few projects:

VB6-4-1: Picture Viewer:

Write a project to view pictures on the hard drive.

Should only display JPG’s and GIF’s…

VB6-4-2: Analog Clock.
A little bit harder,

(A lot more code)

But with our new graphics abilities,

Try to write a digital clock…

VB6-04 - 1 -