本帖最后由 dunphy 于 2014-11-27 19:22 编辑
abcd1234在前面发了一贴,我根据他的思路整理了一下,附件跟代码附上,如何解决以下代码的问题?
需要解决的是:
按下一次按键 判定关键字BB=1的情况,如果BB=1的数量不足设置的匹配数,则写入值BB=1直到按N次按键后达到这个匹配数; 如果BB=1的数量达到了这个比配数就接着判定BB=2的情况。。。 .一直判定到BB=N。。。
(我这里暂时设定了五种BB的情况)
aa.ini[4647]
aa=5416
bb=1
[4714]
aa=1814
bb=1
[2770]
aa=3097
bb=1
[2026]
aa=1818
bb=1
[6068]
aa=6171
bb=1
[4042]
aa=4922
bb=2
[7040]
aa=2199
bb=2
[7549]
aa=6919
bb=2
[6880]
aa=2589
bb=2
[6004]
aa=6656
bb=2
[1808]
aa=3676
bb=2
[3179]
aa=7727
bb=3
[7524]
aa=6269
bb=3
[1737]
aa=5196
bb=3
[1971]
aa=3516
bb=3
[3881]
aa=5280
bb=3
[5297]
aa=6483
bb=3
[7796]
aa=7071
bb=3
[5402]
aa=3870
bb=4
[2183]
aa=1504
bb=4
[1767]
aa=1795
bb=4
[5832]
aa=3075
bb=4
[7052]
aa=1630
bb=4
[2536]
aa=2511
bb=4
[7888]
aa=2295
bb=5
[5982]
aa=5160
bb=5
[3879]
aa=5859
bb=5
[5110]
aa=1572
bb=5
[4467]
aa=3026
bb=5
[1142]
aa=4226
bb=5
[6629]
aa=4176
bb=5
[4076]
aa=7024
bb=5
#include <ButtonConstants.au3>
#include <EditConstants.au3>
#include <GUIConstantsEx.au3>
#include <GuiIPAddress.au3>
#include <StaticConstants.au3>
#include <WindowsConstants.au3>
#include <File.au3>
#include <Array.au3>
HotKeySet("{ESC}", "HotKeyPressed")
Global Const $gc_formName = "配置文件"
Global $ini = @ScriptDir & "\*.ini"
Global $a_PznameA = "aa", $a_PznameB = "bb"
Local $a_bbval[6], $P = 1
For $i = 1 To 5
$a_bbval[$i] = $P
$P += 1
Next
#Region
Global $gu_PzForm = GUICreate("gc_formName", 403, 289, 340, 128)
Global $gu_PzGroup1 = GUICtrlCreateGroup("[1] 设置随机数", 16, 8, 377, 49)
Global $gu_PzInput1 = GUICtrlCreateInput("", 39, 23, 41, 21, $ES_READONLY)
Global $gu_PzLabel1 = GUICtrlCreateLabel("个随机数", 84, 30, 52, 17)
Global $gu_PzButton1 = GUICtrlCreateButton("设置", 304, 24, 51, 25)
GUICtrlCreateGroup("", -99, -99, 1, 1)
Global $gu_PzGroup2 = GUICtrlCreateGroup("[2]设置配置文件", 13, 62, 382, 68)
Global $gu_PzInput2 = GUICtrlCreateInput("", 33, 88, 244, 21)
GUICtrlSetData($gu_PzInput2, $ini)
Global $gu_PzButton2 = GUICtrlCreateButton("打开文件", 296, 86, 70, 25)
GUICtrlCreateGroup("", -99, -99, 1, 1)
Global $gu_PzGroup3 = GUICtrlCreateGroup("[3] 设置匹配值", 16, 136, 377, 57)
Global $gu_PzInput3 = GUICtrlCreateInput("", 36, 157, 49, 21)
GUICtrlCreateGroup("", -99, -99, 1, 1)
Global $gu_PzButton3 = GUICtrlCreateButton("关于(A)", 13, 250, 59, 25)
Global $gu_PzButton4 = GUICtrlCreateButton("判断", 264, 250, 59, 25)
Global $gu_PzButton5 = GUICtrlCreateButton("退出(X)", 328, 250, 59, 25)
GUISetState(@SW_SHOW)
#EndRegion
_Main() ;主函数开始
Exit
Func _Main()
Local $nMsg
While 1
$nMsg = GUIGetMsg()
Switch $nMsg
Case $GUI_EVENT_CLOSE
Exit
Case $gu_PzButton1
;Local $Number = Random(1, 29, 1)
GUICtrlSetData($gu_PzInput1, Random(150, 200, 1))
Local $pz_rdnum = GUICtrlRead($gu_PzInput1)
MsgBox(0, "提示", "准备输入" & $pz_rdnum & "个随机数", 1)
Case $gu_PzButton2
If GUICtrlRead($gu_PzInput1) = "" Then
MsgBox(16, "提示", "请先设置随机数")
Else
Local $path = FileOpenDialog("配置文件存储位置", _
@ScriptDir, "配置文件.ini (*.ini)|所有文件(*.*)", 1 + 8, _
"*.ini", $gu_PzForm)
If @error Then
MsgBox(16, "提示", "你未选择INI文件.")
Else
Global $a_Numbers = _RandomNumber()
; _SortArray($a_Numbers) ;从小到大排序
GUICtrlSetData($gu_PzInput2, $path)
EndIf
EndIf
Case $gu_PzButton4
If GUICtrlRead($gu_PzInput1) = "" Then
MsgBox(16, "提示", "请先设置随机数再判断")
Else
Local $sSection = IniReadSectionNames( GUICtrlRead($gu_PzInput2))
;_ArrayDisplay($sSection, "$sSection")
If @error Then
MsgBox(16, "提示", "先配置文件地址再判断")
Else
Global $a_SecName[$sSection[0] + 1][5]
For $i = 1 To UBound($a_SecName) - 1
Local $pz_array = IniReadSection($path, $sSection[$i])
$a_SecName[0][0] = "字段名"
$a_SecName[0][1] = "第一关键字"
$a_SecName[0][2] = "第一关键字的值"
$a_SecName[0][3] = "第二关键字"
$a_SecName[0][4] = "第二关键字的值"
$a_SecName[$i][0] = $sSection[$i]
$a_SecName[$i][1] = $pz_array[1][0]
$a_SecName[$i][2] = $pz_array[1][1]
$a_SecName[$i][3] = $pz_array[2][0]
$a_SecName[$i][4] = $pz_array[2][1]
Next
;; _ArrayDisplay($a_SecName, "$Array")
_Exists()
EndIf
EndIf
Case $gu_PzButton3
MsgBox(0 + 64, $gc_formName, "提示:" & @CRLF & "1.先设置随机数" _
& @CR & "2.打开文件" _
& @CR & "3.设置查寻值并判断。")
Case $gu_PzButton5
Exit
EndSwitch
WEnd
EndFunc ;==>_Main
Func _RandomNumber()
Local $a_Numbers[1], $P = 1
While $P <= GUICtrlRead($gu_PzInput1) ;随机 所设的上限值 个四位正整数
Local $Number = StringFormat("%03s", Random(1000, 8000, 1))
Local $i, $f = 1
For $i = 1 To UBound($a_Numbers, 1) - 1
If $a_Numbers[$i] = $Number Then
$f = 0
ExitLoop
EndIf
Next
If $f = 1 Then
ReDim $a_Numbers[$P + 1]
$a_Numbers[$P] = $Number
$P += 1
EndIf
WEnd
;; _ArrayDisplay( $a_Numbers," $a_Numbers")
Return $a_Numbers
EndFunc ;==>_RandomNumber
Func _Exists()
Local $SearchVal = GUICtrlRead($gu_PzInput3)
If $SearchVal = "" Then
MsgBox(16, "提示", "请输入查寻值", 1)
ElseIf StringIsInt($SearchVal) = "" Then
MsgBox(16, "提示", "你输入查寻值为" & $SearchVal & @CRLF & "你输入的值不为数字请重新输入")
Else
Local $i=1, $flag=1
Local $iIndex = _ArrayFindAll($a_SecName, $a_bbval[$i], Default, Default, Default, Default, 4)
TrayTip("现在有" & UBound($iIndex) & "个BB=" & $a_bbval[$i] & @CRLF & ",你的匹配值为" & $SearchVal, "提示",1)
Local $j = Random(100, GUICtrlRead($gu_PzInput1), 1)
Local $k = Random(100, GUICtrlRead($gu_PzInput1), 1)
If UBound($iIndex) < $SearchVal Then ;小于所设的匹配值则写入一个BB=1,否则
IniWrite("aa.ini", $a_Numbers[$j], $a_PznameA, $a_Numbers[$k])
IniWrite("aa.ini", $a_Numbers[$j], $a_PznameB, $a_bbval[$i])
Else
; MsgBox(0, "提示", "BB值的数量等于所设的匹配值",1)
$I+=1
; If UBound($iIndex) = $SearchVal Then ;等于或者大于所设的匹配值就判断BB值+1的情况
Local $iIndex = _ArrayFindAll($a_SecName, $a_bbval[$i], Default, Default, Default, Default, 4)
TrayTip("现在有" & UBound($iIndex) & "个BB=" & $a_bbval[$i] & @CRLF & ",你的匹配值为" & $SearchVal, "提示", 1)
Local $j = Random(100,GUICtrlRead($gu_PzInput1), 1)
Local $k = Random(100, GUICtrlRead($gu_PzInput1), 1)
IniWrite("aa.ini", $a_Numbers[$j], $a_PznameA, $a_Numbers[$k])
IniWrite("aa.ini", $a_Numbers[$j], $a_PznameB, $a_bbval[$i])
; EndIf
EndIf
_ArrayDisplay($a_SecName, "$Array")
EndIf
EndFunc ;==>_Exists
Func HotKeyPressed()
Switch @HotKeyPressed ; 最后按下的热键.
Case "{ESC}" ; {ESC} 是"退出"热键.
Exit
EndSwitch
EndFunc ;==>HotKeyPressed
|