Sign in to follow this  
Followers 0
Maxtreeme

Resistor Calculator

11 posts in this topic

#1 ·  Posted (edited)

Dunno if anyone will find it usefull, but i did :P

I updated the code, thanks Zedna :whistle:

Resistor_Calculator.au3

Edited by Maxtreeme

Share this post


Link to post
Share on other sites



That is very nice, could have used that several yrs back when I was into electronics.. LOL Fingers are too fat now to mess with it.. LOL

Share this post


Link to post
Share on other sites

Great job. It beats reciting BBROUGBVGW.

Share this post


Link to post
Share on other sites

Thanks for the replies, i was working on it some time to get it right :shocked:

Maybe i will post some more scripts laterz :(


Share this post


Link to post
Share on other sites

made some changes to the code :shocked: no messageboxes :(


Share this post


Link to post
Share on other sites

#8 ·  Posted (edited)

Love it!!!

As I was Taught in College

Bad Boys Rape Our Young Girls But Violet Gives Willingly... (The Resistor code)

8)

Edited by Valuater

NEWHeader1.png

Share this post


Link to post
Share on other sites

#9 ·  Posted (edited)

made some changes to the code :shocked: no messageboxes :(

Here is another corrected version of your code:

when you changed some colors there was artefacts due to not using GUICtrlSetData but GUICtrlCreateLabel repeatedly

and some other little optimizations.

And another idea for improve: remove button Calculate and use GUIRegisterMsg to catch event for editchanged (I dn't know exactly what event)

#include <GUIConstants.au3>

GUICreate("Resistance Calculator v1.0",500,200)
$1 = GUICtrlCreateCombo ("First color", 10,10,100,20)
GUICtrlSetData($1,"Brown|Red|Orange|Yellow|Green|Blue|Violet|Gray|White")
$2 = GUICtrlCreateCombo ("Second color", 120,10,100,20)
GUICtrlSetData($2,"Black|Brown|Red|Orange|Yellow|Green|Blue|Violet|Gray|White")
$3 = GUICtrlCreateCombo ("Third color", 230,10,100,20)
GUICtrlSetData($3,"Silver|Gold|Black|Brown|Red|Orange|Yellow|Green|Blue|Violet|Gray|White")
$4 = GUICtrlCreateCombo ("Fourth color", 340,10,100,20)
GUICtrlSetData($4,"Silver|Gold|Brown|Red")
$calc = GUICtrlCreateButton ("Calculate",400,140,70,30)
GUICtrlCreateLabel ("More scripts on: www.scripthut.z1.ro",10,180)
$result_ohm = GUICtrlCreateLabel ("",10,60,300)
$result_kohm = GUICtrlCreateLabel ("",10,80,300)
$result_mohm = GUICtrlCreateLabel ("",10,100,300)
GUISetState (@SW_SHOW)

While 1
    $msg = GUIGetMsg()
    If $msg = $GUI_EVENT_CLOSE Then
        ExitLoop
    EndIf
    
    If $msg = $calc Then
        $read1 = GUICtrlRead ($1)
        $read2 = GUICtrlRead ($2)
        $read3 = GUICtrlRead ($3)
        $read4 = GUICtrlRead ($4)
        If $read1 = "First color" Or $read2 = "Second color" Or $read3 = "Third color" Or $read4 = "Fourth color" Then
            GUICtrlSetData($result_ohm,"")
            GUICtrlSetData($result_kohm,"")
            GUICtrlSetData($result_mohm,"")
            MsgBox (48,"Resistance Calculator v1.0","You didn't select all the colors!")
        Else
            If $read1 = "Brown" Then
                $color1 = 1
            ElseIf $read1 = "Red" Then
                $color1 = 2
            ElseIf $read1 = "Orange" Then
                $color1 = 3
            ElseIf $read1 = "Yellow" Then
                $color1 = 4
            ElseIf $read1 = "Green" Then
                $color1 = 5
            ElseIf $read1 = "Blue" Then
                $color1 = 6
            ElseIf $read1 = "Violet" Then
                $color1 = 7
            ElseIf $read1 = "Gray" Then
                $color1 = 8
            ElseIf $read1 = "White" Then
                $color1 = 9
            EndIf
            
            If $read2 = "Black" Then
                $color2 = 0
            ElseIf $read2 = "Brown" Then
                $color2 = 1
            ElseIf $read2 = "Red" Then
                $color2 = 2
            ElseIf $read2 = "Orange" Then
                $color2 = 3
            ElseIf $read2 = "Yellow" Then
                $color2 = 4
            ElseIf $read2 = "Green" Then
                $color2 = 5
            ElseIf $read2 = "Blue" Then
                $color2 = 6
            ElseIf $read2 = "Violet" Then
                $color2 = 7
            ElseIf $read2 = "Gray" Then
                $color2 = 8
            ElseIf $read2 = "White" Then
                $color2 = 9
            EndIf
            
            If $read3 = "Black" Then
                $color3 = 1
            ElseIf $read3 = "Brown" Then
                $color3 = 10
            ElseIf $read3 = "Red" Then
                $color3 = 100
            ElseIf $read3 = "Orange" Then
                $color3 = 1000
            ElseIf $read3 = "Yellow" Then
                $color3 = 10000
            ElseIf $read3 = "Green" Then
                $color3 = 100000
            ElseIf $read3 = "Blue" Then
                $color3 = 1000000
            ElseIf $read3 = "Violet" Then
                $color3 = 10000000
            ElseIf $read3 = "Gray" Then
                $color3 = 100000000
            ElseIf $read3 = "White" Then
                $color3 = 1000000000
            ElseIf $read3 = "Silver" Then
                $color3 = 0.01
            ElseIf $read3 = "Gold" Then
                $color3 = 0.1
            EndIf
            
            If $read4 = "Silver" Then
                $tol = "+- 10%"
            ElseIf $read4 = "Gold" Then
                $tol = "+- 5%"
            ElseIf $read4 = "Brown" Then
                $tol = "+- 1%"
            ElseIf $read4 = "Red" Then
                $tol = "+- 2%"
            EndIf
        
            $ohm = $color1 & $color2 * $color3
            $kohm = $ohm / 1000
            $mohm = $kohm / 1000
            GUICtrlSetData($result_ohm,$ohm & "  " & $tol & "   Ohm")
            If $ohm > 1000 Then
                GUICtrlSetData($result_kohm,$kohm & "  " & $tol & "   KOhm")
            Else
                GUICtrlSetData($result_kohm,"")
            EndIf
            If $kohm > 1000 Then
                GUICtrlSetData($result_mohm,$mohm & "  " & $tol & "   MOhm")
            Else
                GUICtrlSetData($result_mohm,"")
            EndIf
        EndIf
        
    EndIf       
    Sleep (10)
WEnd
Edited by Zedna

Share this post


Link to post
Share on other sites

Here is another corrected version of your code:

when you changed some colors there was artefacts due to not using GUICtrlSetData but GUICtrlCreateLabel repeatedly

and some other little optimizations.

And another idea for improve: remove button Calculate and use GUIRegisterMsg to catch event for editchanged (I dn't know exactly what event)

The reason i didn't use lots of commands relating to GUI, is because i'm not that familiar with GUI, still experimenting and learning them. But thanks for pointing out things, explaining, and giving advices :shocked: They are very much appreciated :(

Share this post


Link to post
Share on other sites

Hi,

Must say great idea ! :shocked:

But I'm sorry to disapoint you. There are some errors in your program :(

1.)

Try using the following colors

color1-color2-Color3

Red-Yellow-Green : 2400000 Ohm --> correct

Red-Black-Green : 20 Ohm --> Wrong !!! (Should be 2000000 Ohm)

Red-Red-Black : 22 Ohm --> correct

Red-Red-Silver : 20.02 Ohm --> Wrong !!! (should be 0.22 Ohm)

I resolved this problem.

2.)

In school I learned to create userfriendly programs, so I try to avoid to use buttons when it can be avoided.

Therefore I changed the program so the result is immediately shown the moment one of the comboboxes (One of the 4 colors) changes. (EventMode)

3.)

Users can type in one of the comboboxes garbage-characters.

Therefore I changed the program so the user can't type garbage into the comboboxes.

Instead when the user types the first character of a existing color, this color is shown.

Adapted code : see attachement

Hope to be of help,

Best regards,

Peter

Resistor_Calculator.au3

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!


Register a new account

Sign in

Already have an account? Sign in here.


Sign In Now
Sign in to follow this  
Followers 0