Page 49 - Computing Book 8
P. 49
Developing Applications – Visual Studio Class 8
Common
language
Variable Type Value range
runtime type
structure
lnteger lnt32 -2,147,483,648 through 2,147,483,647 (signed)
Long -9,223,372,036,854,775,808 through 9,223,372,036,854,775,807
lnt64
(Long lnteger) (9.2... E+18) (signed)
Object Object Any type can be stored in a variable of type Object
String
(variable- String (class) 0 to approximately 2 billion Unicode characters
length)
Declaring a Public Variable
Declaring a public variable is not different from declaring a private variable. The only difference is
that the public variable is accessible from anywhere in the whole program. Follow the steps below to
create a program for a simple counter by using a public variable.
1. Create a new form and save it with the name of Simple Counter.
2. Add 2 buttons first with the text of “Reset” and the other one
with the text of “Add” also edit their name to btnRst and btnAdd
from the design section of the properties panel.
3. Add a label and change the text to “Result”.
4. Double click on the Reset(btnRst) button to include the Reset
button to script, by doing this the script window will open, close
the script window and then double click on the Add(btnAdd) to
include it to the script.
5. Now that both elements codes are included in the script, we will create a public variable that
is accessible for both buttons/elements.
Declaration of Public
Variable
Reset button code which will
declare the pub variable to 0.
pub is the public variable
Label1.Text = pub will display
the text of pub variable in
Label1 element
Add button code will add 1 to
the current value of the pub
variable.
Label1.Text = pub will display
the text of pub variable in
Label1 element after adding 1
every time the button is
pressed
The City School /Academics/Computing Curriculum/Class 8/2020-2021 Page 48 of 75

