Presentation is loading. Please wait.

Presentation is loading. Please wait.

Working with the VB IDE. Running a Program u Clicking the”start” tool begins the program u The “break” tool pauses a program in mid-execution u The “end”

Similar presentations


Presentation on theme: "Working with the VB IDE. Running a Program u Clicking the”start” tool begins the program u The “break” tool pauses a program in mid-execution u The “end”"— Presentation transcript:

1 Working with the VB IDE

2 Running a Program u Clicking the”start” tool begins the program u The “break” tool pauses a program in mid-execution u The “end” tool terminates a program

3 The Forms Editor u 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. u Most of these commands are highly intuitive and do not need much in the way of instruction. u There are, however, a few additional commands in the Forms Editor that are less intuitive.

4 Grouping Objects u 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 u Once several objects have been selected they may be “gang” adjusted by using the “format” menu u One of the options permits resizing all selected objects to match the last one selected.

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

7 To Learn More... u 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 u Visual Basic (VB) supports a text editor (not a word processor) that permits the writing and modification of program code. u The editor is one of two sub-windows that appears in the Workspace. The other is the Forms window. u Many of the commands used in the editor are like those used in word processors, but there are differences.

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

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

11 Line Completion Help (2) u I actually typed: cmdthingie.cap=”start   (no capitals, only part of the word caption, no spaces at all and no closing quote. The  represents the.) u The editor did the rest.

12 Line Completion Help (3) u 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) u When I completed the line by typing the “)” the line turned black again and was correctly spaced. u Note I had typed no spaces.

14 Line Completion Help (5) u 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) u 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 u 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. u 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 u Some lines of code that are too long to fit neatly on a printed line  These lines can be entered on multiple lines u 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.“ u The underscore “_” character on the first line indicates continuation u 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 u You can, equivalently, simply type option explicit at the top of the code

24 Some Common Controls

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

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

27 Properties of Command Buttons u Each command button has several properties. govern the button’s appearance and behavior u 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 u 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”) u Changing the caption to “Stop” gives the user an idea as to the button’s function

30 Programming Convention u 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 program’s 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 u 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 button’s function go here  The “End” command terminates the VB program

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

33 Label Control Properties

34 Using Labels u The label control is usable only for output  It cannot accept input from the user u 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 u 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 ”. u 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 u The Visible property may be either True or False  If false, the label is not displayed

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

39 Text Box Properties u The text property contains the string of text displayed by the text box u Unlike labels, by default this text can be edited by the user at runtime u The proper prefix for text box names is txt


Download ppt "Working with the VB IDE. Running a Program u Clicking the”start” tool begins the program u The “break” tool pauses a program in mid-execution u The “end”"

Similar presentations


Ads by Google