WiNo (Widerstandswert aus der Normwerte-Tabelle ausgeben)

    • Offizieller Beitrag

    Hallo Elektroniker!

    Dieses Programm gibt zu einem (fast) beliebigen Widerstandswert zwei Widerstände aus der Normwerte-Tabelle aus.
    Bedienung: ganz einfach, Widerstandswert eingeben, Normreihe auswählen, [Enter] drücken oder auf [Start] klicken.

    Von den ausgegeben Widerstandswerten ist einer kleiner als der eingegebene Wert und der andere größer.

    Spoiler anzeigen
    [autoit]


    #include <GUIConstants.au3>
    #Include <Misc.au3>
    Opt('TrayAutoPause', 0)
    Opt('GUIOnEventMode', 1)

    [/autoit] [autoit][/autoit] [autoit]

    Dim $reihe[5][97] = [[1.0, 1.5, 2.2, 3.3, 4.7, 6.8, 10.0], _; Reihe E6
    [1.0, 1.2, 1.5, 1.8, 2.2, 2.7, 3.3, 3.9, 4.7, 5.6, 6.8, 8.2, 10.0], _; Reihe E12
    [1.0, 1.1, 1.2, 1.3, 1.5, 1.6, 1.8, 2.0, 2.2, 2.4, 2.7, 3.0, 3.3, 3.6, 3.9, 4.3, 4.7, 5.1, 5.6, 6.2, 6.8, 7.5, 8.2, 9.1, 10.0], _; Reihe E24
    [1.00, 1.05, 1.10, 1.15, 1.21, 1.27, 1.33, 1.40, 1.47, 1.54, 1.62, 1.69, 1.78, 1.87, 1.96, 2.05, 2.15, 2.26, 2.37, 2.49, 2.61, 2.74, 2.87, 3.01, 3.16, 3.32, 3.48, 3.65, 3.83, 4.02, 4.22, 4.42, 4.64, 4.87, 5.11, 5.36, 5.62, 5.90, 6.19, 6.49, 6.81, 7.15, 7.50, 7.87, 8.25, 8.66, 9.09, 9.53, 10.0], _; Reihe E48
    [1.00, 1.02, 1.05, 1.07, 1.10, 1.13, 1.15, 1.18, 1.21, 1.24, 1.27, 1.30, 1.33, 1.37, 1.40, 1.43, 1.47, 1.50, 1.54, 1.58, 1.62, 1.65, 1.69, 1.74, 1.78, 1.82, 1.87, 1.91, 1.96, 2.00, 2.05, 2.10, 2.15, 2.21, 2.26, 2.32, 2.37, 2.43, 2.49, 2.55, 2.61, 2.67, 2.74, 2.80, 2.87, 2.94, 3.01, 3.09, 3.16, 3.24, 3.32, 3.40, 3.48, 3.57, 3.65, 3.74, 3.83, 3.92, 4.02, 4.12, 4.22, 4.32, 4.42, 4.53, 4.64, 4.75, 4.87, 4.99, 5.11, 5.23, 5.36, 5.49, 5.62, 5.76, 5.90, 6.04, 6.19, 6.34, 6.49, 6.65, 6.81, 6.98, 7.15, 7.32, 7.50, 7.68, 7.87, 8.06, 8.25, 8.45, 8.66, 8.87, 9.09, 9.31, 9.53, 9.76, 10.0]]; Reihe E96
    Dim $multipl1[4] = [1, 1e3, 1e6, 1e9]
    Dim $multipl2[6] = [0.01, 0.1, 1, 1E3, 1E6, 1E9]
    Dim $n_einheit[6] = [' Ohm',' Ohm', ' Ohm', ' kOhm', ' MOhm', ' GOhm']
    Dim $ring[8]
    $titel = 'WiNo (Widerstands-Normwerte)'
    $info = 'Dieses Programm sucht aus der Normwerte-Tabelle zwei Widerstände raus,' & @CRLF
    $info &= 'die zu dem eingegebenen Widerstandswert passen.'

    [/autoit] [autoit][/autoit] [autoit]

    $gui = GUICreate($titel, 640, 480, -1, -1, $WS_SIZEBOX+$WS_SYSMENU)
    GUISetOnEvent($GUI_EVENT_CLOSE, 'Beenden')
    GUISetBkColor(0xFFEBCD, $gui)
    GUICtrlCreateIcon(@SystemDir & "\shell32.dll",-222, 10, 10, 32, 32)
    GUICtrlCreateLabel($info, 45, 40, 600, 60)
    GUICtrlSetFont(-1, 14, 400, 0, "Times New Roman")
    GUICtrlCreateLabel('Widerstandswert: ', 45, 120, 130, 30)
    GUICtrlSetFont(-1, 12, 400, 0, "Times New Roman")
    $g_wert = GUICtrlCreateInput('', 180, 120, 60, 21)
    $g_einheit = GUICtrlCreateCombo('', 241, 120, 60, 20, BitOR($CBS_DROPDOWNLIST, $CBS_AUTOHSCROLL))
    GUICtrlSetData(-1, ' Ohm 0| kOhm 1| MOhm 2| GOhm 3', ' kOhm 1')
    GUICtrlCreateLabel('aus der', 315, 120, 60, 30)
    GUICtrlSetFont(-1, 12, 400, 0, "Times New Roman")
    $g_reihe = GUICtrlCreateCombo('', 370, 120, 55, 20, BitOR($CBS_DROPDOWNLIST, $CBS_AUTOHSCROLL))
    GUICtrlSetData(-1, ' E6 060| E12 121| E24 242| E48 483| E96 964', ' E12 121')
    GUICtrlCreateLabel('Normreihe', 430, 120, 130, 30)
    GUICtrlSetFont(-1, 12, 400, 0, "Times New Roman")
    GUICtrlCreateButton('Start', 180, 150, 120, 30)
    GUICtrlSetOnEvent(-1, 'Normwerte')

    [/autoit] [autoit][/autoit] [autoit]

    GUICtrlCreateLabel('Widerstand 1 =', 130, 245, 180, 30)
    GUICtrlSetFont(-1, 20, 800, 0, "Times New Roman")
    $g_erg1 = GUICtrlCreateLabel('0 Ohm', 320, 245, 200, 30)
    GUICtrlSetFont(-1, 20, 800, 0, "Times New Roman")

    [/autoit] [autoit][/autoit] [autoit]

    GUICtrlCreateLabel('Widerstand 2 =', 130, 315, 180, 30)
    GUICtrlSetFont(-1, 20, 800, 0, "Times New Roman")
    $g_erg2 = GUICtrlCreateLabel('0 Ohm', 320, 315, 200, 30)
    GUICtrlSetFont(-1, 20, 800, 0, "Times New Roman")

    [/autoit] [autoit][/autoit] [autoit]

    GUISetState()
    GUICtrlSetState($g_wert, $GUI_FOCUS)
    While 1
    Sleep(100)
    WEnd

    [/autoit] [autoit][/autoit] [autoit]

    Func Beenden()
    Exit
    EndFunc

    [/autoit] [autoit][/autoit] [autoit]

    Func Normwerte()
    $eingabe = StringReplace(GUICtrlRead($g_wert), ',', '.')
    If StringRegExp($eingabe, '[^0-9\.]') Then
    MsgBox(48, $titel, 'Bitte nur Zahlen eingeben!')
    GUICtrlSetState($g_wert, $GUI_FOCUS)
    Return 0
    Else
    $eingabe = Number($eingabe) * $multipl1[StringRight(GUICtrlRead($g_einheit),1)]
    If ($eingabe / $multipl2[5] > 1000) or ($eingabe / $multipl2[1] < 1) Then
    MsgBox(48, $titel, 'Eingabe liegt außerhalb des Wertebereichs!')
    GUICtrlSetState($g_wert, $GUI_FOCUS)
    Return 0
    Else
    Local $m1 = 1, $m2 = 0, $erg1, $erg2
    For $i = 5 To 0 Step -1
    If ($eingabe / $multipl2[$i]) >= 1 and ($eingabe / $multipl2[$i]) < 1000 Then
    $m2 = $i
    $eingabe /= $multipl2[$i]
    ExitLoop
    EndIf
    Next
    If $eingabe >= 100 Then
    $eingabe /= 100
    $m1 = 100
    ElseIf $eingabe >= 10 Then
    $eingabe /= 10
    $m1 = 10
    EndIf
    EndIf
    $lr = GUICtrlRead($g_reihe)
    $r = Number(StringRight($lr, 1))
    $lr = StringRight(StringTrimRight($lr, 1), 2)
    For $i = $lr To 0 Step -1
    If $reihe[$r][$i] <= $eingabe Then
    $erg1 = $reihe[$r][$i] * $m1 * _Iif($m2 < 2, $multipl2[$m2], 1)
    $erg2 = $reihe[$r][$i + 1] * $m1 * _Iif($m2 < 2, $multipl2[$m2], 1)
    ExitLoop
    EndIf
    Next
    GUICtrlSetData($g_erg1, $erg1 & $n_einheit[$m2])
    GUICtrlSetData($g_erg2, $erg2 & $n_einheit[$m2])
    EndIf
    GUICtrlSetState($g_wert, $GUI_FOCUS)
    EndFunc

    [/autoit]

    Edit: Bei der Eingabe ist sowohl der Dezimalpunkt als auch das Dezimalkomma zugelassen. So kann man bequem auch den Zehnerblock benutzen.

    @ Team: AHH! Man kann jetzt *.au3 auswählen und die AutoIt-Tags funktionieren auch wieder. Danke ans Team!