找回密码
 加入
搜索
查看: 2196|回复: 13

如何将数据格式化,有请skyfree,pcbar大侠!30Q币示谢

[复制链接]
发表于 2008-9-21 20:55:49 | 显示全部楼层 |阅读模式

如上图要求(单击图片可放大观看),现附上已有的AU3界面代码和要导入的开奖数据.txt文件,请高人加上代码实现设想,30个Q币以示我的谢意!
#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 ###

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 控件中
EndIf

GUICtrlSetData($list1,"");清空好处是可以多次导入数据文件而不会累加
$fileopen = GUICtrlRead($Input1,0) ;定义$fileopen为 input1控件的值,获得详细路径文件名
$lines = _FileCountLines($fileopen) ;获取文件的行数
$con = FileRead($fileopen)
For $i = 1 To $lines ;遍历文件,从第一行到最后一行
$line = FileReadLine($FileOpen,$i) ;获取行内的文字
$noblank = StringStripWS($line,2) ; 清除行内右边的空格
$last = StringRight($noblank,1);取行内最后一个字符

GUICtrlSetData($list1,$noblank&@CRLF,"a") ;当 GuiCtrlSetData 的对象是edit list时 如果最后一个参数不会空则接着原来的数据 .否则就覆盖掉原来的数据
Next



EndSwitch
WEnd
以下是要导入的数据文件“开奖号码.txt”的内容:(因不能上传TXT附件,只需把下面的内容复制保存成txt文件就行了)
2007 1 06 12 14 30 32 38 41
2007 2 7 08 33 40 42 49 13
2007 13 3 17 33 8 43 49 14
2007 14 11 14 16 19 34 43 48
2008-15-01-02-10-27-40-41-43
2007.6.06.07.25.28.38.45.16
2007 107 14 4 23 25 38 42 1
2008 108 22 03 15 35 08 14 28

写好代码后,请高人留Q,你们的付出,菜鸟我将终生铭记,并在此薄奉Q币,以示最尊敬最实在的谢意!

[ 本帖最后由 蓓蕾 于 2008-9-23 13:30 编辑 ]

本帖子中包含更多资源

您需要 登录 才可以下载或查看,没有账号?加入

×
发表于 2008-9-21 21:03:26 | 显示全部楼层
这个需要用到正则吧
 楼主| 发表于 2008-9-21 22:20:30 | 显示全部楼层
楼上的大侠,我试了不行啊,因为有些行数据之间是没有空格的,是"-"线来的

[ 本帖最后由 蓓蕾 于 2008-9-21 22:35 编辑 ]
发表于 2008-9-21 22:36:56 | 显示全部楼层
都是空格的话 你能做出来么?
能的话有方法哦 哈哈
发表于 2008-9-21 23:30:27 | 显示全部楼层
试试,我的QQ45539551
#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
 楼主| 发表于 2008-9-22 01:09:12 | 显示全部楼层
如果数据变成以下的,只是多了一行而已,NETEGG少侠的代码就出问题了,PCBAR的没问题。
NETEGG少侠能修正下吗?
2007 1 06 12 14 30 32 38 41
2007 2 7 08 33 40 42 49 13
2006 071 15-16-24-04-45-22 02
2007 13 3 17 33 8 43 49 14
2007 14 11 14 16 19 34 43 48
2008-15-01-02-10-27-40-41-43
2007.6.06.07.25.28.38.45.16
2007 107 14 4 23 25 38 42 1

另pcbar Q币已充请查收:亲爱的用户(45539551),恭喜您购买产品成功!
购买明细如下:
产品名称: Q币 产品价格: 30
再次致以感谢!

[ 本帖最后由 蓓蕾 于 2008-9-22 01:18 编辑 ]
 楼主| 发表于 2008-9-22 10:53:33 | 显示全部楼层
楼上少侠,还是不行啊,你没有试过吧,我试了不行的,exiploop是EXITLOOP吧。还有是$j还是$I啊
 楼主| 发表于 2008-9-22 11:17:57 | 显示全部楼层
能修正出能运行的代码吗,q币致谢!因为PCBAR的也有个BUG,就是数据多了,比如500行就不能比较下去了!也不知什么原因
 楼主| 发表于 2008-9-22 12:34:32 | 显示全部楼层
不行啊,提示很多错误,不能运行代码
发表于 2008-9-22 13:41:48 | 显示全部楼层
太长了,贴不下,对了,没像pcbar做的是整个的,只是把数据处理那部分做完了
我试过了,同行的分隔符不一样都行了

[ 本帖最后由 netegg 于 2008-9-22 14:49 编辑 ]

本帖子中包含更多资源

您需要 登录 才可以下载或查看,没有账号?加入

×
发表于 2008-9-22 15:40:51 | 显示全部楼层
还有Q币奖励吗?如果有我就研究一下
发表于 2008-9-22 16:32:47 | 显示全部楼层
原帖由 蓓蕾 于 2008-9-22 11:17 发表
能修正出能运行的代码吗,q币致谢!因为PCBAR的也有个BUG,就是数据多了,比如500行就不能比较下去了!也不知什么原因

$list2 = GUICtrlCreateEdit("", 270, 8, 250, 400)这一行下面加上
GUICtrlSetLimit($list2,640000); 如果需要还可以再加大

因为edit控件默认文本长度是有限制的
发表于 2008-9-22 16:54:49 | 显示全部楼层
原帖由 顽固不化 于 2008-9-22 15:40 发表
还有Q币奖励吗?如果有我就研究一下


你起得太晚了
发表于 2011-3-19 09:51:11 | 显示全部楼层
很不错,谢谢分享
您需要登录后才可以回帖 登录 | 加入

本版积分规则

QQ|手机版|小黑屋|AUTOIT CN ( 鲁ICP备19019924号-1 )谷歌 百度

GMT+8, 2024-10-2 12:21 , Processed in 0.100060 second(s), 22 queries .

Powered by Discuz! X3.5 Licensed

© 2001-2024 Discuz! Team.

快速回复 返回顶部 返回列表