Itp 150
Download
1 / 21

ITP 150 - PowerPoint PPT Presentation


  • 104 Views
  • Uploaded on

ITP 150. Week 4 Variables. Review:. BackStyle FillColor BorderStyle FillStyle Caption Name Enabled Visible. Controls Propeties Events Methods Procedures Functions. Move Clear SetFocus AddItem. Activate DragOver Load Change GotFocus LostFocus Click KeyDown MouseDown

loader
I am the owner, or an agent authorized to act on behalf of the owner, of the copyrighted work described.
capcha
Download Presentation

PowerPoint Slideshow about 'ITP 150' - malloren


An Image/Link below is provided (as is) to download presentation

Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author.While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server.


- - - - - - - - - - - - - - - - - - - - - - - - - - E N D - - - - - - - - - - - - - - - - - - - - - - - - - -
Presentation Transcript
Itp 150

ITP 150

Week 4

Variables


Review
Review:

BackStyle FillColor

BorderStyle FillStyle

Caption Name

Enabled Visible

  • Controls

  • Propeties

  • Events

  • Methods

  • Procedures

  • Functions

Move Clear

SetFocus AddItem

Activate DragOver Load

Change GotFocus LostFocus

Click KeyDown MouseDown

DblClick KeyPress MouseMove

DragDrop KeyUp MouseUp

ITP 150 - Lecturer: A. Borquez


Controls for displaying and entering text
Controls for Displaying andEntering Text

To provide this featureUse this control

Text that can be edited by the user, for example Text box

an order entry field or a password box

Text that is displayed only, for example to identify Label

a field on a form or display instructions to the user

ITP 150 - Lecturer: A. Borquez


Controls that present choices to users
Controls That Present Choices to Users

To provide this featureUse this control

A small set of choices from which a user can choose one or Option buttons

more options. Check boxes A small set of options from which (use frames if

a user can choose just one. additional groups are needed)

A scrollable list of choices from which the user can choose. List box

A scrollable list of choices along with a text edit field. Combo box

The user can either choose from the list or type a choice

in the edit field.


Controls that display pictures and graphics
Controls That Display Pictures and Graphics

To provide this feature Use this control

A container for other controls. Picture box

Printing or graphics methods. Picture box

Displaying a picture. Image control or picture box

Displaying a simple graphical element Shape or line control


Managing forms
Managing Forms

ITP 150 - Lecturer: A. Borquez


Variables
Variables

  • In Visual Basic, you use variables to temporarily store values during the execution of an application

  • Variables have a name (the word you use to refer to the value the variable contains) and a data type (which determines the kind of data the variable can store)

  • To declare a variable is to tell the program about it in advance. You declare a variable with the Dim statement, supplying a name for the variable: Dimvariablename [Astype]

ITP 150 - Lecturer: A. Borquez


Variable rules
Variable rules…...

  • Must begin with a letter.

  • Can't contain an embedded period or embedded type-declaration character.

  • Must not exceed 255 characters.

  • Must be unique within the same scope, which is the range from which the variable can be referenced — a procedure, a form, and so on.

ITP 150 - Lecturer: A. Borquez


Visual Basic Variables

  • Variables: temporarily store values during the

  • execution of an application. Variables have a:

  • name (the word you use to refer to the value the

  • variable contains) and a

  • data type (which determines the kind of data the variable

  • can store).

  • Variables can be used in many ways, including:

    • ®As a counter that stores the number of times a procedure or code

    • block executes.

    • ®As a temporary storage for property values.

    • ®As a place to hold a value returned from a function.

    • ®As a place to store directory or file names.

ITP 150 - Lecturer: A. Borquez


Other variable issues to think about
Other Variable issues to think about….

  • Implicit vs. Explicit Declarations

  • Declaring a variable in the Declarations section of a form, standard, or class module, rather than within a procedure, makes the variable available to all the procedures in the module.

  • Declaring a variable using the Public keyword makes it available throughout your application.

  • Declaring a local variable using the Static keyword preserves its value even when a procedure ends.

ITP 150 - Lecturer: A. Borquez


Variable data types
Variable Data Types

Data typeStorage size

Byte1 byte

Boolean2 bytes

Integer2 bytes

Long (long integer)4 bytes

Single (single floating-point)4 bytes

Double(double floating-point) 8 bytes

Currency (scaled integer)8 bytes

Date8 bytes

Object4 bytes + size of object

String (variable-length)10 bytes + string length

String (fixed-length)length of string

Variant16 bytes

ITP 150 - Lecturer: A. Borquez


Variable data types naming conventions
Variable Data Types Naming Conventions

Data typePrefix

Byte byt

Boolean bln

Integer int

Long lng

Single sng

Double dbl

Currency cur

Date dtm

Object obj

String str

Variant var

ITP 150 - Lecturer: A. Borquez


Understanding the scope of variables
Understanding the Scope of Variables

ScopePrivatePublic

Procedure-level Variables are private to Not applicable. You

the procedure in which cannot declare public

they appear. variables within a

procedure.

Module-level Variables are private to Variables are available

the module in which to all modules.

they appear.


Introduction to procedures
Introduction to Procedures

There are two major benefits of programming with procedures:

  • Procedures allow you to break your programs into discrete logical units, each of which you can debug more easily than an entire program without procedures.

  • Procedures used in one program can act as building blocks for other programs, usually with little or no modification.

ITP 150 - Lecturer: A. Borquez


Working with Date and Time

  • Dim dtNewDate As Date

  • dtNewDate = dtDate + 5

  • Now, Date, and Time functions

  • MsgBox "The current date and time is " & Now()

  • MsgBox "The date is " & Date()

  • MsgBox "The time is " & Time()

ITP 150 - Lecturer: A. Borquez


VB Date/Time Functions

FunctionExampleValue displayed

Year()Year(Now)1999

Month()Month(Now)2

Day()Day(Now)22

Weekday()Weekday(Now)7

Hour()Hour(Now)11

Minute()Minute(Now)38

Second()Second(Now)9

ITP 150 - Lecturer: A. Borquez


The DateDiff Function

The DateDiff function returns the number of time intervals

between two dates.

  • DateDiff(interval, date1, date2[, firstdayofweek[, firstweekofyear]])

  • Dim dtTheDate As Date

  • Dim strMsg As String

  • dtTheDate = InputBox("Enter a date")

  • strMsg = "Days from today: " & DateDiff("d", Now, dtTheDate)

  • MsgBox strMsg


VB Format Function

the Format function accepts a numeric value and converts it to a string

Format syntaxResult

Format(Now, “m/d/yy”)1/27/99

Format(Now, “dddd, mmmm dd, yyyy”)Wednesday, January 27, 1999

Format(Now, “d-mmm”)27-Jan

Format(Now, “mmmm-yy”)January-99

Format(Now, “hh:mm AM/PM”)07:18 AM

Format(Now, “h:mm:ss a/p”)7:18:00 a

Format(Now, “d-mmmm h:mm”)3-January 7:18

Using Named Formats

  • txtDate.Text = Format(Now, "Long Date")

  • txtCost.Text = Format(1000, "Currency")


Sub procedures vs function procedures
Sub Procedures vs. Function Procedures

  • Sub procedures do not return a value.

  • Function procedures return a value.

ITP 150 - Lecturer: A. Borquez


A closer look at sub procedures
A Closer Look at Sub_Procedures...

  • A Sub procedure is a block of code that is executed in response to an event.

  • By breaking the code in a module into Sub procedures, it becomes much easier to find or modify the code in your application.

[Private|Public][Static]Subprocedurename (arguments)statements

  • Each time the procedure is called, the statements between Sub and

  • End Sub are executed.

  • Sub procedures can be placed in standard modules, class modules, and form modules.

  • Sub procedures are by default Public in all modules

ITP 150 - Lecturer: A. Borquez


A closer look at functions
A Closer Look at Functions….

  • Visual Basic includes built-in, or intrinsic functions, like Sqr, Val, or Chr.

  • You can use the Function statement to write your own Function procedures.

[Private|Public][Static]Functionprocedurename (arguments) [Astype]statements

  • Like a Sub procedure, a Function procedure is a separate procedure that can take arguments, perform a series of statements, and change the value of its arguments.

  • Function procedures have data types, just as variables do.

  • You return a value by assigning it to the procedurename itself.


ad