VB: Declaring variables in For loop
I have been trying to declare variables inside a For loop for quite some time now, and I just haven't been able to find a way.
I'm attempting to create a new image (tile) for every time a certain number is encountered in a two-dimensioned array (Measuring 32x16). I may need to add in that I am using Visual Basic 6.Currently I'm using the following code:
Option Explicit
Dim wCount As Integer
Dim hCount As Integer
Dim arrT开发者_开发知识库iles(31, 15) As Integer
Private Sub Form_Load()
For wCount = 0 To 31 Step 1
For hCount = 0 To 15 Step 1
' -Declare variables
' -I.E. Dim NAME As Image
Next
Next
End Sub
However, the above code (Using Dim tile1 As Image) gives me an error whenever trying to access one of the properties of the newly added image (Such as tile1.Width).
Is there any way to declare a variable this way at run-time?
Sincerely
- BirjolaxewYou must assign a valid Image object to the Image variable before you try to access any properties of it. For example, this works fine:
For wCount = 0 To 31 Step 1
For hCount = 0 To 15 Step 1
' -Declare variables
Dim tile1 As Image
tile1 = Image.FromFile("c:/test.png")
Dim width = tile1.Width
Next
Next
精彩评论