找回密码
 加入
搜索
查看: 726|回复: 7

[网络通信] [已解决]列表视图逐行读取文本的问题

[复制链接]
发表于 2022-4-2 10:43:11 | 显示全部楼层 |阅读模式
本帖最后由 lxcai369 于 2022-4-4 02:57 编辑

新手刚学习AU3,正在熟悉列表视图。然后想着自己动手做一个列表视图逐行读取文本,并选中读取后的项输出的测试脚本,但看了帮助里面的例子,感觉还是很糊涂
现在卡在
1:应该怎么逐行读取
2逐行读取的话是自动创建对应多的子项在列表里面的吗?
假如文本有30行,是自动创建30行还是?

3:鼠标选中单独的项,是可以直接使用的还是需要转成需要什么才可以用
麻烦各位大佬给指点一下,下面就是我开了个头然后怎么都弄不下去的代码,个人感觉贴上跟没贴一样


#include <ButtonConstants.au3>
#include <GUIConstantsEx.au3>
#include <ListViewConstants.au3>
#include <WindowsConstants.au3>
#include <GuiListView.au3>
#include <File.au3>
#Region ### START Koda GUI section ### Form=


$Form1 = GUICreate("列表测试", 615, 437, -1, -1)
$ListView1 = GUICtrlCreateListView("", 28, 12, 313, 417)
$Button1 = GUICtrlCreateButton("备用1", 368, 32, 225, 113)
$Button2 = GUICtrlCreateButton("备用2", 368, 162, 225, 113)
$Button3 = GUICtrlCreateButton("备用3", 368, 292, 225, 113)
GUISetState(@SW_SHOW)
Local $file = FileRead(@ScriptDir & "\abc.txt")
Local $line =_FileCountLines($file)
Local $tt = FileReadLine($file,$line)





While 1
   
   
    $nMsg = GUIGetMsg()
    Switch $nMsg
        Case $GUI_EVENT_CLOSE
            Exit
        Case $Button1
        Case $Button2
        Case $Button3
    EndSwitch
WEnd










发表于 2022-4-2 15:02:15 | 显示全部楼层
_GUICtrlListView_GetItemCount  获取行数
for循环 用 _GUICtrlListView_GetItemText 读取每行内容   
 楼主| 发表于 2022-4-2 17:30:46 | 显示全部楼层
skysmile 发表于 2022-4-2 15:02
_GUICtrlListView_GetItemCount  获取行数
for循环 用 _GUICtrlListView_GetItemText 读取每行内容

好的,谢谢大佬指点,我先试试
 楼主| 发表于 2022-4-3 16:07:33 | 显示全部楼层
本帖最后由 lxcai369 于 2022-4-3 16:12 编辑
skysmile 发表于 2022-4-2 15:02
_GUICtrlListView_GetItemCount  获取行数
for循环 用 _GUICtrlListView_GetItemText 读取每行内容

#include <GUIConstantsEx.au3>
#include <GuiListView.au3>
#include <File.au3>


Example()

Func Example()
        Local $idListview

        GUICreate("ListView Set Item Count", 400, 300)
        $idListview = GUICtrlCreateListView("", 2, 2, 394, 268)
        GUISetState(@SW_SHOW)

        Local $file = FileRead(@ScriptDir & "\active.txt")
        Local $line = _FileCountLines(@ScriptDir & "\active.txt")
        Local $tt = FileReadLine(@ScriptDir & "\active.txt", $line)
        ; Add columns
        _GUICtrlListView_AddColumn($idListview, 1, 370)

        ; Add items
        _GUICtrlListView_SetItemCount($idListview, $line)
        For $x = 1 To $line
                GUICtrlCreateListViewItem($x, $idListview)
               

        Next
        _GUICtrlListView_GetItemText($idListview,$tt)
        

        ; Loop until the user exits.
        Do
        Until GUIGetMsg() = $GUI_EVENT_CLOSE
        GUIDelete()
EndFunc   ;==>Example
   
试了下,在读取文本的时候出现错误。应该怎么写读取文本的函数,文本有28行,也读取出了28行,但内容是空的,应该怎么指向每一行的内容呢?
发表于 2022-4-3 16:47:15 | 显示全部楼层


#include <GUIConstantsEx.au3>
#include <GuiListView.au3>
#include <File.au3>


Example()

Func Example()
        Local $idListview

        GUICreate("ListView Set Item Count", 400, 300)
        $idListview = GUICtrlCreateListView("Line", 2, 2, 394, 268)
        GUISetState(@SW_SHOW)

        Local $sFile = @ScriptDir & '\active.txt'
        Local $hFile = FileOpen($sFile, FileGetEncoding($sFile))
        Local $sReadFile = FileRead($hFile)
        FileClose($hFile)
        Local $aLines = StringRegExp($sReadFile, '\V+', 3)
        If Not @error Then
                ; Add columns
                For $x = 0 To UBound($aLines) - 1
                        _GUICtrlListView_AddItem($idListview, $aLines[$x])
                Next
        EndIf
        ; Loop until the user exits.
        Do
        Until GUIGetMsg() = $GUI_EVENT_CLOSE
        GUIDelete()
EndFunc   ;==>Example


 楼主| 发表于 2022-4-3 21:57:28 | 显示全部楼层

看了大佬的代码更迷糊了,可以详细说下思路吗?
Local $hFile = FileOpen($sFile, FileGetEncoding($sFile)) 这行检测编码是为了?
以下这部分也不明白是啥意思
Local $aLines = StringRegExp($sReadFile, '\V+', 3)
        If Not @error Then
                ; Add columns
                For $x = 0 To UBound($aLines) - 1

新手小白,还在熟悉阶段。。实在抱歉
发表于 2022-4-3 22:16:45 | 显示全部楼层
lxcai369 发表于 2022-4-3 21:57
看了大佬的代码更迷糊了,可以详细说下思路吗?
Local $hFile = FileOpen($sFile, FileGetEncoding($sFi ...

是的,是检测编码
下面是用正则拆分文件内容的每一行到数组里面
 楼主| 发表于 2022-4-4 02:55:11 | 显示全部楼层
zghwelcome 发表于 2022-4-3 22:16
是的,是检测编码
下面是用正则拆分文件内容的每一行到数组里面

好的,非常感谢。还没学到那部分,有代码对照,看起来比较容易明白
您需要登录后才可以回帖 登录 | 加入

本版积分规则

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

GMT+8, 2024-5-4 09:35 , Processed in 0.071934 second(s), 19 queries .

Powered by Discuz! X3.5 Licensed

© 2001-2024 Discuz! Team.

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