Frage zum Dateien abspeichern

  • Hallo,
    Ich habe folgendes problem.
    Ich möchte eine textdatei erstellen und dort hineinschreiben. Das geht auch soweit. Nun möchte ich das wenn ein button gedrückt wird die Textdatei als eine .xls Datei gespeichert wird(Excel). Das brauche ich da excel es automatisch unterstützt wenn in einem Textdokument eine Tabelle mit einem tab abstand habe fügt excel das dann automatisch in ein Blatt ein.
    Also wie speicher ich mein txt nachdem der button gedrückt wurde als .xls oder als irgendetwas anderes z.B .au3 ?

    lg

    clonker

    Einmal editiert, zuletzt von clonker (23. Februar 2010 um 18:47)

  • Hallo clonker,

    hier das Beispiel aus der Hilfe (leicht abgeändert):

    Spoiler anzeigen
    [autoit]

    $file = FileOpen("test.xls", 10)

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

    ; Prüfen, ob Datei im Schreibmodus geöffnet ist
    If $file = -1 Then
    MsgBox(0, "Fehler", "Die Datei konnte nicht geöffnet werden.")
    Exit
    EndIf

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

    FileWrite($file, "Zeile 1" & @TAB)
    FileWrite($file, "Immer noch Zeile 1" & @CRLF)
    FileWrite($file, "Zeile 2" & @TAB)
    FileWrite($file, "Zeile 2 Spalte 2")

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

    FileClose($file)

    [/autoit] [autoit][/autoit] [autoit][/autoit]
  • Hey Danke ! Hab aber noch folgendes Problem.

    Wenn ich in meinem Hauptgui einen button drücke öffnet sich ein weiteres gui was mich fragt als was ich speichern will.
    Aber irgendwie kommt mit getmsg jetzt alles durcheinander

    [autoit]

    Case $nMsg = $expogo ;Das ist der button im HauptGUI
    While 1
    $nMsg = GUIGetMsg()

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

    #include <ButtonConstants.au3>
    #include <GUIConstantsEx.au3>
    #include <StaticConstants.au3>
    #include <WindowsConstants.au3>
    #Region ### START Koda GUI section ### Form=
    $Form1 = GUICreate("Form1", 200, 147, 192, 124)
    $txt = GUICtrlCreateButton("Txt", 16, 104, 75, 25, $WS_GROUP)
    $excel = GUICtrlCreateButton("Excel", 112, 104, 75, 25, $WS_GROUP)
    $Label1 = GUICtrlCreateLabel("Soll als Excel oder Txt gespeichert werden ?", 24, 48, 36, 17)
    GUISetState(@SW_SHOW) ;GUI mit Frage öffnet sich
    ;Mein Versuch GUI 2 auch zu sagen auf Nachricht zu warten (geht nicht)
    while 1
    $Msg = GUIGetMsg()
    Select
    Case $Msg = $txt
    $file = FileOpen( "Exponentielles_Wachstum.txt", 1 )
    Case $Msg = $excel
    $file = FileOpen( "Exponentielles_Wachstum.xls", 1 )
    EndSelect
    Wend
    ;unwichtig
    $aenderungexpo = GUICtrlRead($expod) / 100
    $expobestand = GUICtrlRead($expob)
    $expomax = GUICtrlRead($expot)
    $expojahr = 0
    FileWriteLine($file," Zeit t Bestand B ")
    For $i = 0 To $expomax - 1
    $expojahr = $expojahr + 1
    $expobestand =$expobestand + ($aenderungexpo*$expobestand)
    FileWriteLine($file, $expojahr & " " & $expobestand)

    Next
    MsgBox( 64, "Erfolgreich", " Datei wurde unter dem Namen Exponentielles_Wachstum.txt erstellt !")
    exit

    [/autoit]

    lg clonker

  • Was soll denn das durcheinander in den ersten 3 Zeilen? Fehlt da Code? Bitte das ganze Script posten.

  • [autoit]

    #cs ----------------------------------------------------------------------------

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

    AutoIt Version: 3.3.4.0
    Author: myName

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

    Script Function:
    Template AutoIt script.

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

    #ce ----------------------------------------------------------------------------

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

    ; Script Start - Add your code below here

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

    #include <ButtonConstants.au3>
    #include <EditConstants.au3>
    #include <GUIConstantsEx.au3>
    #include <StaticConstants.au3>
    #include <WindowsConstants.au3>
    #Region ### START Koda GUI section ### Form=c:\users\jonas\downloads\koda_1.7.2.0\forms\wachstum.kxf
    $Form1_1 = GUICreate("Wachstumssimulator Version 1.5", 515, 199, 192, 135)
    $lineargo = GUICtrlCreateButton("Berechnen", 48, 144, 97, 33, $WS_GROUP)
    $expogo = GUICtrlCreateButton("Berechnen", 200, 144, 91, 33, $WS_GROUP)
    $bgrgo = GUICtrlCreateButton("Berechnen", 392, 144, 91, 33, $WS_GROUP)
    $Label2 = GUICtrlCreateLabel("Bestand", 32, 40, 43, 17)
    $Label3 = GUICtrlCreateLabel("Änderung", 31, 65, 50, 17)
    $Label4 = GUICtrlCreateLabel("Zeit", 35, 90, 22, 17)
    $linearb = GUICtrlCreateInput("", 80, 40, 57, 21)
    $lineard = GUICtrlCreateInput("", 81, 62, 57, 21)
    $lineart = GUICtrlCreateInput("", 79, 86, 57, 21)
    $Label6 = GUICtrlCreateLabel("Bestand", 192, 38, 43, 17)
    $Label7 = GUICtrlCreateLabel("Änderung", 191, 63, 50, 17)
    $Label8 = GUICtrlCreateLabel("Zeit", 195, 88, 22, 17)
    $expob = GUICtrlCreateInput("", 240, 38, 57, 21)
    $expod = GUICtrlCreateInput("", 241, 60, 57, 21)
    $expot = GUICtrlCreateInput("", 239, 84, 57, 21)
    $Label10 = GUICtrlCreateLabel("Bestand", 392, 38, 43, 17)
    $Label11 = GUICtrlCreateLabel("Änderung", 391, 63, 50, 17)
    $Label12 = GUICtrlCreateLabel("Zeit", 395, 88, 22, 17)
    $bgrb = GUICtrlCreateInput("", 440, 38, 57, 21)
    $bgrd = GUICtrlCreateInput("", 441, 60, 57, 21)
    $bgrt = GUICtrlCreateInput("", 439, 84, 57, 21)
    $Label13 = GUICtrlCreateLabel("Wachstumsgrenze", 343, 114, 92, 17)
    $bgrn = GUICtrlCreateInput("", 435, 110, 57, 21)
    $Label1 = GUICtrlCreateLabel("Exponentiell", 248, 16, 61, 17)
    $Label5 = GUICtrlCreateLabel("Linear", 86, 14, 33, 17)
    $Label9 = GUICtrlCreateLabel("Begrenzt", 446, 14, 46, 17)
    GUISetState(@SW_SHOW)

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

    MsgBox( 64, "Willkommen !", " Herzlich Willkommen zum Wachstumssimulator Version 1.0 von Florian Jonas !")
    #EndRegion ### END Koda GUI section ###
    While 1
    $nMsg = GUIGetMsg()

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

    if $nMsg = $GUI_EVENT_CLOSE then exit
    Select

    Case $nMsg = $lineargo
    $Anzahl = GUICtrlRead ( $lineart )
    $file = FileOpen ( "Lineareswachstum.txt", 1 )
    $aenderunglinear = GUICtrlRead($lineard)
    $linearbestand = GUICtrlRead($linearb)
    $linearmax = GUICtrlRead($lineart)
    $linearjahr = 0
    FileWriteLine($file," Zeit t Bestand B ")
    For $i = 0 To $linearmax - 1
    $linearjahr = $linearjahr + 1
    $linearbestand = $linearbestand + $aenderunglinear
    FileWriteLine($file, $linearjahr & " " & $linearbestand)
    Next
    MsgBox( 64, "Erfolgreich", " Datei wurde unter dem Namen Lineareswachstum.txt erstellt !")
    exit

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

    Case $nMsg = $expogo
    While 1
    $nMsg = GUIGetMsg()

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

    #include <ButtonConstants.au3>
    #include <GUIConstantsEx.au3>
    #include <StaticConstants.au3>
    #include <WindowsConstants.au3>
    #Region ### START Koda GUI section ### Form=
    $Form1 = GUICreate("Form1", 200, 147, 192, 124)
    $txt = GUICtrlCreateButton("Txt", 16, 104, 75, 25, $WS_GROUP)
    $excel = GUICtrlCreateButton("Excel", 112, 104, 75, 25, $WS_GROUP)
    $Label1 = GUICtrlCreateLabel("Soll als Excel oder Txt gespeichert werden ?", 24, 48, 36, 17)
    GUISetState(@SW_SHOW)

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

    while 1
    $Msg = GUIGetMsg()

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

    if $Msg = $txt
    then $file = FileOpen( "Exponentielles_Wachstum.txt", 1 )
    $aenderungexpo = GUICtrlRead($expod) / 100
    $expobestand = GUICtrlRead($expob)
    $expomax = GUICtrlRead($expot)
    $expojahr = 0
    FileWriteLine($file," Zeit t Bestand B ")
    For $i = 0 To $expomax - 1
    $expojahr = $expojahr + 1
    $expobestand =$expobestand + ($aenderungexpo*$expobestand)
    FileWriteLine($file, $expojahr & " " & $expobestand)

    Next
    MsgBox( 64, "Erfolgreich", " Datei wurde unter dem Namen Exponentielles_Wachstum.txt erstellt !")
    exit

    if $Msg = $excel
    then $file = FileOpen( "Exponentielles_Wachstum.xls", 1 )

    $aenderungexpo = GUICtrlRead($expod) / 100
    $expobestand = GUICtrlRead($expob)
    $expomax = GUICtrlRead($expot)
    $expojahr = 0
    FileWriteLine($file," Zeit t Bestand B ")
    For $i = 0 To $expomax - 1
    $expojahr = $expojahr + 1
    $expobestand =$expobestand + ($aenderungexpo*$expobestand)
    FileWriteLine($file, $expojahr & " " & $expobestand)

    Next
    MsgBox( 64, "Erfolgreich", " Datei wurde unter dem Namen Exponentielles_Wachstum.xls erstellt !")
    exit
    Wend

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


    Case $nMsg = $bgrgo
    $Anzahl = GUICtrlRead ( $bgrt )
    $file = FileOpen ( "Begrenztes_Wachstum.txt", 1 )
    $aenderungbgr = GUICtrlRead($bgrd) /100
    $bgrbestand = GUICtrlRead($bgrb)
    $bgrmax = GUICtrlRead($bgrt)
    $bgrgrenze = GUICtrlRead($bgrn)
    $bgrjahr = 0
    FileWriteLine($file," Zeit t Bestand B ")
    For $i = 0 To $bgrmax - 1
    $bgrjahr = $bgrjahr + 1
    $bgrbestand = $bgrbestand + ($aenderungbgr * ( $bgrgrenze - $bgrbestand ))
    FileWriteLine($file, $bgrjahr & " " & $bgrbestand)

    Next
    MsgBox( 64, "Erfolgreich", " Datei wurde unter dem Namen Begrenztes_Wachstum.txt erstellt !")
    exit

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




    EndSelect
    Wend

    [/autoit]
  • Hallo clonker,

    Skript hat Fehlermeldungen beim Starten:

    Spoiler anzeigen

    , daher mit Hilfe Tidy in Form gebracht und danch lauffähig gemacht:

    Spoiler anzeigen
    [autoit]

    #cs ----------------------------------------------------------------------------

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

    AutoIt Version: 3.3.4.0
    Author: myName

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

    Script Function:
    Template AutoIt script.

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

    #ce ----------------------------------------------------------------------------

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

    ; Script Start - Add your code below here

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

    #include <ButtonConstants.au3>
    #include <EditConstants.au3>
    #include <GUIConstantsEx.au3>
    #include <StaticConstants.au3>
    #include <WindowsConstants.au3>
    #Region ### START Koda GUI section ### Form=c:\users\jonas\downloads\koda_1.7.2.0\forms\wachstum.kxf
    $Form1_1 = GUICreate("Wachstumssimulator Version 1.5", 515, 199, 192, 135)
    $lineargo = GUICtrlCreateButton("Berechnen", 48, 144, 97, 33, $WS_GROUP)
    $expogo = GUICtrlCreateButton("Berechnen", 200, 144, 91, 33, $WS_GROUP)
    $bgrgo = GUICtrlCreateButton("Berechnen", 392, 144, 91, 33, $WS_GROUP)
    $Label2 = GUICtrlCreateLabel("Bestand", 32, 40, 43, 17)
    $Label3 = GUICtrlCreateLabel("Änderung", 31, 65, 50, 17)
    $Label4 = GUICtrlCreateLabel("Zeit", 35, 90, 22, 17)
    $linearb = GUICtrlCreateInput("", 80, 40, 57, 21)
    $lineard = GUICtrlCreateInput("", 81, 62, 57, 21)
    $lineart = GUICtrlCreateInput("", 79, 86, 57, 21)
    $Label6 = GUICtrlCreateLabel("Bestand", 192, 38, 43, 17)
    $Label7 = GUICtrlCreateLabel("Änderung", 191, 63, 50, 17)
    $Label8 = GUICtrlCreateLabel("Zeit", 195, 88, 22, 17)
    $expob = GUICtrlCreateInput("", 240, 38, 57, 21)
    $expod = GUICtrlCreateInput("", 241, 60, 57, 21)
    $expot = GUICtrlCreateInput("", 239, 84, 57, 21)
    $Label10 = GUICtrlCreateLabel("Bestand", 392, 38, 43, 17)
    $Label11 = GUICtrlCreateLabel("Änderung", 391, 63, 50, 17)
    $Label12 = GUICtrlCreateLabel("Zeit", 395, 88, 22, 17)
    $bgrb = GUICtrlCreateInput("", 440, 38, 57, 21)
    $bgrd = GUICtrlCreateInput("", 441, 60, 57, 21)
    $bgrt = GUICtrlCreateInput("", 439, 84, 57, 21)
    $Label13 = GUICtrlCreateLabel("Wachstumsgrenze", 343, 114, 92, 17)
    $bgrn = GUICtrlCreateInput("", 435, 110, 57, 21)
    $Label1 = GUICtrlCreateLabel("Exponentiell", 248, 16, 61, 17)
    $Label5 = GUICtrlCreateLabel("Linear", 86, 14, 33, 17)
    $Label9 = GUICtrlCreateLabel("Begrenzt", 446, 14, 46, 17)
    GUISetState(@SW_SHOW)

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

    MsgBox(64, "Willkommen !", " Herzlich Willkommen zum Wachstumssimulator Version 1.0 von Florian Jonas !")
    #EndRegion ### END Koda GUI section ###
    While 1
    $nMsg = GUIGetMsg()

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

    If $nMsg = $GUI_EVENT_CLOSE Then Exit
    Select

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

    Case $nMsg = $lineargo
    $Anzahl = GUICtrlRead($lineart)
    $file = FileOpen("Lineareswachstum.txt", 1)
    $aenderunglinear = GUICtrlRead($lineard)
    $linearbestand = GUICtrlRead($linearb)
    $linearmax = GUICtrlRead($lineart)
    $linearjahr = 0
    FileWriteLine($file, " Zeit t Bestand B ")
    For $i = 0 To $linearmax - 1
    $linearjahr = $linearjahr + 1
    $linearbestand = $linearbestand + $aenderunglinear
    FileWriteLine($file, $linearjahr & " " & $linearbestand)
    Next
    MsgBox(64, "Erfolgreich", " Datei wurde unter dem Namen Lineareswachstum.txt erstellt !")
    FileClose($file)
    Exit

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

    Case $nMsg = $expogo
    #Region ### START Koda GUI section ### Form=
    $Form1 = GUICreate("Form1", 200, 147, 192, 124)
    $txt = GUICtrlCreateButton("Txt", 16, 104, 75, 25, $WS_GROUP)
    $excel = GUICtrlCreateButton("Excel", 112, 104, 75, 25, $WS_GROUP)
    $Label1 = GUICtrlCreateLabel("Soll als Excel oder Txt gespeichert werden ?", 24, 48, 150, 51)
    GUISetState(@SW_SHOW)

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

    While 1
    $Msg = GUIGetMsg()

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

    If $Msg = $txt Then
    $file = FileOpen("Exponentielles_Wachstum.txt", 1)
    $aenderungexpo = GUICtrlRead($expod) / 100
    $expobestand = GUICtrlRead($expob)
    $expomax = GUICtrlRead($expot)
    $expojahr = 0
    FileWriteLine($file, " Zeit t Bestand B ")
    For $i = 0 To $expomax - 1
    $expojahr = $expojahr + 1
    $expobestand = $expobestand + ($aenderungexpo * $expobestand)
    FileWriteLine($file, $expojahr & " " & $expobestand)

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

    Next
    MsgBox(64, "Erfolgreich", " Datei wurde unter dem Namen Exponentielles_Wachstum.txt erstellt !")
    FileClose($file)
    Exit
    EndIf
    If $Msg = $excel Then
    $file = FileOpen("Exponentielles_Wachstum.xls", 1)

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

    $aenderungexpo = GUICtrlRead($expod) / 100
    $expobestand = GUICtrlRead($expob)
    $expomax = GUICtrlRead($expot)
    $expojahr = 0
    FileWriteLine($file, " Zeit t Bestand B ")
    For $i = 0 To $expomax - 1
    $expojahr = $expojahr + 1
    $expobestand = $expobestand + ($aenderungexpo * $expobestand)
    FileWriteLine($file, $expojahr & " " & $expobestand)

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

    Next
    MsgBox(64, "Erfolgreich", " Datei wurde unter dem Namen Exponentielles_Wachstum.xls erstellt !")
    FileClose($file)
    Exit
    EndIf
    WEnd

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

    Case $nMsg = $bgrgo
    $Anzahl = GUICtrlRead($bgrt)
    $file = FileOpen("Begrenztes_Wachstum.txt", 1)
    $aenderungbgr = GUICtrlRead($bgrd) / 100
    $bgrbestand = GUICtrlRead($bgrb)
    $bgrmax = GUICtrlRead($bgrt)
    $bgrgrenze = GUICtrlRead($bgrn)
    $bgrjahr = 0
    FileWriteLine($file, " Zeit t Bestand B ")
    For $i = 0 To $bgrmax - 1
    $bgrjahr = $bgrjahr + 1
    $bgrbestand = $bgrbestand + ($aenderungbgr * ($bgrgrenze - $bgrbestand))
    FileWriteLine($file, $bgrjahr & " " & $bgrbestand)

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

    Next
    MsgBox(64, "Erfolgreich", " Datei wurde unter dem Namen Begrenztes_Wachstum.txt erstellt !")
    FileClose($file)
    Exit
    EndSelect
    WEnd

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

    Teste es ausgiebig durch, ob noch alles so funktioniert wie du es willst, ansonsten zurück zu deinem Stand und die Fehler beseitigen

    Edit: fehlende FileClose eingefügt und doppelte Includes entfernt etc.

    mfg (Auto)Bert

    Einmal editiert, zuletzt von AutoBert (24. Februar 2010 um 09:06)

  • @clonker und AutoBert: doppelte Include's machen wenig Sinn. ;)

    Dann fehlen noch mehrere FileClose's und überarbeite mal noch die GUI. Schau dir auch mal die Funktion GUICtrlSetOnEvent an. Z.B. wenn ich eine Hauptgui habe läuft die mit OnEvent und die anderen kleinen Guis im MessageLoop Modus, da die nur kurze Abläufe haben und die nicht extra in Funktionen auslagern will..

    2 Mal editiert, zuletzt von m-obi (23. Februar 2010 um 21:30)

  • Hallo @m-obi,

    falls es aus meinem vorhergehenden Beitrag nicht hervorgegangen ist: ich habe lediglich (auch mit Hilfe von Tidy) den Code compilierfähig gemacht. Das heist falsche Zeilenschaltungen innerhalb von If .... then entfernt und abschliessende wend's bzw. endselect eingefügt. Ansonsten habe ich den Code nicht überarbeitet,

    mfg (Auto)Bert

  • wenn schon aufräumen dann richtig ^^

    Spoiler anzeigen
    [autoit]

    #include <GUIConstantsEx.au3>
    #include <WindowsConstants.au3>

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

    $Form1_1 = GUICreate("Wachstumssimulator Version 1.5", 515, 199, 192, 135)
    $lineargo = GUICtrlCreateButton("Berechnen", 48, 144, 97, 33, $WS_GROUP)
    $expogo = GUICtrlCreateButton("Berechnen", 200, 144, 91, 33, $WS_GROUP)
    $bgrgo = GUICtrlCreateButton("Berechnen", 392, 144, 91, 33, $WS_GROUP)
    $Label2 = GUICtrlCreateLabel("Bestand", 32, 40, 43, 17)
    $Label3 = GUICtrlCreateLabel("Änderung", 31, 65, 50, 17)
    $Label4 = GUICtrlCreateLabel("Zeit", 35, 90, 22, 17)
    $linearb = GUICtrlCreateInput("", 80, 40, 57, 21)
    $lineard = GUICtrlCreateInput("", 81, 62, 57, 21)
    $lineart = GUICtrlCreateInput("", 79, 86, 57, 21)
    $Label6 = GUICtrlCreateLabel("Bestand", 192, 38, 43, 17)
    $Label7 = GUICtrlCreateLabel("Änderung", 191, 63, 50, 17)
    $Label8 = GUICtrlCreateLabel("Zeit", 195, 88, 22, 17)
    $expob = GUICtrlCreateInput("", 240, 38, 57, 21)
    $expod = GUICtrlCreateInput("", 241, 60, 57, 21)
    $expot = GUICtrlCreateInput("", 239, 84, 57, 21)
    $Label10 = GUICtrlCreateLabel("Bestand", 392, 38, 43, 17)
    $Label11 = GUICtrlCreateLabel("Änderung", 391, 63, 50, 17)
    $Label12 = GUICtrlCreateLabel("Zeit", 395, 88, 22, 17)
    $bgrb = GUICtrlCreateInput("", 440, 38, 57, 21)
    $bgrd = GUICtrlCreateInput("", 441, 60, 57, 21)
    $bgrt = GUICtrlCreateInput("", 439, 84, 57, 21)
    $Label13 = GUICtrlCreateLabel("Wachstumsgrenze", 343, 114, 92, 17)
    $bgrn = GUICtrlCreateInput("", 435, 110, 57, 21)
    $Label1 = GUICtrlCreateLabel("Exponentiell", 248, 16, 61, 17)
    $Label5 = GUICtrlCreateLabel("Linear", 86, 14, 33, 17)
    $Label9 = GUICtrlCreateLabel("Begrenzt", 446, 14, 46, 17)
    GUISetState(@SW_SHOW, $Form1_1)

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

    $Form1 = GUICreate("Form1", 200, 147, 192, 124)
    $txt = GUICtrlCreateButton("Txt", 16, 104, 75, 25, $WS_GROUP)
    $excel = GUICtrlCreateButton("Excel", 112, 104, 75, 25, $WS_GROUP)
    $Label1 = GUICtrlCreateLabel("Soll als Excel oder Txt gespeichert werden ?", 24, 48, 36, 17)
    GUISetState(@SW_HIDE, $Form1)

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

    MsgBox(64, "Willkommen !", " Herzlich Willkommen zum Wachstumssimulator Version 1.0 von Florian Jonas !")

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

    While 1
    $nMsg = GUIGetMsg(1)
    Switch $nMsg[1]
    Case $Form1_1
    Switch $nMsg[0]
    Case $GUI_EVENT_CLOSE
    Exit
    Case $lineargo
    $Anzahl = GUICtrlRead($lineart)
    $file = FileOpen("Lineareswachstum.txt", 1)
    $aenderunglinear = GUICtrlRead($lineard)
    $linearbestand = GUICtrlRead($linearb)
    $linearmax = GUICtrlRead($lineart)
    $linearjahr = 0
    FileWriteLine($file, " Zeit t Bestand B ")
    For $i = 0 To $linearmax - 1
    $linearjahr = $linearjahr + 1
    $linearbestand = $linearbestand + $aenderunglinear
    FileWriteLine($file, $linearjahr & " " & $linearbestand)
    Next
    MsgBox(64, "Erfolgreich", " Datei wurde unter dem Namen Lineareswachstum.txt erstellt !")
    Exit
    Case $expogo
    GUISetState(@SW_HIDE, $Form1_1)
    GUISetState(@SW_SHOW, $Form1)
    Case $bgrgo
    $Anzahl = GUICtrlRead($bgrt)
    $file = FileOpen("Begrenztes_Wachstum.txt", 1)
    $aenderungbgr = GUICtrlRead($bgrd) / 100
    $bgrbestand = GUICtrlRead($bgrb)
    $bgrmax = GUICtrlRead($bgrt)
    $bgrgrenze = GUICtrlRead($bgrn)
    $bgrjahr = 0
    FileWriteLine($file, " Zeit t Bestand B ")
    For $i = 0 To $bgrmax - 1
    $bgrjahr = $bgrjahr + 1
    $bgrbestand = $bgrbestand + ($aenderungbgr * ($bgrgrenze - $bgrbestand))
    FileWriteLine($file, $bgrjahr & " " & $bgrbestand)
    Next
    MsgBox(64, "Erfolgreich", " Datei wurde unter dem Namen Begrenztes_Wachstum.txt erstellt !")
    Exit
    EndSwitch
    Case $Form1
    Switch $nMsg[0]
    Case $GUI_EVENT_CLOSE
    GUISetState(@SW_SHOW, $Form1_1)
    GUISetState(@SW_HIDE, $Form1)
    Case $txt
    $file = FileOpen("Exponentielles_Wachstum.txt", 1)
    $aenderungexpo = GUICtrlRead($expod) / 100
    $expobestand = GUICtrlRead($expob)
    $expomax = GUICtrlRead($expot)
    $expojahr = 0
    FileWriteLine($file, " Zeit t Bestand B ")
    For $i = 0 To $expomax - 1
    $expojahr = $expojahr + 1
    $expobestand = $expobestand + ($aenderungexpo * $expobestand)
    FileWriteLine($file, $expojahr & " " & $expobestand)
    Next
    MsgBox(64, "Erfolgreich", " Datei wurde unter dem Namen Exponentielles_Wachstum.txt erstellt !")
    Exit
    Case $excel
    $file = FileOpen("Exponentielles_Wachstum.xls", 1)
    $aenderungexpo = GUICtrlRead($expod) / 100
    $expobestand = GUICtrlRead($expob)
    $expomax = GUICtrlRead($expot)
    $expojahr = 0
    FileWriteLine($file, " Zeit t Bestand B ")
    For $i = 0 To $expomax - 1
    $expojahr = $expojahr + 1
    $expobestand = $expobestand + ($aenderungexpo * $expobestand)
    FileWriteLine($file, $expojahr & " " & $expobestand)
    Next
    MsgBox(64, "Erfolgreich", " Datei wurde unter dem Namen Exponentielles_Wachstum.xls erstellt !")
    Exit
    EndSwitch
    EndSwitch
    WEnd

    [/autoit]

    @clonker:
    die gui dürfte soweit passen. die einzelnen funktionen hinter den buttons hab ich mir jetzt nicht angesehn. brauchst du noch bei irgendwas hilfe?

    Eine excel würde ich nicht mit filewrite erstellen sondern mit den _Excel...() funktionen. sonst hast du zwar eine .xls datei erstellt, aber die formatierung passt garnicht mit excel
    schau die die am besten mal an:

    [autoit]

    _ExcelBookOpen()
    _ExcelWriteArray()
    _ExcelWriteCell()
    _ExcelWriteFormula()

    [/autoit]
  • Hallo @m-obi,

    falls es aus meinem vorhergehenden Beitrag nicht hervorgegangen ist: ich habe lediglich (auch mit Hilfe von Tidy) den Code compilierfähig gemacht. Das heist falsche Zeilenschaltungen innerhalb von If .... then entfernt und abschliessende wend's bzw. endselect eingefügt. Ansonsten habe ich den Code nicht überarbeitet,

    mfg (Auto)Bert

    Entschuldigung AutoBert dann nimm ich alles zurück. ^^