程序预期的运行效果是在窗体被打开后,(rec-2)个label控件会按照计算好的位置依次排列,每个label控件会显示程序外接文档里一行的内容。
外接文档第一行和第二行都是整数数字。
但是在这个窗体打开后,lblname(n)并没有被创建。
而rec的值大于3,row 与list的值均不为0,控件text1内每行的内容确实为r(rec)的内容。
也就是说,for内的语句没有被执行。
代码如下:
Dim r(100) As String
Dim rec As Integer
Private Sub Form_Load()
Open ("result.txt") For Input As #3
rec = 0
Do Until EOF(3)
Line Input #3, r(rec)
Text1.Text = Text1.Text & vbCrLf & r(rec)
rec = rec + 1
Loop
row = Val(r(0))
list = Val(r(1))
lblrow.Caption = row
lbllist.Caption = list
lblcount.Caption = rec - 2
lbln = Label1.Width / list
lblt = (Label7.Top - Label2.Top - Label2.Height) / row
lblh = lblstand.Height
lblw = lblstand.Width
For i = 2 To n = rec - 1
n = i - 1
Load lblread(n)
X = Int(n / row) + 1
y = n Mod row
If n Mod row = 0 Then
X = X - 1
y = row
End If
If X Mod 2 = 0 Then y = row - y + 1
lblread(n).Height = lblh
lblread(n).Width = lblw
lblread(n).Caption = r(i)
lblread(n).Top = Label1.Top + y * lblt
lblread(n).Left = Label1.Left + Label1.Width - (X - 1) * lbln - lblstand.Width
lblread(n).Visible = True
Next i
End Sub