5 Band Resistor Calculator
Posted: Sun Feb 04, 2018 12:20 am
Hi All,
I need to have a quick to check the values of resistors, so I came up with this little program. A friend saw it an grabbed a copy and said I should share it cause it was quick and easy to use. So here it is as code.
Hope you enjoy and if you find any errors in the calculations let me know.
It was done HW 6.1 but I think it should run on earlier versions, as there is nothing special about the code.
Cheers Leo
HWS
XML = "RC.xml"
I need to have a quick to check the values of resistors, so I came up with this little program. A friend saw it an grabbed a copy and said I should share it cause it was quick and easy to use. So here it is as code.
Hope you enjoy and if you find any errors in the calculations let me know.
It was done HW 6.1 but I think it should run on earlier versions, as there is nothing special about the code.
Cheers Leo
HWS
Code: Select all
/*** Make sure we have at least Hollywood 6.1! */
@VERSION 6,1
/*** This script requires the MUIRoyale plugin */
@REQUIRE "MUIRoyale"
/*** Information about this app */
@APPTITLE "Resistor Calc"
@APPVERSION "$VER: 1.0.0 (26.01.18)"
@APPCOPYRIGHT "(C) 2018 by Leo den Hollander"
@APPAUTHOR "Leo den Hollander"
@APPDESCRIPTION "5 Band Resistor Calculator"
@DISPLAY {Hidden=True}
CreateBrush(0,25,75,$000000)
CreateBrush(1,25,75,$774422)
CreateBrush(2,25,75,$ff0000)
CreateBrush(3,25,75,$ff5522)
CreateBrush(4,25,75,$ffff00)
CreateBrush(5,25,75,$00ff00)
CreateBrush(6,25,75,$0000ff)
CreateBrush(7,25,75,$550055)
CreateBrush(8,25,75,$777777)
CreateBrush(9,25,75,$ffffff)
CreateBrush(10,25,75,$55ccff)
;*** Button Colour Check *****************************************************
Function ColourCheck()
idno = Val(RightStr(buttonid,2))
Mui.Set("result", "contents", idno)
if idno >= 10 and idno <= 19
Mui.set("B1", "Brush", idno - 10)
D1 = idno -10
endif
if idno >= 20 and idno <= 29
Mui.set("B2", "Brush", idno - 20)
D2 = idno -20
endif
if idno >= 30 and idno <= 39
Mui.set("B3", "Brush", idno - 30)
D3 = idno -30
endif
if idno >= 40 and idno <= 49
Mui.set("B4", "Brush", idno - 40)
D4 = idno - 40
If D4 = 0
D4 = 1
ElseIf D4 = 1
D4 = 10
ElseIf D4 = 2
D4 = 100
ElseIf D4 = 3
D4 = 1000
ElseIf D4 = 4
D4 = 10000
ElseIf D4 = 5
D4 = 100000
ElseIf D4 = 6
D4 = 1000000
ElseIf D4 = 7
D4 = 10000000
ElseIf D4 = 8
D4 = 100000000
ElseIf D4 = 9
D4 = 1000000000
Endif
endif
if idno >= 50 and idno <= 59
Mui.set("B5", "Brush", idno - 50)
D5 = idno -50
If D5 = 0
D5 = ""
ElseIf D5 = 1
D5 = " Tol = 1%"
ElseIf D5 = 2
D5 = " Tol = 2%"
ElseIf D5 = 3
D5 = ""
ElseIf D5 = 4
D5 = ""
ElseIf D5 = 5
D5 = " Tol = 0.5%"
ElseIf D5 = 6
D5= " Tol = 0.25%"
ElseIf D5 = 7
D5 = " Tol = 0.1%"
ElseIf D5 = 8
D5 = ""
ElseIf D5 = 9
D5 = ""
Endif
endif
Mui.set("result","contents", D1 .. D2 .. D3 .. " x " .. D4)
EndFunction
;*** Event Functios ***********************************************************
Function p_MUIFunc(msg)
Switch msg.action
Case "MUIRoyale":
Switch msg.attribute
Case "CloseRequest":
End
Case "Pressed":
If msg.id = "calc"
Resist = D1 .. D2 .. D3
Ohms = Val(Resist) * D4
If Ohms > 999 and ohms < 1000000
Ohms = Ohms/1000
Total = strstr(Ohms) .. " K ohms"
elseif Ohms > 999999 and ohms < 1000000000
Ohms = Ohms/1000000
Total = strstr(Ohms) .. " M ohms"
elseif Ohms > 999999999
Ohms = Ohms/1000000000
Total = strstr(Ohms) .. " G ohms"
else
Total = strstr(Ohms) .. " ohms"
endif
Mui.set("result","contents", Total .. D5)
elseif msg.id = "clear"
Mui.set("B1", "Brush", 10)
Mui.set("B2", "Brush", 10)
Mui.set("B3", "Brush", 10)
Mui.set("B4", "Brush", 10)
Mui.set("B5", "Brush", 10)
Mui.set("result","contents","")
D1 =0
D2 = 0
D3 = 0
D4 = 0
D5 = ""
else
buttonid = msg.id
Colourcheck()
endif
EndSwitch
EndSwitch
EndFunction
;*** dynamically create GUI from an external *.xml file definition ************
mui.CreateGui(FileToString("RC.xml"))
;*** listen to these events! **************************************************
InstallEventHandler({MUIRoyale = p_MUIFunc, HideWindow = p_MUIFunc, ShowWindow = p_MUIFunc})
;*** main loop! ***************************************************************
Repeat
WaitEvent
Forever
Code: Select all
<?xml version="1.0" encoding="iso-8859-1"?>
<application id="app">
<window id="win" title="5 Band Resistor Calculator" width="600" height="600" notify="closerequest">
<vgroup backgroundrgb="#bbbbbb" font="big">
<vgroup>
<colgroup columns="7">
<label centered="true"> Colour </label>
<label centered="true"> Band 1 </label>
<label centered="true"> Band 2 </label>
<label centered="true"> Band 3 </label>
<label centered="true"> Multiplier</label>
<label centered="true"> Tolerance </label>
<label centered="true"> Value </label>
<label> Black </label>
<button id="band10" notify="pressed" backgroundrgb="#000000"> </button>
<button id="band20" notify="pressed" backgroundrgb="#000000"> </button>
<button id="band30" notify="pressed" backgroundrgb="#000000"> </button>
<button id="band40" notify="pressed" backgroundrgb="#000000"> </button>
<button id="band50" notify="pressed" backgroundrgb="#000000"> </button>
<label centered="true"> 0 </label>
<label> Brown </label>
<button id="band11" notify="pressed" backgroundrgb="#774422"> </button>
<button id="band21" notify="pressed" backgroundrgb="#774422"> </button>
<button id="band31" notify="pressed" backgroundrgb="#774422"> </button>
<button id="band41" notify="pressed" backgroundrgb="#774422"> </button>
<button id="band51" notify="pressed" backgroundrgb="#774422"> </button>
<label centered="true"> 1 </label>
<label> Red </label>
<button id="band12" notify="pressed" backgroundrgb="#ff0000"> </button>
<button id="band22" notify="pressed" backgroundrgb="#ff0000"> </button>
<button id="band32" notify="pressed" backgroundrgb="#ff0000"> </button>
<button id="band42" notify="pressed" backgroundrgb="#ff0000"> </button>
<button id="band52" notify="pressed" backgroundrgb="#ff0000"> </button>
<label centered="true"> 2 </label>
<label> Orange </label>
<button id="band13" notify="pressed" backgroundrgb="#ff5522"> </button>
<button id="band23" notify="pressed" backgroundrgb="#ff5522"> </button>
<button id="band33" notify="pressed" backgroundrgb="#ff5522"> </button>
<button id="band43" notify="pressed" backgroundrgb="#ff5522"> </button>
<button id="band53" notify="pressed" backgroundrgb="#ff5522"> </button>
<label centered="true"> 3 </label>
<label> Yellow </label>
<button id="band14" notify="pressed" backgroundrgb="#ffff00"> </button>
<button id="band24" notify="pressed" backgroundrgb="#ffff00"> </button>
<button id="band34" notify="pressed" backgroundrgb="#ffff00"> </button>
<button id="band44" notify="pressed" backgroundrgb="#ffff00"> </button>
<button id="band54" notify="pressed" backgroundrgb="#ffff00"> </button>
<label centered="true"> 4 </label>
<label> Green </label>
<button id="band15" notify="pressed" backgroundrgb="#00ff00"> </button>
<button id="band25" notify="pressed" backgroundrgb="#00ff00"> </button>
<button id="band35" notify="pressed" backgroundrgb="#00ff00"> </button>
<button id="band45" notify="pressed" backgroundrgb="#00ff00"> </button>
<button id="band55" notify="pressed" backgroundrgb="#00ff00"> </button>
<label centered="true"> 5 </label>
<label> Blue </label>
<button id="band16" notify="pressed" backgroundrgb="#0000ff"> </button>
<button id="band26" notify="pressed" backgroundrgb="#0000ff"> </button>
<button id="band36" notify="pressed" backgroundrgb="#0000ff"> </button>
<button id="band46" notify="pressed" backgroundrgb="#0000ff"> </button>
<button id="band56" notify="pressed" backgroundrgb="#0000ff"> </button>
<label centered="true"> 6 </label>
<label> Violet </label>
<button id="band17" notify="pressed" backgroundrgb="#550055"> </button>
<button id="band27" notify="pressed" backgroundrgb="#550055"> </button>
<button id="band37" notify="pressed" backgroundrgb="#550055"> </button>
<button id="band47" notify="pressed" backgroundrgb="#550055"> </button>
<button id="band57" notify="pressed" backgroundrgb="#550055"> </button>
<label centered="true"> 7 </label>
<label> Gray </label>
<button id="band18" notify="pressed" backgroundrgb="#777777"> </button>
<button id="band28" notify="pressed" backgroundrgb="#777777"> </button>
<button id="band38" notify="pressed" backgroundrgb="#777777"> </button>
<button id="band48" notify="pressed" backgroundrgb="#777777"> </button>
<button id="band58" notify="pressed" backgroundrgb="#777777"> </button>
<label centered="true"> 8 </label>
<label> White </label>
<button id="band19" notify="pressed" backgroundrgb="#ffffff"> </button>
<button id="band29" notify="pressed" backgroundrgb="#ffffff"> </button>
<button id="band39" notify="pressed" backgroundrgb="#ffffff"> </button>
<button id="band49" notify="pressed" backgroundrgb="#ffffff"> </button>
<button id="band59" notify="pressed" backgroundrgb="#ffffff"> </button>
<label centered="true"> 9 </label>
</colgroup>
<vspace height="20"/>
</vgroup>
<vgroup>
<hgroup>
<rectangle />
<hgroup backgroundrgb="#999999" >
<rectangle />
<hspace width="10"/>
<image id="b1" source="brush:10" />
<image id="b2" source="brush:10" />
<image id="b3" source="brush:10" />
<image id="b4" source="brush:10" />
<hspace width="15"/>
<image id="b5" source="brush:10" />
<hspace width="10"/>
<rectangle/>
</hgroup>
<rectangle/>
</hgroup>
</vgroup>
<vspace height="5"/>
<vgroup>
<hgroup>
<rectangle/>
<text id="result" backgroundrgb="#999999"></text>
<rectangle/>
</hgroup>
</vgroup>
<vspace height="10"/>
<vgroup>
<hgroup>
<rectangle/>
<button id="calc" notify="pressed" >Calculate</button>
<rectangle/>
<button id="clear" notify="pressed" >Clear</button>
<rectangle/>
</hgroup>
<vspace height="10"/>
</vgroup>
</vgroup>
</window>
</application>