找回密码
 加入
搜索
查看: 3028|回复: 8

[AU3基础] [已解决]如何取得ini的key _ MSG可取得 换成Func却一直拿到错误的数据

  [复制链接]
发表于 2012-9-15 21:44:16 | 显示全部楼层 |阅读模式
本帖最后由 jet7253 于 2012-9-17 22:13 编辑

请问各位先进
我想让软件读取一只INI档
但是是随机读取的
$ini = 'zz.ini'
local $section
$section = inireadsection($ini, 'aa')
msgbox(0, 1, $section[random(1, $section[0][0], 1)][1])
Inifile
[aa]
1=aaa
2=bbb
3=ccc
我要怎么得到他读取的是那一个号码 " 1还是2还是3 "
还请多多帮忙~~感激不尽
发表于 2012-9-15 21:56:23 | 显示全部楼层
无语....
你这样不就可以了?
$i = random(1, $section[0][0], 1)
msgbox(0, $section[$i][0], $section[$i][1])

评分

参与人数 1金钱 +30 收起 理由
魔导 + 30 确实很幽默~~

查看全部评分

发表于 2012-9-15 21:58:35 | 显示全部楼层
本帖最后由 xayle 于 2012-9-15 22:01 编辑

$ini = 'zz.ini'
local $section
$section = inireadsection($ini, 'aa')
msgbox(0, 1, $section[random(1, $section[0][0], 1)][1])


红色改成0就是关键字
$ini = 'zz.ini'
local $section
$section = inireadsection($ini, 'aa')
$random = random(1, $section[0][0], 1)
MsgBox(0, $section[$random][0],$section[$random][1])
 楼主| 发表于 2012-9-15 23:42:40 | 显示全部楼层
可以了~~感激不尽
 楼主| 发表于 2012-9-17 19:46:25 | 显示全部楼层
本帖最后由 jet7253 于 2012-9-17 21:03 编辑

小弟这边主要只是想做一个 复习单字的小工具
但题目出来后 往往答对它都会跟你说错
所以只好再次请教>.<
要怎么让显示出来的单字跟答案是一样的...
如果单纯用msg抓的到 key
但是这样写出来的确抓不到 $i 或 $section 的数据
请问这边要怎么改 才可以抓到 "Label跟答案是一样的呢~~" >.<"
#include <ButtonConstants.au3>
#include <EditConstants.au3>
#include <GUIConstantsEx.au3>
$Gui = GUICreate ( "自订意英文单字", 300, 230)
Local $InPut, $Lcbel, $Btn[2], $section, $IniFile, $i
$IniFile = 'Letter.ini'
$section = inireadsection($IniFile, 'letter')
$i = random(1, $section[0][0], 1)
$InPut = GUICtrlCreateInput("Enter Your Answer", 100, 15, 160, 20)
$Lcbel = GUICtrlCreateLabel($section[$i][1], 10, 20, 80, 35)
$Btn[0] = GUICtrlCreateButton ( "离开", 220, 180, 80, 50)
$Btn[1] = GUICtrlCreateButton ( "执行", 1, 180, 80, 50)
GUISetState (@SW_SHOW)
ControlFocus ( $GUI, "", $Btn[1]);将EXIT BOX 设为预设启动按钮

While 1
        $NMsg = GUIGetMsg()
        Switch $NMsg
                Case $GUI_EVENT_CLOSE
                        Exit
                Case $Btn[0]
                        Exit
                Case $Btn[1]
                        GetInput()
                EndSwitch
        WEnd

Func GetInput()
        Local $Input_Get, $section, $IniFile, $i, $IniAddress
        $IniFile = 'Letter.ini'
        $section = inireadsection($IniFile, 'letter')
        $i = random(1, $section[0][0], 1)
        $IniAddress = IniRead($IniFile, 'answer', $i, '找不到相关答案,请检查INI档案')
        $Input_Get = GUICtrlRead($InPut)
        If $Input_Get = $IniAddress Then
                MsgBox(0, '恭喜', '您答对了~!')
                $IniFile = 'Letter.ini'
                $section = inireadsection($IniFile, 'letter')
                $i = random(1, $section[0][0], 1)
                $Change=GUICtrlCreateLabel("",10, 20, 80, 35)
                GUICtrlSetData($Change, $section[$i][1])
        Else
                MsgBox(0, '很可惜', $IniAddress)
                $IniFile = 'Letter.ini'
                $section = inireadsection($IniFile, 'letter')
                $i = random(1, $section[0][0], 1)
                $Change=GUICtrlCreateLabel("",10, 20, 80, 35)
                GUICtrlSetData($Change, $section[$i][1])
        EndIf
EndFunc
IniFile
[Letter]
1=红色
2=橘色
3=黄色
[answer]
1=red
2=orange
3=yellow
发表于 2012-9-17 21:40:14 | 显示全部楼层
本帖最后由 半芯竹 于 2012-9-17 21:54 编辑

#include <ButtonConstants.au3>
#include <EditConstants.au3>
#include <GUIConstantsEx.au3>

Local $InPut, $Lcbel, $Btn[2], $section,  $i,$IniFile = 'Letter.ini'
 $section = inireadsection($IniFile, 'letter')
 $i = random(1, $section[0][0], 1)
 $IniAddress = IniRead($IniFile, 'answer', $i, '')
 $Gui = GUICreate ( "自订意英文单字", 300, 230)
$InPut = GUICtrlCreateInput("Enter Your Answer", 100, 15, 160, 20)
$Lcbel = GUICtrlCreateLabel($section[$i][1], 10, 20, 80, 35)
$Btn[0] = GUICtrlCreateButton ( "离开", 220, 180, 80, 50)
$Btn[1] = GUICtrlCreateButton ( "执行", 1, 180, 80, 50)
GUISetState (@SW_SHOW)
ControlFocus ( $GUI, "", $Btn[1]);将EXIT BOX 设为预设启动按钮
While 1
        $NMsg = GUIGetMsg()
        Switch $NMsg
                Case $GUI_EVENT_CLOSE
                        Exit
                Case $Btn[0]
                        Exit
                Case $Btn[1]
                        GetInput()
                EndSwitch
        WEnd
Func GetInput()
      $Input_Get = GUICtrlRead($InPut)
        If $Input_Get = $IniAddress Then
                MsgBox(0, '恭喜', '您答对了~!')
                $section = inireadsection($IniFile, 'letter')
        $i = random(1, $section[0][0], 1)
        $IniAddress = IniRead($IniFile, 'answer', $i, '')
                GUICtrlSetData($Lcbel, $section[$i][1])
                         
        Else
                MsgBox(0, '很可惜', $IniAddress)
                $section = inireadsection($IniFile, 'letter')
        $i = random(1, $section[0][0], 1)
        $IniAddress = IniRead($IniFile, 'answer', $i, '')
                GUICtrlSetData($Lcbel, $section[$i][1])
        EndIf
EndFunc
 楼主| 发表于 2012-9-17 22:11:03 | 显示全部楼层
好了.....我这样写是错在那边...
变量宣告错误嘛.....囧
感激不尽 ~~!
这让我很困扰 谢谢您的帮忙
发表于 2012-9-17 22:31:39 | 显示全部楼层
回复 7# jet7253


    其实最重要的错误是,当窗口一加载时,你就random了一下。。然后无论对错与否,都重新再random了下。
不要乱用啊。。
 楼主| 发表于 2012-9-17 22:48:30 | 显示全部楼层
哈哈...就是我实力不足阿....
谢谢您的帮忙~~~~
您需要登录后才可以回帖 登录 | 加入

本版积分规则

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

GMT+8, 2024-9-29 23:38 , Processed in 0.139986 second(s), 23 queries .

Powered by Discuz! X3.5 Licensed

© 2001-2024 Discuz! Team.

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