home *** CD-ROM | disk | FTP | other *** search
/ An Introduction to Progr…l Basic 6.0 (4th Edition) / An Introduction to Programming using Visual Basic 6.0.iso / PROGRAMS / CH7 / 7-2-4.FRM (.txt) < prev    next >
Encoding:
Visual Basic Form  |  1998-11-02  |  1.9 KB  |  72 lines

  1. VERSION 5.00
  2. Begin VB.Form frm7_2_4 
  3.    Caption         =   "Average"
  4.    ClientHeight    =   1230
  5.    ClientLeft      =   3180
  6.    ClientTop       =   2475
  7.    ClientWidth     =   2640
  8.    BeginProperty Font 
  9.       Name            =   "MS Sans Serif"
  10.       Size            =   8.25
  11.       Charset         =   0
  12.       Weight          =   700
  13.       Underline       =   0   'False
  14.       Italic          =   0   'False
  15.       Strikethrough   =   0   'False
  16.    EndProperty
  17.    LinkTopic       =   "Form1"
  18.    PaletteMode     =   1  'UseZOrder
  19.    ScaleHeight     =   1230
  20.    ScaleWidth      =   2640
  21.    Begin VB.PictureBox picAverage 
  22.       Height          =   255
  23.       Left            =   120
  24.       ScaleHeight     =   195
  25.       ScaleWidth      =   2355
  26.       TabIndex        =   1
  27.       Top             =   840
  28.       Width           =   2415
  29.    End
  30.    Begin VB.CommandButton cmdDisplay 
  31.       Caption         =   "Display Average"
  32.       Height          =   495
  33.       Left            =   120
  34.       TabIndex        =   0
  35.       Top             =   120
  36.       Width           =   2415
  37.    End
  38. Attribute VB_Name = "frm7_2_4"
  39. Attribute VB_GlobalNameSpace = False
  40. Attribute VB_Creatable = False
  41. Attribute VB_PredeclaredId = True
  42. Attribute VB_Exposed = False
  43. Private Sub cmdDisplay_Click()
  44.   'Pass array to a Sub procedure and a Function procedure
  45.   Dim score(1 To 10) As Integer
  46.   Call FillArray(score())
  47.   picAverage.Cls
  48.   picAverage.Print "The average score is"; Sum(score()) / 10
  49. End Sub
  50. Private Sub FillArray(s() As Integer)
  51.   'Fill array with scores
  52.   s(1) = 85
  53.   s(2) = 92
  54.   s(3) = 75
  55.   s(4) = 68
  56.   s(5) = 84
  57.   s(6) = 86
  58.   s(7) = 94
  59.   s(8) = 74
  60.   s(9) = 79
  61.   s(10) = 88
  62. End Sub
  63. Private Function Sum(s() As Integer) As Integer
  64.   Dim total As Integer, index As Integer
  65.   'Add up scores
  66.   total = 0
  67.   For index = 1 To 10
  68.     total = total + s(index)
  69.   Next index
  70.   Sum = total
  71. End Function
  72.