dunphy
发表于 2014-11-27 19:43:46
本帖最后由 dunphy 于 2014-11-27 23:22 编辑
回复 27# abcd1234
看下,你的这个是不是已经解决了。解决了,请改标题为已解决。
这28楼是手动写入数组,然后再判断。
还有一贴是根据这贴研究了一下,直接打开配置文件去判断
贴子见:
http://www.autoitx.com/thread-46140-1-1.html
#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, $P = 1
For $i = 1 To UBound($a_bbval) - 1
$a_bbval[$i] = $P
$P += 1
Next
#Region
Global $gu_PzForm = GUICreate("gc_formName", 403, 289, 340, 128)
Global $gu_PzGroup1 = GUICtrlCreateGroup(" 设置随机数", 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("设置配置文件", 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(" 设置匹配值", 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
Global $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
_readSecName()
_Exists()
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, $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 _readSecName()
If GUICtrlRead($gu_PzInput1) = "" Then
MsgBox(16, "提示", "请先设置随机数再判断")
Else
Local $sSection = IniReadSectionNames(GUICtrlRead($gu_PzInput2))
If @error Then
MsgBox(16, "提示", "先配置文件地址再判断")
Else
Local $a_SecName[$sSection + 1]
For $i = 1 To UBound($a_SecName) - 1
Local $pz_array = IniReadSection($path, $sSection[$i])
$a_SecName = "字段名"
$a_SecName = "第一关键字"
$a_SecName = "第一关键字的值"
$a_SecName = "第二关键字"
$a_SecName = "第二关键字的值"
$a_SecName[$i] = $sSection[$i]
$a_SecName[$i] = $pz_array
$a_SecName[$i] = $pz_array
$a_SecName[$i] = $pz_array
$a_SecName[$i] = $pz_array
Next
EndIf
EndIf
;;_ArrayDisplay($a_SecName, "$a_SecName")
Return $a_SecName
EndFunc ;==>_readSecName
Func _Exists()
Local $SearchVal = GUICtrlRead($gu_PzInput3)
If $SearchVal = "" Then
MsgBox(16, "提示", "请输入查寻值", 1)
ElseIf StringIsInt($SearchVal) = "" Then
MsgBox(16, "提示", "你输入查寻值为" & $SearchVal & @CRLF & "你输入的值不为数字请重新输入")
Else
Local $i
For $i = 1 To UBound($a_bbval) - 1
Local $a_SecName = _readSecName()
Local $iIndex = _ArrayFindAll($a_SecName, $a_bbval[$i], Default, Default, Default, Default, 4)
TrayTip("现在有" & UBound($iIndex) & "个BB=" & $a_bbval[$i] & @CRLF & ",你的匹配值为" & $SearchVal, "提示", 1)
If UBound($iIndex) < $SearchVal Then ; 小于所设的匹配值则写入一个BB=1
Local $p
Local $n=$SearchVal-UBound($iIndex)
For $p=1 To $n
Local $j = Random(100, GUICtrlRead($gu_PzInput1), 1)
Local $k = Random(100, GUICtrlRead($gu_PzInput1), 1)
IniWrite(GUICtrlRead($gu_PzInput2), $a_Numbers[$j], $a_PznameA, $a_Numbers[$k])
IniWrite(GUICtrlRead($gu_PzInput2), $a_Numbers[$j], $a_PznameB, $a_bbval[$i])
Next
EndIf
_ArrayDisplay($a_SecName, "$a_SecName")
Next
EndIf
EndFunc ;==>_Exists
Func HotKeyPressed()
Switch @HotKeyPressed ; 最后按下的热键.
Case "{ESC}" ; {ESC} 是"退出"热键.
Exit
EndSwitch
EndFunc ;==>HotKeyPressed