☰ Year plan · Communication Technology

The converter in VB.NET: window, code and tests

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.

Worked examples
ControlName in the codeJob
labelLabelHinttells the user what to do
text boxTextNumbertakes the number that is typed
group boxGroupFromholds the three From choices
group boxGroupToholds the three To choices
3 + 3 radio buttonsRadioFromDec, RadioFromHex, RadioFromBin, RadioToDec, RadioToHex, RadioToBinpick the two systems
buttonButtonConvertstarts the conversion
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.
ControlPropertyValue
LabelHintTextType a whole number
TextNumberText(empty at the start)
GroupFromTextFrom
GroupToTextTo
RadioFromDecTextDecimal
ButtonConvertTextConvert
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.
LayoutTicks that can exist at the same time
six radio buttons in one frameonly one tick in total
two frames of threeone 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.
2
Why are the six radio buttons put in two group boxes?
3
Which control holds the number that the user types?
4
What is a property? Give one example.