|
只需模块2
加了注释。自定义函数会用即可
- Sub aa()
- Dim n As Long, h As Long
- Application.ScreenUpdating = False
- [a2:k20].ClearContents '清除
- n = 20 '最大数 取数范围
- h = 19 '题行数
- For ci = 0 To 1 '2栏循环
- arr = ArrRnd20(n, h, , 1) '抽取第1数
- crr = ArrRnd20(n, h, , 1) '抽取第2数
- brr = ArrRnd20(4, h, , 1) '抽取运算符
- fu = "+-×÷"
- ReDim scrr(1 To h, 1 To 4)
- For i = 1 To h
- If brr(i) = 2 And arr(i) < crr(i) Then '交换1、2数
- scrr(i, 3) = arr(i)
- scrr(i, 1) = crr(i)
- Else
- scrr(i, 1) = arr(i)
- scrr(i, 3) = crr(i)
- End If
- scrr(i, 2) = Mid(fu, brr(i), 1)
- scrr(i, 4) = "="
- Next
- Range("a2").Resize(h, 4).Offset(0, ci * 6) = scrr '输出
- Next ci
- Application.ScreenUpdating = True
- End Sub
- '2
- '**********Copyright@Yjh_27*****2020.3.19***********************
- '功能: 从n个中随机取可重复m个,以一维数组返回
- '函数名: ArrRnd20
- '
- '参数1:n 元素数
- '参数2:m 抽取数量
- '参数3:n0 元素起始数(最小数)
- '参数4:m0 输出数组下标、元素数组下标
- '
- '返回值: 一维数组
- '使用方法:kclmr = ArrRnd20(5,2)
- '
- Function ArrRnd20(n As Long, m As Long, Optional n0 = 1, Optional m0 = 0)
- 'If n0 <> 0 Then n0 = 1
- n1 = n + n0 - 1
- m1 = m + m0 - 1
- ReDim brr(m0 To m1)
- Randomize
- For i = m0 To m1
- j = Int(Rnd * (n1 - n0 + 1)) + n0
- brr(i) = j
- Next
- ArrRnd20 = brr
- End Function
复制代码 |
|