StringMid bzw. Richedit Problem

  • Abend,

    ich habe mir mal überlegt so etwas wie ein Speedwritingprogramm/spiel zu schreiben, wie z.B. das auf http://deutscher-speedtest.10fastfingers.com/

    Naja, nun habe ich es mal versucht und auf irgendeiner Art und Weise markiert er das Zeichen in der Editbox nicht, wenn es unten in der Inputbox richtig angegeben wurde.
    Script :

    Spoiler anzeigen
    [autoit]


    #Include <GuiRichEdit.au3>
    #Include <GuiEdit.au3>
    #include <ButtonConstants.au3>
    #include <EditConstants.au3>
    #include <GUIConstantsEx.au3>
    #include <StaticConstants.au3>
    #include <WindowsConstants.au3>
    #include <Color.au3>
    $Form1 = GUICreate("Speedwriting", 615, 414, 192, 124)
    $Edit1 = _GUICtrlRichEdit_Create($Form1,"", 8, 8, 601, 161)
    GUICtrlSetFont(-1, 18, 400, 0, "MS Sans Serif")
    $Start = GUICtrlCreateButton("Start", 240, 352, 131, 57)
    $Input1 = GUICtrlCreateInput("", 8, 232, 593, 21)
    $DeinText = GUICtrlCreateLabel("Dein Text :", 8, 200, 53, 17)
    GUISetState(@SW_SHOW)
    For $i=1 to 8
    $Random = Random (1, 3, 1)

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

    If $Random = 1 Then
    _GUICtrlRichEdit_AppendText($Edit1,"mag ")
    EndIf

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

    If $Random = 2 Then
    _GUICtrlRichEdit_AppendText($Edit1,"sein ")
    EndIf

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

    If $Random = 3 Then
    _GUICtrlRichEdit_AppendText($Edit1,"ich ")
    EndIf

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

    If $Random = 3 Then
    _GUICtrlRichEdit_AppendText($Edit1,"Haus ")
    EndIf

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

    If $Random = 3 Then
    _GUICtrlRichEdit_AppendText($Edit1,"Apfel ")
    EndIf

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

    If $Random = 3 Then
    _GUICtrlRichEdit_AppendText($Edit1,"Getränk ")
    EndIf

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

    If $Random = 3 Then
    _GUICtrlRichEdit_AppendText($Edit1,"bin ")
    EndIf
    next

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

    While 1
    $nMsg = GUIGetMsg()
    Switch $nMsg
    Case $GUI_EVENT_CLOSE
    Exit
    Case $Start
    $Counter1 = 1
    $Counter2 = 0
    while 1
    IF StringMid(GUICtrlRead($Edit1),$Counter1,1) = StringMid(GUICtrlRead($Input1),$Counter1,1) Then
    $Markieren = _GuiCtrlRichEdit_SetSel($Edit1,$Counter2,$Counter1)
    _GUICtrlRichEdit_SetCharColor($Edit1,0x00FF00)
    _GUICtrlRichEdit_Deselect($Edit1)
    $Counter1 += 1
    $Counter2 += 1
    EndIf
    WEnd
    EndSwitch
    WEnd

    [/autoit]

    Kann mir vielleicht jemand sagen, woran es liegt?

    Ich weiß, es ist schlecht geschrieben, möchte es auch erstmal testen, ob es funktioniert.

  • Moin, was soll er den Markieren? 8| verstehe ich nicht naja hab dein Script mal etwas aufgeräumt

    Spoiler anzeigen
    [autoit]


    #include <GUIConstantsEx.au3>
    #Include <GuiRichEdit.au3>

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

    Local $aText[8] = ["mag","sein","ich","Haus","Apfel","Getränk","bin"]
    $Form1 = GUICreate("Speedwriting", 615, 414, 192, 124)
    $Edit1 = _GUICtrlRichEdit_Create($Form1,"", 8, 8, 601, 161)
    _RandomText()
    GUICtrlSetFont(-1, 18, 400, 0, "MS Sans Serif")
    $Start = GUICtrlCreateButton("Start", 240, 352, 131, 57)
    $Input1 = GUICtrlCreateInput("", 8, 232, 593, 21)
    $DeinText = GUICtrlCreateLabel("Dein Text :", 8, 200, 53, 17)
    GUISetState(@SW_SHOW)

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

    While 1
    $nMsg = GUIGetMsg()
    Switch $nMsg
    Case $GUI_EVENT_CLOSE
    Exit
    Case $Start
    _Start()
    EndSwitch
    WEnd

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

    Func _Start()
    Local $TimeStamp = TimerInit()
    ; usw..
    EndFunc
    Func _RandomText()
    Local $RandomINT
    For $i = 1 To 8
    $RandomINT = Random(1, 7, 1)
    _GUICtrlRichEdit_AppendText($Edit1,$aText[$RandomINT]&' ')
    Next
    EndFunc

    [/autoit]

    Gruß Marvin

  • Hallo Julien,

    nimm statt GuiCtrlRead für das RichEditCntro _GUICtrlRichEdit_GetText. Desweiteren slltest du noch eine Abbruchbedingung einbauen snst kmmst du nie aus der 2. Schleife. Ich würde es s machen:

    [autoit]

    Case $Start
    $Counter1 = 1
    $Counter2 = 0
    $i = 0
    $l = _GUICtrlRichEdit_GetTextLength($Edit1)
    Do
    If StringMid(_GUICtrlRichEdit_GetText($Edit1), $Counter1, 1) = StringMid(GUICtrlRead($Input1), $Counter1, 1) Then
    $Markieren = _GuiCtrlRichEdit_SetSel($Edit1, $Counter2, $Counter1)
    _GUICtrlRichEdit_SetCharColor($Edit1, 0x00FF00)
    _GUICtrlRichEdit_Deselect($Edit1)
    $Counter1 += 1
    $Counter2 += 1
    EndIf
    $i+= 1
    Until $i > $l

    [/autoit]

    mfg autoBert