[已解决]如何取得ini的key _ MSG可取得 换成Func却一直拿到错误的数据
本帖最后由 jet7253 于 2012-9-17 22:13 编辑请问各位先进
我想让软件读取一只INI档
但是是随机读取的
$ini = 'zz.ini'
local $section
$section = inireadsection($ini, 'aa')
msgbox(0, 1, $section, 1)])
Inifile
1=aaa
2=bbb
3=ccc
我要怎么得到他读取的是那一个号码 " 1还是2还是3 "
还请多多帮忙~~感激不尽 无语....
你这样不就可以了?
$i = random(1, $section, 1)
msgbox(0, $section[$i], $section[$i]) 本帖最后由 xayle 于 2012-9-15 22:01 编辑
$ini = 'zz.ini'
local $section
$section = inireadsection($ini, 'aa')
msgbox(0, 1, $section, 1)][1])
红色改成0就是关键字
$ini = 'zz.ini'
local $section
$section = inireadsection($ini, 'aa')
$random = random(1, $section, 1)
MsgBox(0, $section[$random],$section[$random])
可以了~~感激不尽 本帖最后由 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, $section, $IniFile, $i
$IniFile = 'Letter.ini'
$section = inireadsection($IniFile, 'letter')
$i = random(1, $section, 1)
$InPut = GUICtrlCreateInput("Enter Your Answer", 100, 15, 160, 20)
$Lcbel = GUICtrlCreateLabel($section[$i], 10, 20, 80, 35)
$Btn = GUICtrlCreateButton ( "离开", 220, 180, 80, 50)
$Btn = GUICtrlCreateButton ( "执行", 1, 180, 80, 50)
GUISetState (@SW_SHOW)
ControlFocus ( $GUI, "", $Btn);将EXIT BOX 设为预设启动按钮
While 1
$NMsg = GUIGetMsg()
Switch $NMsg
Case $GUI_EVENT_CLOSE
Exit
Case $Btn
Exit
Case $Btn
GetInput()
EndSwitch
WEnd
Func GetInput()
Local $Input_Get, $section, $IniFile, $i, $IniAddress
$IniFile = 'Letter.ini'
$section = inireadsection($IniFile, 'letter')
$i = random(1, $section, 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, 1)
$Change=GUICtrlCreateLabel("",10, 20, 80, 35)
GUICtrlSetData($Change, $section[$i])
Else
MsgBox(0, '很可惜', $IniAddress)
$IniFile = 'Letter.ini'
$section = inireadsection($IniFile, 'letter')
$i = random(1, $section, 1)
$Change=GUICtrlCreateLabel("",10, 20, 80, 35)
GUICtrlSetData($Change, $section[$i])
EndIf
EndFunc
IniFile
1=红色
2=橘色
3=黄色
1=red
2=orange
3=yellow
本帖最后由 半芯竹 于 2012-9-17 21:54 编辑
#include <ButtonConstants.au3>
#include <EditConstants.au3>
#include <GUIConstantsEx.au3>
Local $InPut, $Lcbel, $Btn, $section,$i,$IniFile = 'Letter.ini'
$section = inireadsection($IniFile, 'letter')
$i = random(1, $section, 1)
$IniAddress = IniRead($IniFile, 'answer', $i, '')
$Gui = GUICreate ( "自订意英文单字", 300, 230)
$InPut = GUICtrlCreateInput("Enter Your Answer", 100, 15, 160, 20)
$Lcbel = GUICtrlCreateLabel($section[$i], 10, 20, 80, 35)
$Btn = GUICtrlCreateButton ( "离开", 220, 180, 80, 50)
$Btn = GUICtrlCreateButton ( "执行", 1, 180, 80, 50)
GUISetState (@SW_SHOW)
ControlFocus ( $GUI, "", $Btn);将EXIT BOX 设为预设启动按钮
While 1
$NMsg = GUIGetMsg()
Switch $NMsg
Case $GUI_EVENT_CLOSE
Exit
Case $Btn
Exit
Case $Btn
GetInput()
EndSwitch
WEnd
Func GetInput()
$Input_Get = GUICtrlRead($InPut)
If $Input_Get = $IniAddress Then
MsgBox(0, '恭喜', '您答对了~!')
$section = inireadsection($IniFile, 'letter')
$i = random(1, $section, 1)
$IniAddress = IniRead($IniFile, 'answer', $i, '')
GUICtrlSetData($Lcbel, $section[$i])
Else
MsgBox(0, '很可惜', $IniAddress)
$section = inireadsection($IniFile, 'letter')
$i = random(1, $section, 1)
$IniAddress = IniRead($IniFile, 'answer', $i, '')
GUICtrlSetData($Lcbel, $section[$i])
EndIf
EndFunc 好了.....我这样写是错在那边...
变量宣告错误嘛.....囧
感激不尽 ~~!
这让我很困扰 谢谢您的帮忙 回复 7# jet7253
其实最重要的错误是,当窗口一加载时,你就random了一下。。然后无论对错与否,都重新再random了下。
不要乱用啊。。 哈哈...就是我实力不足阿....
谢谢您的帮忙~~~~
页:
[1]