当前高中学生在尝试设置这些图像框的左侧和顶部值时学习vb6并遇到此主要问题。我一直收到错误:
对象变量或未设置块变量
和debug似乎将它引向左值和顶值变量。
Option Explicit
Dim GapY As Integer
Dim GapX As Integer
Dim x As Integer
Dim y As Integer
Dim Tile() As Image
Dim NumOfTiles
Dim h, i As Integer 'Counter
Private Sub cmdRender_Click()
x = 480
y = 480
GapX = Val(InputBox("Enter How Many tile you want horizontally:"))
GapY = Val(InputBox("Enter How Many tile you want vertically"))
NumOfTiles = (GapY * GapX)
ReDim Tile(NumOfTiles)
For i = 1 To GapY
For h = 1 To GapX
Tile(h).Height = 615
Tile(h).Width = 615
Tile(h).Left = x
Tile(h).Top = y
'Tile(h).Stretch = True
x = x + 600
Next
y = y + 600
x = 480
Next
End Sub
答案 0 :(得分:2)
您尚未为图块阵列指定任何图像,即您的阵列中有NumOfTiles
个空位。
我不知道你从哪里获取图像。您可以使用new Image
创建图像,或者从文件中读取图像,或者从表单上的图像框中获取图像等。
您可能希望使用PictureBox
控件。如果您在表单上有这样的控件,则必须按类型键入数组
Dim Tile() As PictureBox
ReDim Tile(NumOfTiles) As PictureBox
然后从表单中分配它们(假设您已在表单上放置了一些):
Set Tile(1) = pictureBox1
Set Tile(2) = pictureBox2
...
或循环
For i = 1 To NumOfTiles
Set Tile(i) = Me("pictureBox" & i)
Tile(i).Left = ...
Next
或在表单上创建这样的东西(我没试过)
Set Tile(i) = Me.Controls.Add("VB.PictureBox", "pictureBox" & i)