|
Option Explicit
Sub test()
Dim ar, iRnd, i&, j&, k&, m&, n&, iNum&, vTemp
ReDim ar(1 To 30, 1 To 4)
ReDim iRnd(1 To 3)
Randomize
For i = 1 To UBound(ar)
For j = 1 To UBound(ar, 2)
Do
n = Int(2 * Rnd)
iRnd(2) = Switch(n = 0, "-", n = 1, "+")
If iRnd(2) = "-" Then
iRnd(1) = Int(91 * Rnd + 10)
iRnd(3) = Int(100 * Rnd)
Else
iRnd(1) = Int(100 * Rnd)
iRnd(3) = Int(100 * Rnd)
End If
If iRnd(2) = "-" Then
If iRnd(1) < iRnd(3) Then vTemp = iRnd(1): iRnd(1) = iRnd(3): iRnd(3) = vTemp
m = Val(Right(iRnd(1), 1)) - Val(Right(iRnd(3), 1))
Else
m = Val(Right(iRnd(1), 1)) + Val(Right(iRnd(3), 1))
End If
iNum = IIf(iRnd(2) = "-", iRnd(1) - iRnd(3), iRnd(1) + iRnd(3))
Loop Until (m < 0 Or m > 10) And iNum <= 100
ar(i, j) = Join(iRnd, "") & "="
Next j
Next i
With ActiveDocument
.Range(0).Delete
With .Tables.Add(Range:=Selection.Range, NumRows:=30, NumColumns:=4, DefaultTableBehavior:=wdWord9TableBehavior)
.Range.ParagraphFormat.Alignment = wdAlignParagraphCenter
.Range.Cells.VerticalAlignment = wdCellAlignVerticalCenter
For i = 1 To UBound(ar)
For j = 1 To UBound(ar, 2)
.Cell(i, j).Range.Text = ar(i, j)
Next j
Next i
End With
End With
End Sub
|
评分
-
1
查看全部评分
-
|