Jump to content

resistor decoder


corey822
 Share

Recommended Posts

CODE
;++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++

++

; creator corey822 from the autoit forum +

; +

; title = RESISTOR DECODER +

; +

; this program is used to decode resistors by putting the colors in the boxes +

;++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++

#include <GUIConstants.au3>

$Form1_1 = GUICreate("resistor decoding", 452, 231, 245, 118)

$color1 = GUICtrlCreateInput("color1", 56, 32, 65, 21)

$color2 = GUICtrlCreateInput("color2", 136, 32, 65, 21)

$color3 = GUICtrlCreateInput("color3", 216, 32, 65, 21)

$color4 = GUICtrlCreateInput("color4", 288, 32, 65, 21)

$Label1 = GUICtrlCreateLabel("resistor colors", 168, 8, 68, 17)

$Button1 = GUICtrlCreateButton("decode", 136, 64, 121, 25, 0)

$Label2 = GUICtrlCreateLabel("resistor code", 168, 104, 64, 17)

$Label3 = GUICtrlCreateLabel("0", 104, 144, 10, 17)

$Label4 = GUICtrlCreateLabel("0", 120, 144, 10, 17)

$Label5 = GUICtrlCreateLabel("0", 136, 144, 106, 17)

$Label6 = GUICtrlCreateLabel("resistance ==>>", 24, 184, 79, 17)

$Label7 = GUICtrlCreateLabel("0", 104, 184, 66, 25)

$Label8 = GUICtrlCreateLabel("color code ===>>", 16, 144, 87, 17)

$MenuItem1 = GUICtrlCreateMenu("help")

$MenuItem2 = GUICtrlCreateMenuItem("how to", $MenuItem1)

$MenuItem3 = GUICtrlCreateMenuItem("created by", $MenuItem1)

GUISetState(@SW_SHOW)

While 1

$nMsg = GUIGetMsg()

Switch $nMsg

Case $GUI_EVENT_CLOSE

Exit

Case $nMsg = $Button1

If GUICtrlRead($color1) = "black" Then

GUICtrlSetData($Label3, "0")

ElseIf GUICtrlRead($color1) = "brown" Then

GUICtrlSetData($Label3, "1")

ElseIf GUICtrlRead($color1) = "red" Then

GUICtrlSetData($Label3, "2")

ElseIf GUICtrlRead($color1) = "orange" Then

GUICtrlSetData($Label3, "3")

ElseIf GUICtrlRead($color1) = "yellow" Then

GUICtrlSetData($Label3, "4")

ElseIf GUICtrlRead($color1) = "green" Then

GUICtrlSetData($Label3, "5")

ElseIf GUICtrlRead($color1) = "blue" Then

GUICtrlSetData($Label3, "6")

ElseIf GUICtrlRead($color1) = "purple" Then

GUICtrlSetData($Label3, "7")

ElseIf GUICtrlRead($color1) = "grey" Then

GUICtrlSetData($Label3, "8")

ElseIf GUICtrlRead($color1) = "white" Then

GUICtrlSetData($Label3, "9")

ElseIf GUICtrlRead($color1) = "" Then

GUICtrlSetData($Label3, "No color entered !")

EndIf

If GUICtrlRead($color2) = "black" Then

GUICtrlSetData($Label4, "0")

ElseIf GUICtrlRead($color2) = "brown" Then

GUICtrlSetData($Label4, "1")

ElseIf GUICtrlRead($color2) = "red" Then

GUICtrlSetData($Label4, "2")

ElseIf GUICtrlRead($color2) = "orange" Then

GUICtrlSetData($Label4, "3")

ElseIf GUICtrlRead($color2) = "yellow" Then

GUICtrlSetData($Label4, "4")

ElseIf GUICtrlRead($color2) = "green" Then

GUICtrlSetData($Label4, "5")

ElseIf GUICtrlRead($color2) = "blue" Then

GUICtrlSetData($Label4, "6")

ElseIf GUICtrlRead($color2) = "purple" Then

GUICtrlSetData($Label4, "7")

ElseIf GUICtrlRead($color2) = "grey" Then

GUICtrlSetData($Label4, "8")

ElseIf GUICtrlRead($color2) = "white" Then

GUICtrlSetData($Label4, "9")

ElseIf GUICtrlRead($color2) = "" Then

GUICtrlSetData($Label4, "No text")

EndIf

If GUICtrlRead($color3) = "black" Then

GUICtrlSetData($color3, "")

ElseIf GUICtrlRead($color3) = "brown" Then

GUICtrlSetData($Label5, "0")

ElseIf GUICtrlRead($color3) = "red" Then

GUICtrlSetData($Label5, "00")

ElseIf GUICtrlRead($color3) = "orange" Then

GUICtrlSetData($Label5, "000")

ElseIf GUICtrlRead($color3) = "yellow" Then

GUICtrlSetData($Label5, "0000")

ElseIf GUICtrlRead($color3) = "green" Then

GUICtrlSetData($Label5, "0000")

ElseIf GUICtrlRead($color3) = "blue" Then

GUICtrlSetData($Label5, "00000")

ElseIf GUICtrlRead($color3) = "purple" Then

GUICtrlSetData($Label5, "000000")

ElseIf GUICtrlRead($color3) = "grey" Then

GUICtrlSetData($Label5, "00000000")

ElseIf GUICtrlRead($color3) = "white" Then

GUICtrlSetData($Label5, "000000000")

ElseIf GUICtrlRead($color3) = "" Then

GUICtrlSetData($Label5, "No text")

EndIf

If GUICtrlRead($color4) = "silver" Then

GUICtrlSetData($Label7, "10%")

ElseIf GUICtrlRead($color4) = "brown" Then

GUICtrlSetData($Label7, "1%")

ElseIf GUICtrlRead($color4) = "red" Then

GUICtrlSetData($Label7, "2%")

ElseIf GUICtrlRead($color4) = "gold" Then

GUICtrlSetData($Label7, "5%")

ElseIf GUICtrlRead($color4) = "none" Then

GUICtrlSetData($Label7, "20%")

ElseIf GUICtrlRead($color4) = "white" Then

GUICtrlSetData($Label7, "20%")

ElseIf GUICtrlRead($color4) = "" Then

GUICtrlSetData($Label7, "20%")

EndIf

EndSwitch

WEnd

hey yall this is my example of if statements used to create a program that decodes the colcors of resistors this is my first one so bar with me thsi still has soem edges to smooth off if any bugs or anywya you wopuld like to help me by telling me some good ways to do some things make it better

also looking for a way to link the menubar items

anyway please rate it from 1 to 10 please

cheers C.W

C.Wnew rules:1.dont use plz in a post or title use please instead2.always use help file as it is now muchly over rated3. dont think where not watching u4.please wait 24 hours after last post ot bump XD i use to make that mistake

Link to comment
Share on other sites

20 mins no reply :)

C.Wnew rules:1.dont use plz in a post or title use please instead2.always use help file as it is now muchly over rated3. dont think where not watching u4.please wait 24 hours after last post ot bump XD i use to make that mistake

Link to comment
Share on other sites

CODE
;++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++

++

; creator corey822 from the autoit forum +

; +

; title = RESISTOR DECODER +

; +

; this program is used to decode resistors by putting the colors in the boxes +

;++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++

#include <GUIConstants.au3>

$Form1_1 = GUICreate("resistor decoding", 452, 231, 245, 118)

$color1 = GUICtrlCreateInput("color1", 56, 32, 65, 21)

$color2 = GUICtrlCreateInput("color2", 136, 32, 65, 21)

$color3 = GUICtrlCreateInput("color3", 216, 32, 65, 21)

$color4 = GUICtrlCreateInput("color4", 288, 32, 65, 21)

$Label1 = GUICtrlCreateLabel("resistor colors", 168, 8, 68, 17)

$Button1 = GUICtrlCreateButton("decode", 136, 64, 121, 25, 0)

$Label2 = GUICtrlCreateLabel("resistor code", 168, 104, 64, 17)

$Label3 = GUICtrlCreateLabel("0", 104, 144, 10, 17)

$Label4 = GUICtrlCreateLabel("0", 120, 144, 10, 17)

$Label5 = GUICtrlCreateLabel("0", 136, 144, 106, 17)

$Label6 = GUICtrlCreateLabel("resistance ==>>", 24, 184, 79, 17)

$Label7 = GUICtrlCreateLabel("0", 104, 184, 66, 25)

$Label8 = GUICtrlCreateLabel("color code ===>>", 16, 144, 87, 17)

$MenuItem1 = GUICtrlCreateMenu("help")

$MenuItem2 = GUICtrlCreateMenuItem("how to", $MenuItem1)

$MenuItem3 = GUICtrlCreateMenuItem("created by", $MenuItem1)

GUISetState(@SW_SHOW)

While 1

$nMsg = GUIGetMsg()

Switch $nMsg

Case $GUI_EVENT_CLOSE

Exit

Case $nMsg = $Button1

If GUICtrlRead($color1) = "black" Then

GUICtrlSetData($Label3, "0")

ElseIf GUICtrlRead($color1) = "brown" Then

GUICtrlSetData($Label3, "1")

ElseIf GUICtrlRead($color1) = "red" Then

GUICtrlSetData($Label3, "2")

ElseIf GUICtrlRead($color1) = "orange" Then

GUICtrlSetData($Label3, "3")

ElseIf GUICtrlRead($color1) = "yellow" Then

GUICtrlSetData($Label3, "4")

ElseIf GUICtrlRead($color1) = "green" Then

GUICtrlSetData($Label3, "5")

ElseIf GUICtrlRead($color1) = "blue" Then

GUICtrlSetData($Label3, "6")

ElseIf GUICtrlRead($color1) = "purple" Then

GUICtrlSetData($Label3, "7")

ElseIf GUICtrlRead($color1) = "grey" Then

GUICtrlSetData($Label3, "8")

ElseIf GUICtrlRead($color1) = "white" Then

GUICtrlSetData($Label3, "9")

ElseIf GUICtrlRead($color1) = "" Then

GUICtrlSetData($Label3, "No color entered !")

EndIf

If GUICtrlRead($color2) = "black" Then

GUICtrlSetData($Label4, "0")

ElseIf GUICtrlRead($color2) = "brown" Then

GUICtrlSetData($Label4, "1")

ElseIf GUICtrlRead($color2) = "red" Then

GUICtrlSetData($Label4, "2")

ElseIf GUICtrlRead($color2) = "orange" Then

GUICtrlSetData($Label4, "3")

ElseIf GUICtrlRead($color2) = "yellow" Then

GUICtrlSetData($Label4, "4")

ElseIf GUICtrlRead($color2) = "green" Then

GUICtrlSetData($Label4, "5")

ElseIf GUICtrlRead($color2) = "blue" Then

GUICtrlSetData($Label4, "6")

ElseIf GUICtrlRead($color2) = "purple" Then

GUICtrlSetData($Label4, "7")

ElseIf GUICtrlRead($color2) = "grey" Then

GUICtrlSetData($Label4, "8")

ElseIf GUICtrlRead($color2) = "white" Then

GUICtrlSetData($Label4, "9")

ElseIf GUICtrlRead($color2) = "" Then

GUICtrlSetData($Label4, "No text")

EndIf

If GUICtrlRead($color3) = "black" Then

GUICtrlSetData($color3, "")

ElseIf GUICtrlRead($color3) = "brown" Then

GUICtrlSetData($Label5, "0")

ElseIf GUICtrlRead($color3) = "red" Then

GUICtrlSetData($Label5, "00")

ElseIf GUICtrlRead($color3) = "orange" Then

GUICtrlSetData($Label5, "000")

ElseIf GUICtrlRead($color3) = "yellow" Then

GUICtrlSetData($Label5, "0000")

ElseIf GUICtrlRead($color3) = "green" Then

GUICtrlSetData($Label5, "0000")

ElseIf GUICtrlRead($color3) = "blue" Then

GUICtrlSetData($Label5, "00000")

ElseIf GUICtrlRead($color3) = "purple" Then

GUICtrlSetData($Label5, "000000")

ElseIf GUICtrlRead($color3) = "grey" Then

GUICtrlSetData($Label5, "00000000")

ElseIf GUICtrlRead($color3) = "white" Then

GUICtrlSetData($Label5, "000000000")

ElseIf GUICtrlRead($color3) = "" Then

GUICtrlSetData($Label5, "No text")

EndIf

If GUICtrlRead($color4) = "silver" Then

GUICtrlSetData($Label7, "10%")

ElseIf GUICtrlRead($color4) = "brown" Then

GUICtrlSetData($Label7, "1%")

ElseIf GUICtrlRead($color4) = "red" Then

GUICtrlSetData($Label7, "2%")

ElseIf GUICtrlRead($color4) = "gold" Then

GUICtrlSetData($Label7, "5%")

ElseIf GUICtrlRead($color4) = "none" Then

GUICtrlSetData($Label7, "20%")

ElseIf GUICtrlRead($color4) = "white" Then

GUICtrlSetData($Label7, "20%")

ElseIf GUICtrlRead($color4) = "" Then

GUICtrlSetData($Label7, "20%")

EndIf

EndSwitch

WEnd

hey yall this is my example of if statements used to create a program that decodes the colcors of resistors this is my first one so bar with me thsi still has soem edges to smooth off if any bugs or anywya you wopuld like to help me by telling me some good ways to do some things make it better

also looking for a way to link the menubar items

anyway please rate it from 1 to 10 please

cheers C.W

It's a good start- keep playing with these ideas.

You have a small mistake in the second case statement. "Case $Msg = $Button1" should be "Case $Button1".

Here is a way to do it without using if at all for the colours.

;++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
; creator corey822 from the autoit forum +
; +
; title = RESISTOR DECODER +
; +
; this program is used to decode resistors by putting the colors in the boxes +
;++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++




#include <GUIConstants.au3>
Enum $black,$brown,$red,$orange,$yellow,$green,$blue, $purple, $grey, $white


$Form1_1 = GUICreate("resistor decoding", 452, 231, 245, 118)
$color1 = GUICtrlCreateInput("color1", 56, 32, 65, 21)
$color2 = GUICtrlCreateInput("color2", 136, 32, 65, 21)
$color3 = GUICtrlCreateInput("color3", 216, 32, 65, 21)
$color4 = GUICtrlCreateInput("color4", 288, 32, 65, 21)
$Label1 = GUICtrlCreateLabel("resistor colors", 168, 8, 68, 17)
$Button1 = GUICtrlCreateButton("decode", 136, 64, 121, 25, 0)
$Label2 = GUICtrlCreateLabel("resistor code", 168, 104, 64, 17)
$Label3 = GUICtrlCreateLabel("0", 104, 144, 10, 17)
$Label4 = GUICtrlCreateLabel("0", 120, 144, 10, 17)
$Label5 = GUICtrlCreateLabel("0", 136, 144, 106, 17)
$Label6 = GUICtrlCreateLabel("resistance ==>>", 24, 184, 79, 17)
$Label7 = GUICtrlCreateLabel("0", 104, 184, 66, 25)
$Label8 = GUICtrlCreateLabel("color code ===>>", 16, 144, 87, 17)
$MenuItem1 = GUICtrlCreateMenu("help")
$MenuItem2 = GUICtrlCreateMenuItem("how to", $MenuItem1)
$MenuItem3 = GUICtrlCreateMenuItem("created by", $MenuItem1)
GUISetState(@SW_SHOW)

While 1
    $nMsg = GUIGetMsg()
    Switch $nMsg
        Case $GUI_EVENT_CLOSE
            Exit
        Case $Button1
            GUICtrlSetData($Label3,Eval(GUICtrlRead($color1)))

            GUICtrlSetData($Label4,Eval(GUICtrlRead($color2)))

            GUICtrlSetData($Label5,Eval(GUICtrlRead($color3)))

            GUICtrlSetData($Label7,Eval(GUICtrlRead($color4)))

            If GUICtrlRead($color4) = "silver" Then
                GUICtrlSetData($Label7, "10%")
            ElseIf GUICtrlRead($color4) = "brown" Then
                GUICtrlSetData($Label7, "1%")
            ElseIf GUICtrlRead($color4) = "red" Then
                GUICtrlSetData($Label7, "2%")
            ElseIf GUICtrlRead($color4) = "gold" Then
                GUICtrlSetData($Label7, "5%")
            ElseIf GUICtrlRead($color4) = "none" Then
                GUICtrlSetData($Label7, "20%")
            ElseIf GUICtrlRead($color4) = "white" Then
                GUICtrlSetData($Label7, "20%")
            ElseIf GUICtrlRead($color4) = "" Then
                GUICtrlSetData($Label7, "20%")
            EndIf
    EndSwitch
WEnd
Serial port communications UDF Includes functions for binary transmission and reception.printing UDF Useful for graphs, forms, labels, reports etc.Add User Call Tips to SciTE for functions in UDFs not included with AutoIt and for your own scripts.Functions with parameters in OnEvent mode and for Hot Keys One function replaces GuiSetOnEvent, GuiCtrlSetOnEvent and HotKeySet.UDF IsConnected2 for notification of status of connected state of many urls or IPs, without slowing the script.
Link to comment
Share on other sites

It's a good start- keep playing with these ideas.

You have a small mistake in the second case statement. "Case $Msg = $Button1" should be "Case $Button1".

Here is a way to do it without using if at all for the colours.

;++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
; creator corey822 from the autoit forum +
; +
; title = RESISTOR DECODER +
; +
; this program is used to decode resistors by putting the colors in the boxes +
;++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++




#include <GUIConstants.au3>
Enum $black,$brown,$red,$orange,$yellow,$green,$blue, $purple, $grey, $white


$Form1_1 = GUICreate("resistor decoding", 452, 231, 245, 118)
$color1 = GUICtrlCreateInput("color1", 56, 32, 65, 21)
$color2 = GUICtrlCreateInput("color2", 136, 32, 65, 21)
$color3 = GUICtrlCreateInput("color3", 216, 32, 65, 21)
$color4 = GUICtrlCreateInput("color4", 288, 32, 65, 21)
$Label1 = GUICtrlCreateLabel("resistor colors", 168, 8, 68, 17)
$Button1 = GUICtrlCreateButton("decode", 136, 64, 121, 25, 0)
$Label2 = GUICtrlCreateLabel("resistor code", 168, 104, 64, 17)
$Label3 = GUICtrlCreateLabel("0", 104, 144, 10, 17)
$Label4 = GUICtrlCreateLabel("0", 120, 144, 10, 17)
$Label5 = GUICtrlCreateLabel("0", 136, 144, 106, 17)
$Label6 = GUICtrlCreateLabel("resistance ==>>", 24, 184, 79, 17)
$Label7 = GUICtrlCreateLabel("0", 104, 184, 66, 25)
$Label8 = GUICtrlCreateLabel("color code ===>>", 16, 144, 87, 17)
$MenuItem1 = GUICtrlCreateMenu("help")
$MenuItem2 = GUICtrlCreateMenuItem("how to", $MenuItem1)
$MenuItem3 = GUICtrlCreateMenuItem("created by", $MenuItem1)
GUISetState(@SW_SHOW)

While 1
    $nMsg = GUIGetMsg()
    Switch $nMsg
        Case $GUI_EVENT_CLOSE
            Exit
        Case $Button1
            GUICtrlSetData($Label3,Eval(GUICtrlRead($color1)))

            GUICtrlSetData($Label4,Eval(GUICtrlRead($color2)))

            GUICtrlSetData($Label5,Eval(GUICtrlRead($color3)))

            GUICtrlSetData($Label7,Eval(GUICtrlRead($color4)))

            If GUICtrlRead($color4) = "silver" Then
                GUICtrlSetData($Label7, "10%")
            ElseIf GUICtrlRead($color4) = "brown" Then
                GUICtrlSetData($Label7, "1%")
            ElseIf GUICtrlRead($color4) = "red" Then
                GUICtrlSetData($Label7, "2%")
            ElseIf GUICtrlRead($color4) = "gold" Then
                GUICtrlSetData($Label7, "5%")
            ElseIf GUICtrlRead($color4) = "none" Then
                GUICtrlSetData($Label7, "20%")
            ElseIf GUICtrlRead($color4) = "white" Then
                GUICtrlSetData($Label7, "20%")
            ElseIf GUICtrlRead($color4) = "" Then
                GUICtrlSetData($Label7, "20%")
            EndIf
    EndSwitch
WEnd

also ive noticed i think i need to create a button for each block of if's otherwise when i click the button it keeps running decodeing every single one as i put in a new color it keeps decoding which i think may use some pcu power

but thnx for the comments

cheers C.W

C.Wnew rules:1.dont use plz in a post or title use please instead2.always use help file as it is now muchly over rated3. dont think where not watching u4.please wait 24 hours after last post ot bump XD i use to make that mistake

Link to comment
Share on other sites

also ive noticed i think i need to create a button for each block of if's otherwise when i click the button it keeps running decodeing every single one as i put in a new color it keeps decoding which i think may use some pcu power

but thnx for the comments

cheers C.W

That's because of this if I understand you.

You have a small mistake in the second case statement. "Case $Msg = $Button1" should be "Case $Button1".

Serial port communications UDF Includes functions for binary transmission and reception.printing UDF Useful for graphs, forms, labels, reports etc.Add User Call Tips to SciTE for functions in UDFs not included with AutoIt and for your own scripts.Functions with parameters in OnEvent mode and for Hot Keys One function replaces GuiSetOnEvent, GuiCtrlSetOnEvent and HotKeySet.UDF IsConnected2 for notification of status of connected state of many urls or IPs, without slowing the script.
Link to comment
Share on other sites

That's because of this if I understand you.

ohhh infact u are right it becuyase first time i only took out the = sign :s

cheers C.W

C.Wnew rules:1.dont use plz in a post or title use please instead2.always use help file as it is now muchly over rated3. dont think where not watching u4.please wait 24 hours after last post ot bump XD i use to make that mistake

Link to comment
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
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...