Page 129 - Open Soource Technologies 304.indd
P. 129

Unit 6: VB Control Structure



                Private Sub frmSales_Load(...) Handles MyBase. Load
                  lblDept(0) = Label1
                  lblDept(1) = Label2
                lblDept(2)        = Label3
                  lblDept(3) = Label4
                  lblDept(4) = Label5
                  txtDept(0) = TextBox1
                  txtDept(1) = TextBox2
                  txtDept(2) = TextBox3
                  txtDept(3) = TextBox4
                  txtDept(4) = TextBox5
                  ‘Set the labels’ Text property to the corresponding department
                  ‘Set the text boxes’ Text property to the empty string
                  For depNum As Integer = 1 To 5
                    lblDept(depNum - 1).Text = “Department “ & depNum & “:”
                  Next
                End Sub
                Private Sub btnCompute_Click(...) Handles btnCompute.Click
                  Dim totalSales As Double = 0
                  For depNum As Integer = 1 To 5
                    totalSales += CDbl(txtDept(depNum - 1).Text)
                 Next
                 txtTotal.Text = FormatCurrency(totalSales)
                End Sub


                [Run, enter amounts into the text boxes, and then click the button.]






























                                      LOVELY PROFESSIONAL UNIVERSITY                        123
   124   125   126   127   128   129   130   131   132   133   134