2017-09-02 100 views
-1

我想做一个窗体从文件中选择某些样本,并将其添加到另一个文件..无法弄清楚为什么它不会工作..我试过它和没有数组,程序只是列出文件的位置而不是内容..还有人有这样的东西的机会已经设置每个列表附加到文件?自动加载文件到

#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

检查sFilename是否正确计算。在调用FileReadToArray之前它有什么价值? – yacc

回答

0

使用_FileReadToArray正确的是here。 因此,你必须使用:

_FileReadToArray($sFileName, $aFileContent) 

也可能是你需要更新您的AutoIt版本最新。 完整代码:

#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