zhx40672203 zhx40672203
关注数: 33 粉丝数: 42 发帖数: 1,638 关注贴吧数: 51
随机数的问题,应该编的没问题,可会陷入死循环? Private Sub Command1_Click() Call GetExcel Set xlapp = GetObject(App.Path & "\data.xls") Randomize Dim j, cf, hh, t As Integer Dim Sm() As Integer hh = 0 Open App.Path & "\题目.TXT" For Output As #1 Open App.Path & "\答案.TXT" For Output As #2 For t = 1 To 16 If Text1(t - 1) <> 0 Then If Text1(t - 1).Enabled = True Then If IsNumeric(Text1(t)) = True Then ReDim Sm(1 To xlapp.Worksheets(t).UsedRange.Rows.Count) As Integer For i = 1 To xlapp.Worksheets(t).UsedRange.Rows.Count Sm(i) = 0 Next i For j = 1 To Text1(t - 1) begin: cf = Int(Rnd() * (xlapp.Worksheets(t).UsedRange.Rows.Count - 1) + 2) If Sm(cf) <> 1 Then Sm(cf) = 1 Else GoTo begin: End If If Not xlapp.Worksheets(t).Cells(cf + 1, 1) = "" Then Print #1, xlapp.Worksheets(t).Cells(cf + 1, 1) Print #1, xlapp.Worksheets(t).Cells(cf + 1, 2) Print #1, xlapp.Worksheets(t).Cells(cf + 1, 3) If Not xlapp.Worksheets(t).Cells(cf + 1, 4) = "" Then Print #1, xlapp.Worksheets(t).Cells(cf + 1, 4) Print #1, xlapp.Worksheets(t).Cells(cf + 1, 5) End If End If Print #1, If Not xlapp.Worksheets(t).Cells(cf + 1, 6) = "" Then hh = hh + 1 Print #2, " " & xlapp.Worksheets(t).Cells(cf + 1, 6); If hh Mod 5 = 0 Then Print #2, End If End If Next j End If End If End If Next t Close #1 Close #2 Call MsgBox("出题完成!", , "提示") End Sub我随机数的目的是想生成2-XXX范围内的数,可当我输入需要生成的随机数个数为XXX的时候就会一直无限的循环下去,输入XXX-1都不会,顶多几秒种就会得出结果
1 下一页