Chapter 7 - Use a single graphics box for the resistor display
- StPendl Oct 29, 2011
Since we have now got rid of a bunch of controls, we further reduce the number of controls by removing the individual graphics boxes, which make up the display of the resistor.
For this we introduce some global variables to keep track of the current color selection:
' define variables to be remembered between calling the subGLOBAL Band1value, Band2value, Band3value, Band4value
GLOBAL ColorValue1$, ColorValue2$, ColorValue3$, ColorValue4$
' set initial band color to body color
ColorValue1$ ="21 228 255"
ColorValue2$ = ColorValue1$
ColorValue3$ = ColorValue1$
ColorValue4$ = ColorValue1$
Further we replace the seven resistor display graphics boxes:
'Selected Bands of Body Resistancegraphicbox#w.Band1,155,470,15,35graphicbox#w.Band2,185,470,15,35graphicbox#w.Band3,215,470,15,35graphicbox#w.Band4,255,470,15,35stylebits#w.Band1,0,_WS_BORDER,0,0stylebits#w.Band2,0,_WS_BORDER,0,0stylebits#w.Band3,0,_WS_BORDER,0,0stylebits#w.Band4,0,_WS_BORDER,0,0'General Body Resistancegraphicbox#w.37,130,470,168,35stylebits#w.37,0,_WS_BORDER,0,0'Terminal Wiresgraphicbox#w.42,80,485,50,5graphicbox#w.43,300,485,50,5
With a single resistor display graphics box:
'General Body Resistancegraphicbox#w.resistor,80,470,270,35stylebits#w.resistor,0,_WS_BORDER,0,0
We also have to introduce the code to draw the resistor based on the users selection in the mouse event handler subroutine:
Streamlining your code
Chapter 7 - Use a single graphics box for the resistor display
-Since we have now got rid of a bunch of controls, we further reduce the number of controls by removing the individual graphics boxes, which make up the display of the resistor.
For this we introduce some global variables to keep track of the current color selection:
Further we replace the seven resistor display graphics boxes:
With a single resistor display graphics box:
We also have to introduce the code to draw the resistor based on the users selection in the mouse event handler subroutine:
The complete code now looks like this.
Chapter 1 - Starting the mission
Chapter 2 - Using arrays to reduce redundant code
Chapter 3 - Use variables for duplicate command strings
Chapter 4 - Consolidate event handlers
Chapter 5 - Apply mouse selection
Chapter 6 - Remove radio buttons
Chapter 7 - Use a single graphics box for the resistor display
Chapter 8 - Further reduce the amount of GUI controls (Using hot-spots)
Chapter 9 - Adding some eye-candy
Chapter 10 - Summary