Liste soll .txt Datei einlesen...

  • Hey leute,

    ich habe ein Liste in dieser soll der inhalt einer .txt datei angezeigt werden...
    Jedoch soll man trozdem noch selber etwas eintragen können ohne das dies gespeichert wird...

    Das mit dem eintragen ohne speicheren habe ich hin bekommen nur das einlesen der .txt datei nicht...
    Hier eine kleine demo (Nicht der Original Code)

    [autoit]


    #include <ButtonConstants.au3>
    #include <GUIConstantsEx.au3>
    #include <GUIListBox.au3>
    #include <StaticConstants.au3>
    #include <WindowsConstants.au3>
    #include <File.au3>

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

    Global $links[1]
    _FileReadToArray(@DesktopDir & "\links.txt", $links)

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

    $Form3 = GUICreate("Form1", 405, 296, 302, 218)
    $List1 = GUICtrlCreateList("", 16, 8, 185, 266)
    $Button1 = GUICtrlCreateButton("Öffnen", 216, 16, 115, 25)
    GUISetState(@SW_SHOW)

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

    While 1
    $nMsg = GUIGetMsg()
    Switch $nMsg
    Case $GUI_EVENT_CLOSE
    Exit

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

    EndSwitch
    WEnd

    [/autoit]

    Wie bekomme ich es hin das eine Liste immer eingelesen wird ohne das man diese öffnen muss oder auch mit dem Öffnen button?

    Einmal editiert, zuletzt von Zero2q (3. September 2010 um 19:56)

  • Sowas?

    [autoit]


    _FileReadToArray(@DesktopDir & "\links.txt", $links)

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

    For $z = 1 To $links[0]
    GuiCtrlSetData($List1, $links[$z] & "|")
    Next

    [/autoit]


    leider ungetestet, hoffe das das so funktioniert, einfach an den Anfang des Scriptes oder dann bei "Case $Button1" in der While Schleife
    Deklarieren nicht vergessen

  • [autoit]


    #include <ButtonConstants.au3>
    #include <GUIConstantsEx.au3>
    #include <GUIListBox.au3>
    #include <StaticConstants.au3>
    #include <WindowsConstants.au3>
    #include <File.au3>

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

    Global $links[1]
    _FileReadToArray(@DesktopDir & "\links.txt", $links)

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

    $Form3 = GUICreate("Form1", 405, 296, 302, 218)
    $List1 = GUICtrlCreateList("", 16, 8, 185, 266)
    for $i = 1 to $links[0]
    $message &= $links[$i]&"|"
    next
    GUICtrlSetData($list1, $MESSAGE, $links[1])
    $Button1 = GUICtrlCreateButton("Öffnen", 216, 16, 115, 25)
    GUISetState(@SW_SHOW)

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

    While 1
    $nMsg = GUIGetMsg()
    Switch $nMsg
    Case $GUI_EVENT_CLOSE
    Exit

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

    EndSwitch
    WEnd

    [/autoit]
  • Error:

    GUICtrlSetData($list1, $MESSAGE, $links[1])
    GUICtrlSetData($list1, ^ ERROR
    >Exit code: 1 Time: 0.419

  • Ist doch vom Prinzip her das gleiche was ich versucht habe, oder?

    [autoit]

    Global $links[1]

    [/autoit]


    Versteh ich nicht ganz... dann hat das array doch nur platz für 1, sollte doch eig. unbeschränkt, bzw. je nach Größe der Datei sein, oder lieg ich da falsch?
    Stimmt dann bei mir oben auch nicht

  • Hallo zero2q,

    mach es so:

    Spoiler anzeigen
    [autoit]

    #include <ButtonConstants.au3>
    #include <GUIConstantsEx.au3>
    #include <GUIListBox.au3>
    #include <StaticConstants.au3>
    #include <WindowsConstants.au3>
    #include <File.au3>

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

    $sFilePath = @ScriptDir & "\Test.txt"
    if not FileExists($sFilePath) then
    For $i = 1 to 9
    FileWriteLine($sFilePath,$i &". Link")
    Next
    EndIf
    Global $links[1]

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

    $Form3 = GUICreate("Form1", 405, 296, 302, 218)
    $List1 = GUICtrlCreateList("", 16, 8, 185, 266)
    ;$Button1 = GUICtrlCreateButton("Öffnen", 216, 16, 115, 25)
    _FileReadToArray($sFilePath, $links)
    For $i = 1 To $links[0]
    GuiCtrlSetData($List1, $links[$i])
    Next
    GUISetState(@SW_SHOW)

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

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

    [/autoit]

    du must nur noch den Pfad zu deiner Datei anpassen,

    mfg autoBert

  • Hi!


    Probier das beispiel! ;)

    Spoiler anzeigen
    [autoit]

    #include <ButtonConstants.au3>
    #include <GUIConstantsEx.au3>
    #include <GUIListBox.au3>
    #include <StaticConstants.au3>
    #include <WindowsConstants.au3>
    #include <File.au3>

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

    $sFilePath = @ScriptDir & "\........txt"

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

    Global $links

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

    $Form3 = GUICreate("Form1", 405, 296, 302, 218)
    $List1 = GUICtrlCreateList("", 16, 8, 185, 266, BitOR($WS_BORDER, $WS_VSCROLL, $LBS_NOTIFY, $LBS_DISABLENOSCROLL, $WS_HSCROLL))
    ;$Button1 = GUICtrlCreateButton("Öffnen", 216, 16, 115, 25)
    _FileReadToArray($sFilePath, $links)
    For $i = 1 To $links[0]
    _GUICtrlListBox_AddString($List1, $links[$i])
    Next
    GUISetState(@SW_SHOW)

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

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

    [/autoit]

    Pfad anpassen!

    Lg Kleiner

  • Zitat

    ich habe ein Liste in dieser soll der inhalt einer .txt datei angezeigt werden...
    Jedoch soll man trozdem noch selber etwas eintragen können ohne das dies gespeichert wird...


    Das würde ich dann so machen:

    [autoit]

    #include <GuiConstantsEx.au3>
    $sFilePath = @DesktopDir & "\Links.txt"

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

    $Form3 = GUICreate("Form1", 405, 296, 302, 218)
    $List1 = GUICtrlCreateList("", 16, 8, 185, 266)
    GUICtrlSetData(-1, StringReplace(FileRead($sFilePath), @CRLF, Opt("GUIDataSeparatorChar")))
    GUISetState(@SW_SHOW)

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

    Do
    Until GUIGetMsg() = $GUI_EVENT_CLOSE

    [/autoit]
  • Ja Super funktioniert doch =) Danke AutoBert