Hilfe bei IGR mit If Else Anweisung

  • Hallo , seit etwa 4 Wochen arbeit ich mit AutoIT und die Benutzeroberfläche hat mich begeistert , leider bin ich ein Neuling. Dennoch läuft mein erstes Script , der IGR (Idealgewichtsrechner), recht gut.
    Mein Problem zeigt sich bei der Eingabe von Schriftzeichen anstelle von Zahlen , hier kommt es natürlich zu Fehlern.
    Eine IF Else IsNumber müsste eingebaut werden - aber wie und wo?
    Was kann ich besser machen?

    [autoit]

    #include <GUIConstants.au3>

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

    $Form1_1 = GUICreate(" IGR", 370, 300, 193, 115)
    GUISetFont(12, 400, 0, "MS Sans Serif")
    $Label1 = GUICtrlCreateLabel(" Ihr IdealGewichtsRechner ", 32, 32, 318, 30)
    GUICtrlSetFont(-1, 18, 800, 0, "MS Sans Serif")
    $Input1 = GUICtrlCreateInput(" Hier Ihre Körpergröße in cm eingeben !", 40, 96, 289, 30)
    GUICtrlSetFont(-1, 12, 400, 0, "MS Sans Serif")
    $Button1 = GUICtrlCreateButton("Idealgewicht berechnen", 40, 152, 289, 30, 0)
    GUICtrlSetFont(-1, 12, 400, 0, "MS Sans Serif")
    $Label2 = GUICtrlCreateLabel("Ihr Idealgewicht in kg :", 88, 216, 187, 24)
    GUICtrlSetFont(-1, 12, 400, 0, "MS Sans Serif")
    $Label3 = GUICtrlCreateLabel("-kein-", 160, 256, 43, 24)
    GUICtrlSetFont(-1, 12, 400, 0, "MS Sans Serif")
    $Label4 = GUICtrlCreateLabel("V 2.0 Build 20070820", 0, 280, 107, 18)
    GUICtrlSetFont(-1, 8, 400, 0, "Arial")
    $Icon1 = GUICtrlCreateIcon("Smiley12.ico", 0, 296, 240, 32, 32, BitOR($SS_NOTIFY,$WS_GROUP))
    $Label5 = GUICtrlCreateLabel("Kiesi", 344, 280, 27, 18)
    GUICtrlSetFont(-1, 8, 400, 0, "Arial")
    GUISetState(@SW_SHOW)

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

    While 1
    $nMsg = GUIGetMsg()
    If $nMsg <> 0 Then
    $Zahl1 = GUICtrlRead ( $Input1 )
    Select
    Case $nMsg = $Button1
    GUICtrlSetData ($Label3, ( $Zahl1 - 100 ) * 0.9 )
    Case $nMsg = $GUI_EVENT_CLOSE
    Exit
    ExitLoop
    EndSelect
    EndIf

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

    WEnd

    [/autoit]
    • Offizieller Beitrag
    [autoit]

    #include <GUIConstants.au3>

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

    $Form1_1 = GUICreate(" IGR", 370, 300, 193, 115)
    GUISetFont(12, 400, 0, "MS Sans Serif")
    $Label1 = GUICtrlCreateLabel(" Ihr IdealGewichtsRechner ", 32, 32, 318, 30)
    GUICtrlSetFont(-1, 18, 800, 0, "MS Sans Serif")
    $Input1 = GUICtrlCreateInput(" Hier Ihre Körpergröße in cm eingeben !", 40, 96, 289, 30)
    GUICtrlSetFont(-1, 12, 400, 0, "MS Sans Serif")
    $Button1 = GUICtrlCreateButton("Idealgewicht berechnen", 40, 152, 289, 30, 0)
    GUICtrlSetFont(-1, 12, 400, 0, "MS Sans Serif")
    $Label2 = GUICtrlCreateLabel("Ihr Idealgewicht in kg :", 88, 216, 187, 24)
    GUICtrlSetFont(-1, 12, 400, 0, "MS Sans Serif")
    $Label3 = GUICtrlCreateLabel("-kein-", 160, 256, 43, 24)
    GUICtrlSetFont(-1, 12, 400, 0, "MS Sans Serif")
    $Label4 = GUICtrlCreateLabel("V 2.0 Build 20070820", 0, 280, 107, 18)
    GUICtrlSetFont(-1, 8, 400, 0, "Arial")
    $Icon1 = GUICtrlCreateIcon("Smiley12.ico", 0, 296, 240, 32, 32, BitOR($SS_NOTIFY, $WS_GROUP))
    $Label5 = GUICtrlCreateLabel("Kiesi", 344, 280, 27, 18)
    GUICtrlSetFont(-1, 8, 400, 0, "Arial")
    GUISetState(@SW_SHOW)

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

    While 1
    $nMsg = GUIGetMsg()
    If $nMsg <> 0 Then
    $Zahl1 = GUICtrlRead($Input1)
    Select
    Case $nMsg = $Button1
    If not StringIsDigit(GUICtrlRead($Input1)) THen
    MsgBox(0, "Fehler", "Bitte nur Zahlen eingeben!")
    Else
    GUICtrlSetData($Label3, ($Zahl1 - 100) * 0.9)
    EndIf
    Case $nMsg = $GUI_EVENT_CLOSE
    Exit
    ExitLoop
    EndSelect
    EndIf

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

    WEnd

    [/autoit]

    Sorra, habe gerade keine Zeit, es weiter zu erläutern, aber schau dir einfach mal die Funktionen in der Hilfe an, die ich verwendet habe.

    peethebee

  • [autoit]

    #include <GUIConstants.au3>

    $Form1_1 = GUICreate(" IGR", 370, 300, 193, 115)
    GUISetFont(12, 400, 0, "MS Sans Serif")
    $Label1 = GUICtrlCreateLabel(" Ihr IdealGewichtsRechner ", 32, 32, 318, 30)
    GUICtrlSetFont(-1, 18, 800, 0, "MS Sans Serif")
    $Input1 = GUICtrlCreateInput(" Hier Ihre Körpergröße in cm eingeben !", 40, 96, 289, 30)
    GUICtrlSetFont(-1, 12, 400, 0, "MS Sans Serif")
    $Button1 = GUICtrlCreateButton("Idealgewicht berechnen", 40, 152, 289, 30, 0)
    GUICtrlSetFont(-1, 12, 400, 0, "MS Sans Serif")
    $Label2 = GUICtrlCreateLabel("Ihr Idealgewicht in kg :", 88, 216, 187, 24)
    GUICtrlSetFont(-1, 12, 400, 0, "MS Sans Serif")
    $Label3 = GUICtrlCreateLabel("-kein-", 160, 256, 43, 24)
    GUICtrlSetFont(-1, 12, 400, 0, "MS Sans Serif")
    $Label4 = GUICtrlCreateLabel("V 2.0 Build 20070820", 0, 280, 107, 18)
    GUICtrlSetFont(-1, 8, 400, 0, "Arial")
    $Icon1 = GUICtrlCreateIcon("Smiley12.ico", 0, 296, 240, 32, 32, BitOR($SS_NOTIFY,$WS_GROUP))
    $Label5 = GUICtrlCreateLabel("Kiesi", 344, 280, 27, 18)
    GUICtrlSetFont(-1, 8, 400, 0, "Arial")
    GUISetState(@SW_SHOW)

    While 1
    $nMsg = GUIGetMsg()
    If $nMsg <> 0 Then
    $Zahl1 = GUICtrlRead ( $Input1 )
    Select
    Case $nMsg = $Button1

    if NOT IsNumber(GUICtrlRead($Input1)) Then
    MsgBox(0, "ERROR", "Bitte nur Zahlen eingeben!", 4)
    Endif
    GUICtrlSetData ($Label3, ( $Zahl1 - 100 ) * 0.9 )
    Case $nMsg = $GUI_EVENT_CLOSE
    Exit
    ExitLoop
    EndSelect
    EndIf

    WEnd

    [/autoit]
  • sofern es nur natürliche Zahlen seien dürfen, kannst Du das auch über einen Style erreichen:

    [autoit]


    $Input1 = GUICtrlCreateInput(" Hier Ihre Körpergröße in cm eingeben !", 40, 96, 289, 30,$ES_NUMBER)

    [/autoit]