Variable außerhalb einer Funktion benutzen

  • Habe ein kleines Problemchen und dazu mal ein Beispiel gemacht...

    [autoit]

    _test()
    func _test()
    $a = "hallo"
    EndFunc

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

    MsgBox(0, "", $a)

    [/autoit]


    da kommt jetzt immer Variable used without bla bla
    kennt jemand eine Lösung ohne iniwrite?
    weil eigentlich wird ja die Variable definiert in der Funktion die ja VOR der msgbox kommt...

  • Mach so:

    [autoit]

    Local $a

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

    _test()
    func _test()
    $a = "hallo"
    EndFunc

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

    MsgBox(0, "", $a)

    [/autoit]
  • Hi,
    mach es besser so:

    [autoit]

    Global $a

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

    _test()
    MsgBox(0, "", $a)

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

    func _test()
    $a = "hallo"
    EndFunc

    [/autoit]

    ;-))

  • ja die Funktionen sind in meinem Skript eh alle ganz unten..war ja nur beim Beispiel so..
    und ob ich jetz local oder global nehme ist doch eigentlich auch egal odre?

  • Global = besserer Programmierstil ;) Local außerhalb von Funktio9nen ist eigentlich sinnlos, wird von AutoIt stillschweigend wie Global behandlet.