TA的每日心情 | 奋斗 2014-12-18 10:31 |
---|
签到天数: 1 天 连续签到: 1 天 [LV.1]测试小兵
|
我上面已经说过,你的函数RandomChar(a1,a2)返回值只是个固定的值,一个固定的值,作为参数仍是个固定的值,因此要想在每次使用时,都取不同的值,那么函数必须返回不止一个的值,下面以返回数组为例:
'思路:随即获取10组数据,并存放在数组中,然后将数组作为参数传递给函数,这样在函数体内就可以根据数组的下标,去取相应的数据
''============================================
''从上到下填入10个值,再从左2到右填入10个值
Call ReportInformation("D:\test.xls",RandomChar(65,90))
Sub ReportInformation(filename,mychar)
Set Excel = CreateObject("Excel.Application")
Excel.DisplayAlerts = False
Excel.Workbooks.Add
Set NewSheet = Excel.Sheets.Item(1)
NewSheet.Name = "Test"
For i = 1 to 10
NewSheet.Cells(i,1).value = mychar(i-1)
i = i + 1
NewSheet.Cells(1,i).value = mychar(i-1)
i = i - 1
Next
Excel.ActiveWorkbook.SaveAs filename
Excel.Workbooks.Close
Excel.Quit
Set NewSheet=Nothing
Set Excel = Nothing
End Sub
Function RandomChar(a1,a2)
Dim Charaa(10)
For j=0 to 9
Num1 = RandomNumber(a1, a2)
Num2 = RandomNumber(a1, a2)
Num3 = RandomNumber(a1, a2)
Num4 = RandomNumber(a1, a2)
Num5 = RandomNumber(a1, a2)
Num6 = RandomNumber(a1, a2)
Num7 = RandomNumber(a1, a2)
Num8 = RandomNumber(a1, a2)
Num9 = RandomNumber(a1, a2)
Num10 = RandomNumber(a1, a2)
Charaa(j) = (chr(Num1)&chr(Num2)&chr(Num3)&chr(Num4)&chr(Num5)&chr(Num6)&chr(Num7)&chr(Num8)&chr(Num9)&chr(Num10))
RandomChar=Charaa
Next
End Function
[ 本帖最后由 feiyunkai 于 2010-3-11 17:11 编辑 ] |
|