Working with the VB IDE - PowerPoint PPT Presentation

1 / 39
About This Presentation
Title:

Working with the VB IDE

Description:

Dragging all tagged objects without disturbing their relative locations. ... tagged objects. Changing the spacing (vertical, horizontal or both) of all tagged ... – PowerPoint PPT presentation

Number of Views:110
Avg rating:3.0/5.0
Slides: 40
Provided by: jayso
Category:
Tags: ide | tagged | working

less

Transcript and Presenter's Notes

Title: Working with the VB IDE


1
Working with the VB IDE
2
Running a Program
  • Clicking thestart tool begins the program
  • The break tool pauses a program in
    mid-execution
  • The end tool terminates a program

3
The Forms Editor
  • Like the Program Editor, the Forms Editor allows
    the user to modify the properties of forms, the
    sort of object that may be placed on a form and
    the location, properties and size of these
    objects.
  • Most of these commands are highly intuitive and
    do not need much in the way of instruction.
  • There are, however, a few additional commands in
    the Forms Editor that are less intuitive.

4
Grouping Objects
  • On the form several objects can be selected at
    the same time. Do this by clicking on the
    desired objects while holding the Shift Key down.
  • Here the last command
  • selected was
  • cmdcompute.

5
Resizing Objects
  • Once several objects have been selected they may
    be gang adjusted by using the format menu
  • One of the options permits resizing all selected
    objects to match the last one selected.

6
Other Commands
  • Dragging all tagged objects without disturbing
    their relative locations.
  • Changing justification of all text.
  • Changing Font and size of all text.
  • Changing the visibility of all tagged objects
  • Changing the spacing (vertical, horizontal or
    both) of all tagged objects.
  • Aligning all tagged objects.

7
To Learn More...
  • Use the search term Format Command in the help
    system to get more detailed data.
  • (note Format is such a common term that you
    must limit your search.)

8
The Program Editor
  • Visual Basic (VB) supports a text editor (not a
    word processor) that permits the writing and
    modification of program code.
  • The editor is one of two sub-windows that appears
    in the Workspace. The other is the Forms window.
  • Many of the commands used in the editor are like
    those used in word processors, but there are
    differences.

9
Entering the Editor
  • The editor is normally entered by double
    clicking on an Event Producing Object in the
    workspace.
  • The result is a code window which opens with the
    subroutine describing that event as the focus.

10
Line Completion Help (1)
  • When a line is being entered, the editor will
    make suggestions.
  • When changing the caption on the button
    cmdthingie the editor presents suggestions when
    you add the dot.

11
Line Completion Help (2)
  • I actually typed
  • cmdthingie.capstart?
  • (no capitals, only part of the word caption, no
    spaces at all and no closing quote. The ?
    represents the .)
  • The editor did the rest.

12
Line Completion Help (3)
  • When I typed a syntactically incorrect line, the
    line turned red, and a notice box was posted as
    soon as I struck the key or moved the cursor
    to a different line.

13
Line Completion Help (4)
  • When I completed the line by typing the ) the
    line turned black again and was correctly spaced.
  • Note I had typed no spaces.

14
Line Completion Help (5)
  • If I had typed
  • cmdthingee.
  • The editor would not have provided any help
    since I had no existing data object named
    cmdthingee.

15
Line Completion Help (6)
  • If I had completed the line anyhow and run the
    program, only then would the system be able to
    find this more complex syntactical error.

16
The Helpful Program Editor
  • The Program Editor will correctly capitalize the
    names of existing data objects and legally
    spelled system commands. If you misspell one of
    them things remain in lower case.
  • The Program Editor will suggest and complete the
    spelling of properties of data objects. It will
    insert appropriate spaces and complete the lines
    of correctly entered command lines.

17
The Long and the Short of It
  • Some lines of code that are too long to fit
    neatly on a printed line
  • These lines can be entered on multiple lines
  • Some are so short that they need only a few
    characters to print
  • One line can hold multiple statements

18
One statement on multiple lines
  • Dim strThing As String
  • strThing "This is text that " _
  • is too long to fit on one line.
  • The underscore _ character on the first line
    indicates continuation
  • the ampersand character concatenates

19
One statement on multiple lines
  • Dim sngVolume as Single, _
  • sngRadius as Single, sngHeight _
  • as Single
  • sngVolume 3.14159 sngRadius _
  • 2 sngHeight
  • (You can place the underscore wherever a space
    may go, except within a quotation.)

20
Multiple statements on one line
  • Dim intRed As Byte, intBlue As Byte
  • intRed 3 intBlue 4
  • Note the two commands on the second line
    separated by the colon character. This
    would work just as if the two commands were put
    on two separate lines. Use whatever makes the
    program read more easily.

21
Option Explicit
  • To force VB to require all variables be defined,
    first click on the option sub-option of the
    tools command.

22
Option Explicit
  • Then be sure to check the box require variable
    declaration on the revealed option menu.

23
Option Explicit
  • You can, equivalently, simply type option
    explicit at the top of the code

24
Some Common Controls
25
The Command Control
  • The command control is one of the most important
    tools in the toolbox
  • Double clicking on the command button icon will
    install a command button on the working form

26
Adding a Command Button
  • The command buttons are named, by default
    Command1, Command2, etc.
  • They may be moved or changed in size using the
    mouse

27
Properties of Command Buttons
  • Each command button has several properties.
    govern the buttons appearance and behavior
  • The most important are the (name) and the caption
  • (name) is how a programmer can refer to the
    button in VB code
  • caption is the text a user will see displayed
    inside the button

28
Highlighting a Property
  • When you highlight a property, its definition
    appears below the properties window

29
Names and Captions
  • Clicking on the (name) property lets us name it
    cmdstop, (note the name starts with cmd)
  • Changing the caption to Stop gives the user an
    idea as to the buttons function

30
Programming Convention
  • Good practice in Visual Basic suggests that we
    should name all objects in a program with names
    that indicate their function
  • These names are invariant during a programs
    execution and are seen only by programmers
  • Command buttons names should begin with the
    prefix cmd
  • Names should begin with the prefix for the given
    object type, and should contain only letters and
    numbers
  • Captions are used to convey information to the
    user
  • They can change as the program runs
  • They may contain any letters, numbers, spaces,
    etc.

31
Entering Event Code
  • Double clicking on the cmdstop button itself,
    causes the Code window to open
  • The VB commands the define the buttons function
    go here
  • The End command terminates the VB program

32
The Label Control
  • The label control is an object with 37 named
    Properties.
  • You can adjust its size and position with the
    mouse.
  • You can change its (name) its caption and
    visibility using the Properties window.

33
Label Control Properties
34
Using Labels
  • The label control is usable only for output
  • It cannot accept input from the user
  • Its size, shape, color, visibility and the form
    of the information presented can be controlled
  • By editing its properties
  • By writing VB code to change its properties
  • Labels can be sized and moved using the mouse.

35
A Program Using a Label
36
Using a Label
  • When program execution begins, the system starts
    as in A, when the cmdby button is pressed the
    system goes to B
  • Repeated pressing of the cmdby button bounces the
    system between the two states

37
Programming Convention
  • Labels should be given a (name) that begins with
    lbl.
  • The Caption property of a label may be anything
    that makes sense one or more words or symbols.
  • Caption is displayed for the user
  • (name) is only accessible to the programmer
  • The Visible property may be either True or False
  • If false, the label is not displayed

38
The Text Box Control
  • Labels are designed to be used for output
  • Command buttons can accept input from the user,
    but only of a limited nature
  • The text box control allows the user input data

39
Text Box Properties
  • The text property contains the string of text
    displayed by the text box
  • Unlike labels, by default this text can be edited
    by the user at runtime
  • The proper prefix for text box names is txt
Write a Comment
User Comments (0)
About PowerShow.com