Variables and Constants - PowerPoint PPT Presentation

1 / 9
About This Presentation
Title:

Variables and Constants

Description:

Public creates variables that can be modified by all parts of the program ... an executable for your tutorials and application and submit in your flash drive ... – PowerPoint PPT presentation

Number of Views:244
Avg rating:3.0/5.0
Slides: 10
Provided by: mobi5
Category:

less

Transcript and Presenter's Notes

Title: Variables and Constants


1
Variables and Constants
  • Business 92
  • Fall 2007
  • Roldan

2
Variables
  • Stores data temporarily in the computers memory
  • Key to working with user input
  • Allows a program to proceed based on user inputs
    and actions
  • First step Declare the Variable

3
Declaring Variables
  • You declare variables to
  • Tell the computer which parts of your program
    have permission to store and retrieve the data in
    the variable
  • Tell the computer the name of the variable
  • Tell the computer what type of information that
    variable is allowed to hold
  • Basic syntax
  • ScopeType VariableName as DataType
  • Scopetype can either be Dim or Public
  • Dim allows the variable to be modified by only
    one part of the program
  • Public creates variables that can be modified
    by all parts of the program
  • VariableName keep it simple letters numbers
    only, no spaces or punctuation marks
  • DataType tables of datatypes can be found in
    pages 234, 235, 236, 237, and 238

4
Declaring Constants
  • Constants always contain a fixed value
  • Basic syntax is
  • Const constantname as datatype constantvalue
  • Enables you to have only one place where the
    value of the constant is to be updated and the
    change ripples through your program
  • Constants also allow you to have descriptive
    names for fixed values you use in your program

5
Code Anatomy
6
Variable only for the Form
Dim Statement for Dogage in Code behind Form
7
Variable for your entire Program
  • Declare a public variable in a module
  • Select ProjectAdd Module then click ok to add
    Module1.vb to your program
  • Code AnatomyPublic DogAge as Integer

8
Using a Public Variable
  • A Public Variable is can be edited and used by
    any part of your program
  • Add a second form and link code to a button on
    this second form to display the value for DogAge
  • Add a button to Form1 to show Form2

9
In Class Work
  • Complete the tutorial on page 244 if you have not
    yet done so.
  • Add a second form to your tutorial program to use
    the data collected in form1 (see Slide 8)
  • Add at least two variables and one constant to
    your application to capture user input
  • one variable should be local to a form and the
    other should be a public variable
  • Build an executable for your tutorials and
    application and submit in your flash drive
  • Talk to me about your application if you are
    having trouble figuring out how to fit these
    elements to it
Write a Comment
User Comments (0)
About PowerShow.com