Text3.Text = Text3.Text & B(j - 1) 越界

来源:百度知道 编辑:UC知道 时间:2024/06/05 16:35:39
Option Explicit
Dim n As Integer, i As Integer, s As Integer, A(100) As Integer, B() As String, C(100) As String

Private Sub Command1_Click()
s = 0
Dim k As Integer, Same As Boolean
Text3.Text = ""
Text1.Text = Text1.Text
Text2.Text = Text2.Text
Randomize

For i = 1 To Text1.Text
Do
Same = False
A(i) = Int(Rnd * Text2.Text)
For k = 1 To i - 1
If A(i) = A(k) Then Same = True: Exit For
Next k
Loop While Same = True

Next i

showopen.showopen
Open (showopen.FileName) For Input As #1
Dim Lines As String
Dim NextLine As String
Dim n As Integer
Dim j As Integer
Dim t As Integer

Do While Not EOF(1)
ReDim Preserve B(n)
Line Input #1, B(n)
n = n + 1
Loop

For i = 1 To Text1.Text
j = A(i)
'DoEvents '

Text3.Text = Text3.Text & B(j - 1) & vbCrLf
Next i

Close

我想原因可能是出在 Text1.Text 不是数字或为空,还有一种可能,就是数组A(i)中有一个数为0。你检查一下,下标越界时,j的值和对应的A(i)的值,以确定原因。

看到眼花都不知道你的代码到底想干什么,拜托,给点注释吧。