怎么把TXT文件读入文本框中?
怎么把TXT文件读入文本框中,然后在文本框中修改,点确定按钮能够保存修改后的TXT文件内容。#include <ButtonConstants.au3>
#include <EditConstants.au3>
#include <GUIConstantsEx.au3>
#include <WindowsConstants.au3>
#Region ### START Koda GUI section ### Form=
$Form1 = GUICreate("Form1", 633, 447, 193, 125)
$Edit1 = GUICtrlCreateEdit("", 24, 16, 289, 153, BitOR($ES_AUTOVSCROLL,$ES_AUTOHSCROLL,$ES_WANTRETURN,$WS_VSCROLL))
GUICtrlSetData(-1, "Edit1")
$Button1 = GUICtrlCreateButton("确定", 184, 184, 113, 33, 0)
GUISetState(@SW_SHOW)
#EndRegion ### END Koda GUI section ###
While 1
$nMsg = GUIGetMsg()
Switch $nMsg
Case $GUI_EVENT_CLOSE
Exit
EndSwitch
WEnd
[ 本帖最后由 redapple2008 于 2008-7-31 07:00 编辑 ] $file = FileOpen("1.txt", 0)
While 1
$line = FileReadLine($file)
If @error = -1 Then ExitLoop
$Cnt += $Line & @CR;如果不用精确到行,可以使用 FileRead
Wend
GUICTRLSETDATA($Input1, $CNT)
手头没有 AU3 相关的东西,大致是这样,难免有错。
重新写回去,可以在帮助中查找 FileWrite。 为什么读TXT文件的时候是选中状态? #include <ButtonConstants.au3>
#include <EditConstants.au3>
#include <GUIConstantsEx.au3>
#include <WindowsConstants.au3>
#Region ### START Koda GUI section ### Form=
$Form1 = GUICreate("Form1", 633, 447, 193, 125)
$Edit1 = GUICtrlCreateEdit("", 24, 16, 289, 153, BitOR($ES_AUTOVSCROLL,$ES_AUTOHSCROLL,$ES_WANTRETURN,$WS_VSCROLL))
;GUICtrlSetData(-1, "Edit1")
$Button1 = GUICtrlCreateButton("确定", 184, 184, 113, 33, 0)
GUISetState(@SW_SHOW)
#EndRegion ### END Koda GUI section ###
$file = FileOpen("新建 文本文档.txt", 0)
dim $Cnt
While 1
$line = FileReadLine($file)
If @error = -1 Then ExitLoop
$Cnt += $Line & @CR
;如果不用精确到行,可以使用 FileRead
GUICTRLSETDATA($Edit1, $CNT)
Wend
While 1
$nMsg = GUIGetMsg()
Switch $nMsg
Case $GUI_EVENT_CLOSE
Exit
EndSwitch
WEnd
还是不行? 读取
while 1
if @error<>0 then exitloop
else
$line=FileReadLine($file,$i) & @CRLF & $line
endif
$i=$i+1
wend
GuiCtrlsetdata($Edit, $line)
写回
filewrite($fiel, $line)
[ 本帖最后由 netegg 于 2008-7-30 11:06 编辑 ] 为什么文本框读TXT文件的时候是选中状态? 回写不了。请改一下谢谢!
#include <ButtonConstants.au3>
#include <EditConstants.au3>
#include <GUIConstantsEx.au3>
#include <WindowsConstants.au3>
#Region ### START Koda GUI section ### Form=
$Form1 = GUICreate("Form1", 633, 447, 193, 125)
$Edit1 = GUICtrlCreateEdit("", 24, 16, 289, 153, BitOR($ES_AUTOVSCROLL,$ES_AUTOHSCROLL,$ES_WANTRETURN,$WS_VSCROLL))
;GUICtrlSetData(-1, "Edit1")
$Button1 = GUICtrlCreateButton("确定", 184, 184, 113, 33, 0)
GUISetState(@SW_SHOW)
#EndRegion ### END Koda GUI section ###
$file = FileOpen("新建 文本文档.txt", 0)
$i=1
While 1
$line=FileReadLine($file,$i)
;$line = FileReadLine($file)
If @error = -1 Then ExitLoop
$i=$i+1
GUICTRLSETDATA($Edit1, $line)
;$Cnt += $Line & @CR
;如果不用精确到行,可以使用 FileRead
FileClose("新建 文本文档.txt")
Wend
While 1
$nMsg = GUIGetMsg()
Switch $nMsg
Case $GUI_EVENT_CLOSE
Exit
Case $Button1
filewrite($file, $line)
EndSwitch
WEnd #include <file.au3>
#include <GuiEdit.au3>
#include <ButtonConstants.au3>
#include <EditConstants.au3>
#include <GUIConstantsEx.au3>
#include <WindowsConstants.au3>
Global $Files="1.txt"
$GUI = GUICreate("", 423, 254, 193, 115)
$Edit = GUICtrlCreateEdit("", 8, 8, 401, 201)
$OK = GUICtrlCreateButton("编辑", 8, 216, 75, 25, 0)
Readdate()
GUISetState()
While 1
$nMsg = GUIGetMsg()
Switch $nMsg
Case $GUI_EVENT_CLOSE
Exit
Case $OK
Setdate()
EndSwitch
WEnd
Func Readdate()
Dim $aRecords
If Not _FileReadToArray($Files, $aRecords) Then
MsgBox(4096, "错误", "无法打开文件!", 2)
Exit
EndIf
For $x = 1 To $aRecords
GUICtrlSetData($Edit, $aRecords[$x] & @CRLF, $x)
Next
EndFunc ;==>readdate
Func Setdate()
$Max = _GUICtrlEdit_GetLineCount($Edit)
For $y = 1 To $Max
$txt = _GUICtrlEdit_GetLine($Edit, $y)
_FileWriteToLine($Files, $y, $txt, 1)
Next
EndFunc ;==>Setdate 干嘛要用数组
#include <ButtonConstants.au3>
#include <EditConstants.au3>
#include <GUIConstantsEx.au3>
#include <WindowsConstants.au3>
Global $Files="log.txt"
$GUI = GUICreate("", 423, 254, 193, 115)
$Edit = GUICtrlCreateEdit("", 8, 8, 401, 201)
GUICtrlSetData(-1,readdate())
$OK = GUICtrlCreateButton("保存", 8, 216, 75, 25, 0)
GUISetState()
send("{down}")
While 1
$nMsg = GUIGetMsg()
Switch $nMsg
Case $GUI_EVENT_CLOSE
ExitLoop
Case $OK
Setdate()
EndSwitch
WEnd
Func Readdate()
Local $txt,$temp
$temp=FileOpen($Files,0)
$txt=FileRead($temp)
FileClose($temp)
Return $txt
EndFunc ;==>readdate
Func Setdate()
Local $txt,$temp
$temp=FileOpen($Files,2)
$txt=GUICtrlRead($Edit)
FileWrite($temp,$txt)
FileClose($temp)
EndFunc ;==>Setdate
回复 9# pcbar 的帖子
老大就是老大,简洁明了,学习了。 对在下有用,留着备用! 不错。。学习了。 谢谢,学习了 学习了,谢谢
页:
[1]