|
楼主 |
发表于 2014-3-7 09:32:03
|
显示全部楼层
换了一个有提示的版本。以上的错误已经发现并解决。下面是解决方案和说明:
#include <Array.au3>
Local $Y, $r, $keywords[20] = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20]
$file = FileOpen("d:\test.txt", 1)
If @error Then
MsgBox(0, "", "文件不存在")
EndIf
Dim $a[1]
For $conut=1 To 30
$num = Random(8, 15, 1)
ReDim $a[$num]
;从keywords中取Num个数
Dim $key = $keywords
For $j = 1 To $num
Local $Y = Random(1, UBound($key)-1, 1)
$a[$j-1]=$key[$Y]
_ArrayDelete($key, $Y)
Next
;交替随机值
For $i = 1 To UBound($a) * 3
_ArraySwap($a[Random(0, UBound($a) - 1, 1)], $a[Random(0, UBound($a) - 1, 1)])
Next
_ArrayToClip($a, 0, $num)
$Y = StringRegExpReplace(ClipGet(), "\s", ",")
FileWrite("d:\test.txt", $Y &"A值:"&$a&"$num值:"&$num&"$a维数:"&UBound($a)&@CRLF)
Next
FileClose($file)
出现赋值错语是因为:Array variable has incorrect number of subscripts or subscript dimension range exceeded.:。翻译过来的意思是:赋值的两个数组有一个下标超出了。所以有时候运行正常有时候出错。因为有时超出有时没有超出。百度翻译后自己理解的,意思如果不对大家指正。
解决办法是:由Local $Y = Random(1, UBound($key), 1)改成Local $Y = Random(1, UBound($key)-1, 1). |
|