本帖最后由 dunphy 于 2014-11-27 23:16 编辑
回复 27# abcd1234
今天有空改了改,随机了100个,段名不固定了,AA的值不固定了,然后平均分配了一下,BB =1;2;3;4;5的情况各20, 你看你的例子才出来。。我先贴代码
#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
Global $path = FileSaveDialog("配置文件存储位置", _
@ScriptDir, "配置文件.ini (*.ini)|所有文件(*.*)", 1 + 8, _
"*.ini", $gu_PzForm)
If @error Then
MsgBox(16, "提示", "你未选择INI文件.")
Else
If FileExists($path) = 1 Then FileDelete($path)
Global $a_Numbers = _RandomNumber()
; _SortArray($a_Numbers) ;从小到大排序
Local $i, $j = UBound($a_Numbers) - 1, $P = 1
For $i = 1 To 8 Step 1
IniWrite($path, $a_Numbers[$i], $a_PznameA, $a_Numbers[$j])
IniWrite($path, $a_Numbers[$i], $a_PznameB, $a_bbval[1])
$j -= 1
Next
For $i = 9 To 16 Step 1
IniWrite($path, $a_Numbers[$i], $a_PznameA, $a_Numbers[$j])
IniWrite($path, $a_Numbers[$i], $a_PznameB, $a_bbval[2])
$j -= 1
Next
For $i = 17 To 24 Step 1
IniWrite($path, $a_Numbers[$i], $a_PznameA, $a_Numbers[$j])
IniWrite($path, $a_Numbers[$i], $a_PznameB, $a_bbval[3])
$j -= 1
Next
For $i = 25 To 32 Step 1
IniWrite($path, $a_Numbers[$i], $a_PznameA, $a_Numbers[$j])
IniWrite($path, $a_Numbers[$i], $a_PznameB, $a_bbval[4])
$j -= 1
Next
For $i = 33 To 40 Step 1
IniWrite($path, $a_Numbers[$i], $a_PznameA, $a_Numbers[$j])
IniWrite($path, $a_Numbers[$i], $a_PznameB, $a_bbval[5])
$j -= 1
Next
GUICtrlSetData($gu_PzInput2, $path)
MsgBox(0, "提示:", "成功写入配置文件" & @CRLF & "请在当前程序目录查看")
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[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 _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[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
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
|