Page 48 - Computing Book 8
P. 48

Developing Applications – Visual Studio                                              Class 8


                       button to “Add” from the text option in the properties panel
                   4.  Add 1 label from the toolbox in the form and change the text of the label to “Result” from
                       the text option in the properties panel
                   5.  Double click on the Add button and enter this code as shown in the example below


               Enter this code




              Name of Variable                                                           Name of text box



                  Label                                                                  Calculation of variables



                                       nd
                             st
                     •  The 1  and the 2  line of code are where we have declared the variables with its data type
                        which is an integer in this case.
                                      th
                               rd
                     •  In the 3  and 4  lines, we have declared the value of a variable. In this case, we are taking
                        the user input from the textbox.
                               th
                     •  In the 5  line, our code adds the two variables and puts the sum as text into Label1.

                   6.  Click on the debug button   or F5 to execute the program in debugging mode.
                     The “=” here is an assignment operator, a symbol used to assign the value on the right of the
                     sign to the variable on the left. So here, the content of TextBox1 is stored in variable number1.
                     Note here that although whatever you write in a text box is considered as String, Visual Basic
                     automatically converts it to a number since the variable number1 is declared as Integer.

               Common Data Types:
                                   Common
                                   language
                 Variable Type                                          Value range
                                 runtime type
                                   structure
                Boolean         Boolean          True or False
                Byte            Byte             0 through 255 (unsigned)
                Char
                (single         Char             0 through 65535 (unsigned)
                character)
                                                 0:00:00 (midnight) on January 1, 0001 through 11:59:59 PM on
                Date            DateTime
                                                 December 31, 9999
                                                 0 through +/-79,228,162,514,264,337,593,543,950,335 (+/-
                                                 7.9...E+28) with no decimal point; 0 through +/-
                                                 7.9228162514264337593543950335 with 28 places to the right
                Decimal         Decimal
                                                 of the decimal;
                                                 smallest nonzero number is +/-
                                                 0.0000000000000000000000000001 (+/-1E-28)





               The City School /Academics/Computing Curriculum/Class 8/2020-2021                Page 47 of 75
   43   44   45   46   47   48   49   50   51   52   53