自动加载文件到

时间:2017-09-02 00:59:29

标签: autoit

我正在尝试制作一个表单来从文件中选择某些样本并将其添加到另一个文件中...无法弄清楚它为什么不能正常工作..我尝试了它有没有数组,而程序只是列出文件位置而不是内容..也有人有这样的事情已经设置好每个列表附加到文件?

#include <ButtonConstants.au3>
#include <GUIConstantsEx.au3>
#include <GUIListBox.au3>
#include <WindowsConstants.au3>
#include <FileConstants.au3>
#include <MsgBoxConstants.au3>
#include <WinAPIFiles.au3>
#include <Date.au3>
#include <File.au3>

Global $aDate, $aTime
$text = ClipGet()
$sFileName = "\\SERVER\Server H\Staff Dropbox\blah\" & @MON & @MDAY & @YEAR & ".que"

#Region ### START Koda GUI section ### Form=
$Form2 = GUICreate("Choices Dialog", 345, 252, -1, -1)
$ListBox1 = GUICtrlCreateList("", 8, 8, 137, 201)
GUICtrlSetData(-1, "Item1|Item2|Item3|Item4|Item5")
$Button1 = GUICtrlCreateButton(">", 156, 15, 30, 25)
$Button2 = GUICtrlCreateButton(">>", 156, 48, 31, 25)
$Button3 = GUICtrlCreateButton("<", 157, 81, 31, 25)
GUICtrlSetState(-1, $GUI_DISABLE)
$Button4 = GUICtrlCreateButton("<<", 157, 114, 32, 25)
$ListBox2 = GUICtrlCreateList("", 200, 8, 137, 201)
$Button5 = GUICtrlCreateButton("&OK", 104, 225, 75, 25)
$Button6 = GUICtrlCreateButton("&Cancel", 184, 225, 75, 25)
$Clear = GUICtrlCreateButton("&Clear", 264, 225, 75, 25)
GUISetState(@SW_SHOW)
#EndRegion ### END Koda GUI section ###
GUICtrlSetData($ListBox1, "")
GUICtrlSetData($ListBox2, "")

$FileNameList = FileReadToArray($sFileName)

GUICtrlSetData($ListBox1, $sFileNameList)

While 1
    $nMsg = GUIGetMsg()
    Switch $nMsg
        Case $GUI_EVENT_CLOSE
            Exit
         Case $Button6
            Exit
         Case $Clear
            GUICtrlSetData($ListBox1, "")


    EndSwitch
WEnd

1 个答案:

答案 0 :(得分:0)

正确使用_FileReadToArrayhere。 因此,您必须使用:

_FileReadToArray($sFileName, $aFileContent)

也可能需要将自动版本更新为最新版本。 完整代码:

#include <ButtonConstants.au3>
#include <GUIConstantsEx.au3>
#include <GUIListBox.au3>
#include <WindowsConstants.au3>
#include <FileConstants.au3>
#include <Date.au3>
#include <File.au3>
#include <Array.au3>

Global $aDate, $aTime, $aFileContent
$text = ClipGet()
$sFileName = "\\SERVER\Server H\Staff Dropbox\blah\" & @MON & @MDAY & @YEAR & ".que"

#Region ### START Koda GUI section ### Form=
$Form2 = GUICreate("Choices Dialog", 345, 252, -1, -1)
$ListBox1 = GUICtrlCreateList("", 8, 8, 137, 201)
GUICtrlSetData(-1, "Item1|Item2|Item3|Item4|Item5")
$Button1 = GUICtrlCreateButton(">", 156, 15, 30, 25)
$Button2 = GUICtrlCreateButton(">>", 156, 48, 31, 25)
$Button3 = GUICtrlCreateButton("<", 157, 81, 31, 25)
GUICtrlSetState(-1, $GUI_DISABLE)
$Button4 = GUICtrlCreateButton("<<", 157, 114, 32, 25)
$ListBox2 = GUICtrlCreateList("", 200, 8, 137, 201)
$Button5 = GUICtrlCreateButton("&OK", 104, 225, 75, 25)
$Button6 = GUICtrlCreateButton("&Cancel", 184, 225, 75, 25)
$Clear = GUICtrlCreateButton("&Clear", 264, 225, 75, 25)
GUISetState(@SW_SHOW)
#EndRegion ### END Koda GUI section ###
GUICtrlSetData($ListBox1, "")
GUICtrlSetData($ListBox2, "")

_FileReadToArray($sFileName, $aFileContent)

if not IsArray($aFileContent) then
    msgbox(16,"Error","File read error")
    Exit
EndIf

;~ _ArrayDisplay($aFileContent)  ; to check content of  array

for $i = 1 to Ubound($aFileContent)-1
    GUICtrlSetData($ListBox1, $aFileContent[$i])
Next

While 1
    $nMsg = GUIGetMsg()
    Switch $nMsg
        Case $GUI_EVENT_CLOSE
            Exit
         Case $Button6
            Exit
         Case $Clear
            GUICtrlSetData($ListBox1, "")
    EndSwitch
WEnd