#include <ButtonConstants.au3>
#include <EditConstants.au3>
#include <GUIConstantsEx.au3>
#include <WindowsConstants.au3>
#include<ListBoxConstants.au3>
#include <File.au3>
#Region ### START Koda GUI section ### Form=
GUICreate("Form1")
Dim $width = 800
Local $height = 600
GUICreate("Form1", $width, $height, (@DesktopWidth - $width) / 2, (@DesktopHeight - $height) / 2)
$list1 = GUICtrlCreateEdit("", 8, 8, 250, 400)
$list2 = GUICtrlCreateEdit("", 270, 8, 250, 400)
$Button1 = GUICtrlCreateButton("格式化数据文件", 8, 470, 105, 25, 0)
$Input1 = GUICtrlCreateInput("", 104, 440, 320, 21)
$Button2 = GUICtrlCreateButton("导入数据文件", 8, 440, 90, 25, 0)
GUISetState(@SW_SHOW)
#EndRegion ### END Koda GUI section ###
$newtxt = ''
While 1
$nMsg = GUIGetMsg()
Switch $nMsg
Case $GUI_EVENT_CLOSE
Exit
Case $Button2
$file = FileOpenDialog("请选择你要读取的文件", @ScriptDir, "txt(*.txt)", 3) ;出现一个选择文件的对话框
If $file <> "" Then
GUICtrlSetData($Input1, $file);将选择的文件写到 input1 控件中
GUICtrlSetData($list1, "");清空好处是可以多次导入数据文件而不会累加
GUICtrlSetData($list1, FileRead($file))
EndIf
Case $Button1;by pcbar edit
GUICtrlSetData($list2, "")
$txt = FileRead($file)
$txtline = StringSplit($txt, @CRLF)
If IsArray($txtline) Then
For $i = 1 To UBound($txtline) - 1
If $txtline[$i] <> "" Then
$txtline[$i] = StringRegExpReplace($txtline[$i], "\D", ' ')
$txtline[$i] = StringStripWS($txtline[$i], 1 + 2 + 4)
$tmp = StringSplit($txtline[$i], ' ')
If UBound($tmp) = 10 Then
$txtline[$i] = StringFormat("%04d %03d %02d %02d %02d %02d %02d %02d %02d", $tmp[1], $tmp[2], $tmp[3], $tmp[4], $tmp[5], $tmp[6], $tmp[7], $tmp[8], $tmp[9])
EndIf
GUICtrlSetData($list2, $txtline[$i] & @CRLF, 0)
EndIf
Next
EndIf
EndSwitch
WEnd