Week 6 · Unit 1 Topic 2: a number converter project with VB.NET: window, controls, properties and code · 3 lessons
1
Planning a converter window: stages, controls and properties
ICT Secondary 3 Term 1, Unit 1, Topic 2: pp. 27–36
GoalName the three stages of the converter project and say what each control of its window and each property is for.
New words
control · a ready-made part of a window, such as a label, a text box or a buttonproperty · a setting of a control, such as the words it showsgroup box · a frame that holds some controls together, here the radio buttonsradio button · a round choice: ticking one unticks the others in the same frame
Explanation
A converter project has three stages: design the window, write the code, and run and check. In the first stage we choose controls, the ready-made parts of a window. Ours needs a label that tells the user what to do, a text box where the number is typed, two group boxes called From and To with three radio buttons each (decimal, hexadecimal, binary), and one button. Every control has properties, the settings that decide how it looks and what it says; the most used one is its text. The two frames matter. Radio buttons in one frame belong together, so ticking one unticks the others, and the program can ask, for each frame, which system the user picked. Planning all this on paper first makes the code short. We also name each control by its type and its job, such as TextNumber or ButtonConvert, so that the code reads almost like a sentence.
These are the controls of the window and the name each gets in the code. The first letters of a name tell the type, the rest tell the job.
Control
Property
Value
LabelHint
Text
Type a whole number
TextNumber
Text
(empty at the start)
GroupFrom
Text
From
GroupTo
Text
To
RadioFromDec
Text
Decimal
ButtonConvert
Text
Convert
Now the properties. Each row sets the text a control shows. For an Arabic window, one more property makes the window run from right to left; the code itself always stays left to right.
Layout
Ticks that can exist at the same time
six radio buttons in one frame
only one tick in total
two frames of three
one tick in From and one tick in To
Why two group boxes? If all six radio buttons stood in one frame, ticking a To button would untick the From button. Two frames give one tick in each.
Class activity
On paper, plan a window that turns a length in metres into centimetres, or centimetres into metres. List its controls with a name for each, say which one needs a group box, and write the Text property of every control.
Practice
1
Name the three stages of the project.
Design the window, write the code, run and check.
2
Why are the six radio buttons put in two group boxes?
Ticking a radio button unticks the others in its frame, so each frame gives one choice: one for From and one for To.
3
Which control holds the number that the user types?
The text box.
4
What is a property? Give one example.
A setting of a control, such as its Text, the words it shows.