找回密码
 加入
搜索
查看: 4326|回复: 15

[AU3基础] 求查询文本数据的实现方法

[复制链接]
发表于 2019-10-17 09:12:38 | 显示全部楼层 |阅读模式
本帖最后由 smooth 于 2019-10-17 09:15 编辑

求一个根据输入的已知条件,搜索显示给定数据的实现方法。

要求:
    1、左打右,即表格中的左逆风、右顺风;右打左,即表中的右逆风、左顺风;
    2、当输入风力及屏距数据,自动搜索出:以该风力、屏距为中心,前后各3个屏距对应的“角度力度”数据,加上中心屏距,共7组数据。
    举例:当左逆风(从左边往右打)时,输入:风力20,屏距104,则输出:

        左逆风 20.0  101 54度(36.37)
        左逆风 20.0  102 62.63度(51)
        左逆风 20.0  103 64.63度(55)
        左逆风 20.0  104 60度(44.45)-----这是中心组
        左逆风 20.0  105 64度(59)
        左逆风 20.0  105 59度(44)
        左逆风 20.0  106 62度(49)

        如果前溯和后追时,遇到屏距与中心组一样时,则视为与中心组,不计算在前溯或后追的3组内。如:当左逆风时,输入风力20,屏距118,则得到如下数据输出:

        左逆风 20.0  113 60度(46.47)
        左逆风 20.0  115 63度(57)
        左逆风 20.0  115 62度(52)
        左逆风 20.0  115 59度(46)
        左逆风 20.0  117 61度(51)
        左逆风 20.0  118 63度(56)
        左逆风 20.0  118 57度(43.44)------中心组
        左逆风 20.0  119 55度(41)
        左逆风 20.0  120 64度(60)
        左逆风 20.0  120 54度(40)
        左逆风 20.0  122 62度(55)
        左逆风 20.0  122 60度(49)

        因为前溯一组,屏距也是118,所以视为中心组,则屏距117的组,才作为前溯的第一组。再往前的3个数据,屏距都是115,就作为同一组,将3行都输出。后追也是同样的道理。

        3、当左打右的框内有数据,右打左禁止输入数据。

欢迎各位大神指点一下实现的算法,如有大神帮忙做出来的,有酬谢。

GUI界面如下:



原始数据


本帖子中包含更多资源

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

×
发表于 2019-10-17 09:16:51 | 显示全部楼层
這是出考題??  都中級會員了  怎麼會這樣問問題....
 楼主| 发表于 2019-10-17 09:37:11 | 显示全部楼层
本帖最后由 smooth 于 2019-10-17 09:38 编辑
kk_lee69 发表于 2019-10-17 09:16
這是出考題??  都中級會員了  怎麼會這樣問問題....

自己水平不够啊,和中级会员没关系,有6、7年没玩AU3了。想付费找人帮忙写,不知道合不合版规,不合规的话我删掉。
发表于 2019-10-18 15:17:20 | 显示全部楼层
如果是纯文本数据我还可以搭把手,操作第三方数据就算了,办公软件没兴趣 我一个都没装
 楼主| 发表于 2019-10-20 12:01:03 | 显示全部楼层
afan 发表于 2019-10-18 15:17
如果是纯文本数据我还可以搭把手,操作第三方数据就算了,办公软件没兴趣 我一个都没装

A大,附件就是纯文本的数据,也可以直接把这些文本数据,直接在AU3里写入数组。麻烦A大指导一下。我现在也在写,遇到很多无法解决的困难,比如如何同时监视2个输入框,当有变化即时响应。

附件:

本帖子中包含更多资源

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

×
发表于 2019-10-20 12:17:39 | 显示全部楼层
本帖最后由 afan 于 2019-10-21 22:49 编辑
smooth 发表于 2019-10-20 12:01
A大,附件就是纯文本的数据,也可以直接把这些文本数据,直接在AU3里写入数组。麻烦A大指导一下。我现在 ...

看懂了大概的意思,不难但需要点时间搞
回复太慢,不等了。  
如有偿服务可PM我


发表于 2019-10-20 14:26:21 | 显示全部楼层
本帖最后由 yohoboy 于 2019-10-20 14:30 编辑

还没打完,,, 只是初步写个架构,后面就差不多, 你先清除栏位文字,然后第一个栏位及第二个栏位打数字,第二个栏位打完后按下ENTER键
#include <Array.au3>
#include <ButtonConstants.au3>
#include <Color.au3>
#include <SQLite.au3>
#include <EditConstants.au3>
#include <GuiButton.au3>
#include <GUIConstantsEx.au3>
#include <GUIEdit.au3>
#include <GUIListBox.au3>
#Include <GuiListView.au3>
#include <GuiStatusBar.au3>
#include <GuiRichEdit.au3>
#include <StaticConstants.au3>
#include <WindowsConstants.au3>

Opt("TrayIconHide", 1) ;0 = 顯示托盤圖標, 1 = 隱藏托盤圖標
Opt('MustDeclareVars', 1) ;0 = 變量不需預先聲明, 1 = 變量必需預先聲明
Opt("GUICloseOnESC", 0) ;0 = 點擊 Esc 鍵不關閉, 1 = 點擊 Esc 鍵關閉

Global $aRow, $hQuery

Local $SQLite_Data_Path = "Game_Books.sqlite" ;sql資料庫路徑及名稱

_SQLite_Startup ("sqlite3.dll", TRUE, 1) ;加載SQLite3.dll,工作目錄下需有SQLite3.dll
If @error Then ;如果沒有SQLite3.dll檔案則顯示錯誤訊息
    MsgBox($MB_SYSTEMMODAL, "SQLite 錯誤", "SQLite3.dll 不能載入,請檢查SQLite3.dll,SQLite3.def檔案是否存在同一目錄下!")
    Exit ;離開程式不執行
EndIf

If Not FileExists($SQLite_Data_Path) Then ;如果無資料庫或資料庫損毀要重建則執行以下命令
        Local $QUERY = MsgBox(1,"錯誤","資料庫無法打開,請檢查""BM-QUERY.sqlite""檔是否存在或是檔案已損毀,如要建立新檔請按確定,否則取消。")
        If $QUERY = 1 Then
                SQLCreate() ;建立新資料庫,參考SQLCreate() 功能,在下面
                Exit
        Else
                Exit
        EndIf
EndIf

Func SQLCreate() ;建立資料庫
    _SQLite_Open ($SQLite_Data_Path) ;建立資料庫,名稱為$SQLite_Data_Path 變數名稱
    _SQLite_Exec(-1, "Create Table IF NOT Exists Game_Books (Wind_Direction Text, Wind_Speed REAL," & _
                                 " Distance REAL, Angle Text);") ;建立資料庫內容
                                                                         ;以上執行SQL語法建立 BM_Number 資料表,並建立相關欄位等資料內容
        _SQLite_Close (-1) ;關閉資料庫
        MsgBox(0,"資料庫","資料庫已建立,請重新執行程式")
        Exit
EndFunc



Local $Title = "Game Books.." ;標題名稱
Local $GUI_Form = GUICreate($Title, 750, 480, -1, -1) ;建立主視窗GUI樣式
GUICtrlCreateLabel("左打右", 24, 32, 36, 17)
GUICtrlCreateLabel("逆风", 48, 64, 36, 17)
GUICtrlCreateLabel("屏距", 176, 64, 36, 17)
GUICtrlCreateLabel("顺风", 48, 128, 36, 17)
GUICtrlCreateLabel("屏距", 176, 128, 36, 17)
GUICtrlCreateLabel("右打左", 24, 184, 36, 17)
GUICtrlCreateLabel("逆风", 56, 216, 36, 17)
GUICtrlCreateLabel("屏距", 176, 208, 36, 17)
GUICtrlCreateLabel("顺风", 56, 280, 36, 17)
GUICtrlCreateLabel("屏距", 176, 280, 42, 17)
GUICtrlCreateLabel("數據顯示區域", 328, 16, 90, 17)
Local $Button1 = GUICtrlCreateButton("調整數據", 48, 360, 73, 25)
Local $Button2 = GUICtrlCreateButton("清除數據", 150, 360, 65, 25)
Local $Button3 = GUICtrlCreateButton("關閉", 250, 360, 65, 25)
Global $Edit1 = GUICtrlCreateEdit("", 344, 64, 309, 137)
GUICtrlSetData(-1, "Edit1")
Global $Edit2 = GUICtrlCreateEdit("", 344, 240, 309, 129)
GUICtrlSetData(-1, "Edit2")

Local $Input1 = GUICtrlCreateInput("Input1", 88, 64, 65, 21)
Local $Input2 = GUICtrlCreateInput("Input2", 224, 56, 57, 21)
Local $Input3 = GUICtrlCreateInput("Input3", 96, 136, 49, 21)
Local $Input4 = GUICtrlCreateInput("Input4", 224, 128, 49, 21)
Local $Input5 = GUICtrlCreateInput("Input5", 104, 216, 49, 21)
Local $Input6 = GUICtrlCreateInput("Input6", 232, 208, 49, 21)
Local $Input7 = GUICtrlCreateInput("Input7", 96, 280, 57, 21)
Local $Input8 = GUICtrlCreateInput("Input8", 240, 280, 41, 21)
_SQLite_Open ($SQLite_Data_Path)
GUISetState(@SW_SHOW,$GUI_Form) ;GUI 顯示

While 1
        Switch GUIGetMsg()
                Case $Button3,$GUI_EVENT_CLOSE
                        ExitLoop
                Case $Input2
                        If $Input1 <> "" And $Input2 <> "" Then Left_Headwind1()

                Case $Input4
                        If $Input1 <> "" And $Input2 <> "" Then MsgBox(0,"",GUICtrlRead($Input3)& "," & GUICtrlRead($Input4))
                Case $Button2
                        GUICtrlSetData($Input1, "")
                        GUICtrlSetData($Input2, "")
                        GUICtrlSetData($Input3, "")
                        GUICtrlSetData($Input4, "")
                        GUICtrlSetData($Input5, "")
                        GUICtrlSetData($Input6, "")
                        GUICtrlSetData($Input7, "")
                        GUICtrlSetData($Input8, "")
                        GUICtrlSetData($Edit1, "")
                        GUICtrlSetData($Edit2, "")
        EndSwitch
WEnd

Func Left_Headwind1()
        Local $Input2_temp1, $Input2_temp2, $sMsg, $COLOR_RED
        $Input2_temp1 = GUICtrlRead($Input2) - 4
        If $Input2_temp1 <= 0 Then $Input2_temp1 = 0
        $Input2_temp2 = GUICtrlRead($Input2) + 4
        ;MsgBox(0,"",$Input2_temp1&","&$Input2_temp2)
        _SQLite_Query(-1, "SELECT * FROM Game_Books Where Wind_Direction = 'Left_Headwind' And Wind_Speed = '" & GUICtrlRead($Input1)& _
                                "' And Distance >= '" & $Input2_temp1 & "' And Distance <= '" & $Input2_temp2 & "';",$hQuery)
        While _SQLite_FetchData($hQuery, $aRow) = $SQLITE_OK
                If $aRow[1] = GUICtrlRead($Input1) AND $aRow[2] = GUICtrlRead($Input2) Then
                        $sMsg &= "左逆風" & @TAB & $aRow[1] & @TAB & $aRow[2] & @TAB & $aRow[3] & @CRLF
                        GUICtrlSetColor($Edit1, $COLOR_RED)
                Else
                        $sMsg &= "左逆風" & @TAB & $aRow[1] & @TAB & $aRow[2] & @TAB & $aRow[3] & @CRLF
                EndIf
                ;MsgBox(0,"",$sMsg)
        WEnd
        GUICtrlSetData($Edit1,$sMsg,"")
EndFunc
放个目录下面执行看看


本帖子中包含更多资源

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

×
 楼主| 发表于 2019-10-20 21:06:09 | 显示全部楼层
yohoboy 发表于 2019-10-20 14:26
还没打完,,, 只是初步写个架构,后面就差不多, 你先清除栏位文字,然后第一个栏位及第二个栏位打数字,第 ...

下载下来,无法运行,提示第26行变量未声明。很多文字变成了乱码。
发表于 2019-10-20 22:57:18 | 显示全部楼层
本帖最后由 yohoboy 于 2019-10-21 00:54 编辑
smooth 发表于 2019-10-20 21:06
下载下来,无法运行,提示第26行变量未声明。很多文字变成了乱码。

選項/ user Options 開啟後輸入 code.page=65001  output.code.page=65001 , 很多繁體字,所以會有亂碼,用繁簡編輯軟體將內容改成簡體看看,
第26行改為
MsgBox(0, "SQLite 錯誤", "SQLite3.dll 不能載入,請檢查SQLite3.dll,SQLite3.def檔案是否存在同一目錄下!")

試試看
#include <Array.au3>
#include <ButtonConstants.au3>
#include <Color.au3>
#include <SQLite.au3>
#include <EditConstants.au3>
#include <GuiButton.au3>
#include <GUIConstantsEx.au3>
#include <GUIEdit.au3>
#include <GUIListBox.au3>
#Include <GuiListView.au3>
#include <GuiStatusBar.au3>
#include <GuiRichEdit.au3>
#include <StaticConstants.au3>
#include <WindowsConstants.au3>

Opt("TrayIconHide", 1) ;0 = 显示托盘图标, 1 = 隐藏托盘图标
Opt('MustDeclareVars', 1) ;0 = 变量不需预先声明, 1 = 变量必需预先声明
Opt("GUICloseOnESC", 0) ;0 = 点击 Esc 键不关闭, 1 = 点击 Esc 键关闭

Global $aRow, $hQuery, $GUI_ListBox

Local $SQLite_Data_Path = "Game_Books.sqlite" ;sql数据库路径及名称

_SQLite_Startup ("sqlite3.dll", TRUE, 1) ;加载SQLite3.dll,工作目录下需有SQLite3.dll
If @error Then ;如果没有SQLite3.dll档案则显示错误讯息
    MsgBox($MB_SYSTEMMODAL, "SQLite 错误", "SQLite3.dll 不能载入,请检查SQLite3.dll,SQLite3.def档案是否存在同一目录下!")
    Exit ;离开程序不执行
EndIf

If Not FileExists($SQLite_Data_Path) Then ;如果无数据库或数据库损毁要重建则执行以下命令
        Local $QUERY = MsgBox(1,"错误","数据库无法打开,请检查""BM-QUERY.sqlite""档是否存在或是档案已损毁,如要建立新档请按确定,否则取消。")
        If $QUERY = 1 Then
                SQLCreate() ;建立新数据库,参考SQLCreate() 功能,在下面
                Exit
        Else
                Exit
        EndIf
EndIf

Func SQLCreate() ;建立数据库
    _SQLite_Open ($SQLite_Data_Path) ;建立数据库,名称为$SQLite_Data_Path 变量名称
    _SQLite_Exec(-1, "Create Table IF NOT Exists Game_Books (Wind_Direction Text, Wind_Speed REAL," & _
                                 " Distance REAL, Angle Text);") ;建立数据库内容
                                                                         ;以上执行SQL语法建立数据表,并建立相关字段等数据内容
        _SQLite_Close (-1) ;关闭数据库
        MsgBox(0,"数据库","数据库已建立,请重新执行程序")
        Exit
EndFunc



Local $Title = "Game Books.." ;标题名称
Local $GUI_Form = GUICreate($Title, 750, 480, -1, -1) ;建立主窗口GUI样式
GUICtrlCreateLabel("左打右", 24, 32, 36, 17)
GUICtrlCreateLabel("逆风", 48, 64, 36, 17)
GUICtrlCreateLabel("屏距", 176, 64, 36, 17)
GUICtrlCreateLabel("顺风", 48, 128, 36, 17)
GUICtrlCreateLabel("屏距", 176, 128, 36, 17)
GUICtrlCreateLabel("右打左", 24, 184, 36, 17)
GUICtrlCreateLabel("逆风", 56, 216, 36, 17)
GUICtrlCreateLabel("屏距", 176, 208, 36, 17)
GUICtrlCreateLabel("顺风", 56, 280, 36, 17)
GUICtrlCreateLabel("屏距", 176, 280, 42, 17)
GUICtrlCreateLabel("数据显示区域", 328, 16, 90, 17)
;Local $Button1 = GUICtrlCreateButton("调整数据", 48, 360, 73, 25)
Local $Button2 = GUICtrlCreateButton("清除数据", 150, 360, 65, 25)
Local $Button3 = GUICtrlCreateButton("关闭", 250, 360, 65, 25)

Local $iStylesEx = BitOR($LVS_EX_FULLROWSELECT, $LVS_EX_CHECKBOXES)
$GUI_ListBox = GUICtrlCreateListView("  风    向  |风向值| 屏 距 |    角    度    ", 344, 64, 300, 300)
_GUICtrlListView_SetExtendedListViewStyle($GUI_ListBox, $iStylesEx)
Local $Input1 = GUICtrlCreateInput("", 88, 64, 65, 21)
Local $Input2 = GUICtrlCreateInput("", 224, 56, 57, 21)
Local $Input3 = GUICtrlCreateInput("", 96, 136, 49, 21)
Local $Input4 = GUICtrlCreateInput("", 224, 128, 49, 21)
Local $Input5 = GUICtrlCreateInput("", 104, 216, 49, 21)
Local $Input6 = GUICtrlCreateInput("", 232, 208, 49, 21)
Local $Input7 = GUICtrlCreateInput("", 96, 280, 57, 21)
Local $Input8 = GUICtrlCreateInput("", 240, 280, 41, 21)
_SQLite_Open ($SQLite_Data_Path)
GUISetState(@SW_SHOW,$GUI_Form) ;GUI 显示

While 1
        Switch GUIGetMsg()
                Case $Button3,$GUI_EVENT_CLOSE
                        ExitLoop
                Case $Input2
                        If $Input1 <> "" And $Input2 <> "" Then Left_Headwind1()

                Case $Input4
                       ; If $Input3 <> "" And $Input4 <> "" Then MsgBox(0,"",GUICtrlRead($Input3)& "," & GUICtrlRead($Input4))
                Case $Button2
                        GUICtrlSetData($Input1, "")
                        GUICtrlSetData($Input2, "")
                        GUICtrlSetData($Input3, "")
                        GUICtrlSetData($Input4, "")
                        GUICtrlSetData($Input5, "")
                        GUICtrlSetData($Input6, "")
                        GUICtrlSetData($Input7, "")
                        GUICtrlSetData($Input8, "")
        EndSwitch
WEnd

Func Left_Headwind1()
        _GUICtrlListView_DeleteAllItems($GUI_ListBox)
        Local $Input2_temp1, $Input2_temp2
        $Input2_temp1 = GUICtrlRead($Input2) - 4
        If $Input2_temp1 <= 0 Then $Input2_temp1 = 0
        $Input2_temp2 = GUICtrlRead($Input2) + 4
        ;MsgBox(0,"",$Input2_temp1&","&$Input2_temp2)
        _SQLite_QuerySingleRow(-1, "SELECT count(*) FROM Game_Books Where Wind_Direction = 'Left_Headwind' And Wind_Speed = '" & GUICtrlRead($Input1)& _
                                "' And Distance >= '" & $Input2_temp1 & "' And Distance <= '" & $Input2_temp2 & "';",$aRow)
        Local $ArrayData[Int($aRow[0])][4]
    ;_ArrayDisplay($list_view)
        _SQLite_Query(-1, "SELECT * FROM Game_Books Where Wind_Direction = 'Left_Headwind' And Wind_Speed = '" & GUICtrlRead($Input1)& _
                                "' And Distance >= '" & $Input2_temp1 & "' And Distance <= '" & $Input2_temp2 & "';",$hQuery)
        Local $c = 0
        While _SQLite_FetchData($hQuery, $aRow) = $SQLITE_OK
                Local $i = 0
                $aRow[0] = "左逆风"
                For  $i = 0 to 3 Step 1
                        $ArrayData[$c][$i] = $aRow[$i]
                Next
                $c = $c +1
        WEnd
        _GUICtrlListView_AddArray($GUI_ListBox, $ArrayData)
        Local $sText, $aItem
        $sText = _GUICtrlListView_GetItemCount($GUI_ListBox) ;统计显示至ListView笔数
        For $i = 0 To ($sText - 1) Step 1 ;循环处理
                $aItem = _GUICtrlListView_GetItemTextArray($GUI_ListBox, $i) ;取得每行资料
                ;MsgBox(0,"", $aItem[2] & "," & $aItem[3])
                ;MsgBox(0,"", GUICtrlRead($Input1) & "," & GUICtrlRead($Input2))
                If Number($aItem[2]) = GUICtrlRead($Input1) And Number($aItem[3]) = GUICtrlRead($Input2) Then
                        _GUICtrlListView_SetItemChecked($GUI_ListBox, $i)
                EndIf
        Next
EndFunc
改用listview 方式,就幫到這了..有些只要調整一下就符合您的需求了。

本帖子中包含更多资源

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

×
 楼主| 发表于 2019-10-21 19:35:51 | 显示全部楼层
yohoboy 发表于 2019-10-20 22:57
選項/ user Options 開啟後輸入 code.page=65001  output.code.page=65001 , 很多繁體字,所以會有亂碼, ...

不知道为什么,总是无法运行,提示26行变量未声明。我也按照你说的,在用户选项里设置了。
发表于 2019-10-21 23:50:47 | 显示全部楼层
本帖最后由 yohoboy 于 2019-10-22 00:23 编辑
smooth 发表于 2019-10-21 19:35
不知道为什么,总是无法运行,提示26行变量未声明。我也按照你说的,在用户选项里设置了。

那附件的程序 開起來ok麻?   game.exe ????
另 f5 狀態下,scit 的狀態欄位有甚麼錯誤訊息?
或是把 25到28行 註解掉看看


 楼主| 发表于 2019-10-22 07:57:35 | 显示全部楼层
yohoboy 发表于 2019-10-21 23:50
那附件的程序 開起來ok麻?   game.exe ????
另 f5 狀態下,scit 的狀態欄位有甚麼錯誤訊息?
或是把 25 ...

AU3还是运行不了,我是运行EXE文件的,基本的功能有了,有几个问题:
1、清除数据,数据显示区数据没被清除;
2、当输入的数据检索不到时,把数据修改掉,就不会自动去检索数据了;
3、先输入屏距,再输入风力,就不会自动检索。
发表于 2019-10-22 12:28:21 | 显示全部楼层
smooth 发表于 2019-10-22 07:57
AU3还是运行不了,我是运行EXE文件的,基本的功能有了,有几个问题:
1、清除数据,数据显示区数据没被 ...

系统是64位???
 楼主| 发表于 2019-10-23 08:59:47 | 显示全部楼层
chzj589 发表于 2019-10-22 12:28
系统是64位???

是的,我系统是64位的,都好多年没用32位系统了。
发表于 2019-10-23 13:21:55 | 显示全部楼层
smooth 发表于 2019-10-23 08:59
是的,我系统是64位的,都好多年没用32位系统了。

同目录要有:sqlite3_x64.dll
您需要登录后才可以回帖 登录 | 加入

本版积分规则

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

GMT+8, 2024-4-20 18:01 , Processed in 0.088170 second(s), 20 queries .

Powered by Discuz! X3.5 Licensed

© 2001-2024 Discuz! Team.

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