visualbasic lecture4.pdf

Upload: aseret423

Post on 02-Jun-2018

229 views

Category:

Documents


0 download

TRANSCRIPT

  • 8/10/2019 visualbasic lecture4.pdf

    1/20

    Copyright 2011 Pearson Addison-Wesley

    Addison Wesley

    is an imprint of

    2011 Pearson Addison-Wesley. All rights reserved.

    Addison Wesley

    is an imprint of

    Chapter 3

    Variables and Calculations

  • 8/10/2019 visualbasic lecture4.pdf

    2/20

  • 8/10/2019 visualbasic lecture4.pdf

    3/20

    Copyright 2011 Pearson Addison-Wesley

    The TextBox Control

    % text box is a rectangular area on a "or# that

    accepts input "ro# a eyboard

    Tutorial 3&1 pro'ides an exa#ple in the use o"a text box

    Chapter 3& Slide 3

  • 8/10/2019 visualbasic lecture4.pdf

    4/20

    Copyright 2011 Pearson Addison-Wesley

    (sing the Text )roperty in Code

    The TextBox control$s Text property can be

    accessed in code the sa#e way you access

    other properties

    *or +xa#ple

    The contents o" the Text property can be assigned

    into a -abel control$s Text property

    lblInfo.Text = txtInput.Text

    The contents o" the Text property can be displayed

    in a #essage box Chapter 3& Slide

  • 8/10/2019 visualbasic lecture4.pdf

    5/20

  • 8/10/2019 visualbasic lecture4.pdf

    6/20

    Copyright 2011 Pearson Addison-Wesley

    String Concatenation

    %ssu#e the user has entered their na#e into

    the TextBox txt2a#e

    -abel lblGreeting can say, 4ello5 to any na#e"ound in the TextBox

    lblreeting.Text = !"ello ! # txt$ame.Text

    %ppends user na#e in txt2a#e.Text to 4ello 5and stores result in text property o" lblGreeting

    Chapter 3& Slide 6

  • 8/10/2019 visualbasic lecture4.pdf

    7/20

    Copyright 2011 Pearson Addison-Wesley

    String Concatenation

    Tutorial 3&7 pro'ides another exa#ple o" how

    to concatenate strings "ro# text boxes

    Chapter 3& Slide 8

    txtDayOfWee

    ktxtMonth

    txtDayOfMont

    htxtYear

    lblDateString

    btnExitbtnClearbtnShowDate

  • 8/10/2019 visualbasic lecture4.pdf

    8/20

    Copyright 2011 Pearson Addison-Wesley

    %ligning Controls in 9esign /ode

    !hen dragging a control to a "or#, it can be

    aligned with a control already on the "or#

    Blue guide lines appear "or 'ertical align#ent

    -a'ender guide lines "or hori:ontal align#ent

    Chapter 3& Slide ;

  • 8/10/2019 visualbasic lecture4.pdf

    9/20

    Copyright 2011 Pearson Addison-Wesley

    The *ocus /ethod

    *or a control to ha'e the "ocus #eans that it is

    ready to recei'e the user

  • 8/10/2019 visualbasic lecture4.pdf

    10/20

    Copyright 2011 Pearson Addison-Wesley

    The *ocus /ethod

    ?ou can tell which control has "ocus by its

    characteristics

    !hen a TextBox has "ocus, it will ha'e a blining

    cursor or its text will be highlighted

    !hen a button, radio button, or a chec box has

    "ocus, you$ll see a thin dotted line around the

    control

    Tutorial 3&3 shows an exa#ple o" the *ocus

    #ethodChapter 3& Slide1@

  • 8/10/2019 visualbasic lecture4.pdf

    11/20

    Copyright 2011 Pearson Addison-Wesley

    Controlling a *or#$s Tab =rder

    with the TabIndex )roperty Tab ey steps "ocus "ro# one control to the

    next

    This order is set by the TabIndex property The Tab ey causes the "ocus to Au#p to the

    control with the next highest TabIndex 'alue

    The TabIndex property is best changed withthe Tab =rder option "ro# the View #enu

    9isplays the "or# in tab order selection #ode

    Set a new tab order by clicing the controls in theChapter 3& Slide11

  • 8/10/2019 visualbasic lecture4.pdf

    12/20

    Copyright 2011 Pearson Addison-Wesley

    %ssigning eyboard %ccess eys to Buttons

    Say your "or# had a button with the text

    +xit on it

    ?ou can allow the user to acti'ate the buttonusing %lt&D instead o" a #ouse clic

    Eust change the button text property to

    +Fxit The character "ollowing the

  • 8/10/2019 visualbasic lecture4.pdf

    13/20

    Copyright 2011 Pearson Addison-Wesley

  • 8/10/2019 visualbasic lecture4.pdf

    14/20

    Copyright 2011 Pearson Addison-Wesley

    Setting the %ccept Button

    The accept button is a button that is i#plicitly

    acti'ated i" the user hits the +nter ey

    The %cceptButton )roperty designates whichbutton on the "or# will beha'e in this #anner

    The button cliced #ost "reuently on a "or#

    is usually assigned as the accept button

    Chapter 3& Slide1

  • 8/10/2019 visualbasic lecture4.pdf

    15/20

    Copyright 2011 Pearson Addison-Wesley

    Setting the Cancel Button

    The cancel button is a button that is i#plicitly

    acti'ated i" the user hits the +scape ey

    The CancelButton )roperty designates whichbutton on the "or# will beha'e in this #anner

    %ny exit or cancel button on a "or# is a

    candidate to beco#e the cancel button Tutorial 3& pro'ides exa#ples o" setting

    access eys, accept, and cancel buttons

    Chapter 3& Slide1

  • 8/10/2019 visualbasic lecture4.pdf

    16/20

    Copyright 2011 Pearson Addison-Wesley

    Addison Wesley

    is an imprint of

    2011 Pearson Addison-Wesley. All rights reserved.

    Addison Wesley

    is an imprint of

    Section 3.7

    Variables and 9ata Types

    Variables hold data that #ay be

    #anipulated, used to #anipulate other data, or re#e#bered "or later use.

  • 8/10/2019 visualbasic lecture4.pdf

    17/20

    Copyright 2011 Pearson Addison-Wesley

    !hy 4a'e VariablesJ

    % 'ariable is a storage location in the

    co#puter$s #e#ory, used "or holding

    in"or#ation while the progra# is running

    The in"or#ation that is stored in a 'ariable

    #ay change, hence the na#e 'ariable5

    Chapter 3& Slide18

  • 8/10/2019 visualbasic lecture4.pdf

    18/20

    Copyright 2011 Pearson Addison-Wesley

    !hat Can ?ou 9o !ith VariablesJ

    Copy and store 'alues entered by the user, so

    they #ay be #anipulated

    )er"or# arith#etic on 'alues Test 'alues to deter#ine that they #eet so#e

    criterion

    Te#porarily hold and #anipulate the 'alue o"a control property

    Ke#e#ber in"or#ation "or later use in the

    progra# Chapter 3& Slide1;

  • 8/10/2019 visualbasic lecture4.pdf

    19/20

    Copyright 2011 Pearson Addison-Wesley

    4ow to Thin %bout Variables

    ?ou the progra##er #ae up a na#e "or the

    'ariable

    Visual Basic associates that na#e with alocation in the co#puter

  • 8/10/2019 visualbasic lecture4.pdf

    20/20

    Copyright 2011 Pearson Addison-Wesley

    9eclaring Variables

    % 'ariable declaration is a state#ent that creates a 'ariable in

    #e#ory

    The syntax is

    im ariable$ame *s ataType

    imshort "or 9i#ensionH is a eyword

    ariable$ameis the progra##er designated na#e

    *sis a eyword

    ataTypeis one o" #any possible eywords "or the type

    o" 'alue the 'ariable will contain

    Chapter 3& Slide7@