Sortarius 08-23-2001, 04:29 AM just not thinking right on it. Anyway, I need to tile an image control array on a form. Should be simple, just a 10x10 grid. Heres what I have so far... Mine doesnt work, but I think its close...what am I skipping over here guys?
For s = 1 To 10
For i = 1 To 10
Load Image1(i)
Image1(i).Left = Image1(i - 1).Left + Image1(i).Width
Image1(i).Visible = True
Next
Image1(s).Top = Image1(s - 1).Top + Image1(s).Width
Next
Thanks,
Sort
quos deus vult peredere prius dementat
2 things: do you have an Image1(0)? If not, then when i = 1, Image1(i-1) will probably give you an out of range error.
Also, the line:
Image1(s).Top = Image1(s - 1).Top + Image1(s).Width
uses the width property instead of the height property.
"The face of a child can say it all, especially the mouth part of the face." - Jack Handy
BillSoo 08-23-2001, 11:36 AM You are loading the same 10 image controls 10 times over. For instance, in your code, you can't possible load image(51).
Try this:
h = image1(0).Height
w = image1(0).Width
x = ? 'left edge of array. ie. where you want image1(1).left
y = ? 'top edge of array, ie. where you want image1(1).top
ndx =1
For s = 0 To 9
For i = 0 To 9
Load Image1(ndx)
image1(ndx).Top = y + s * h
Image1(ndx).Left = x + i * w
Image1(ndx).Visible = True
ndx = ndx + 1
Next
Next
You will wind up with 101 images from 0 to 100. Presumably image1(0) will be invisible and will not be shown....
Personally though, I prefer 100 images from 0 to 99 with 0 visible. But that's just me....
"I have a plan so cunning you could put a tail on it and call it a weasel!" - Edmund Blackadder
Sortarius 08-23-2001, 11:43 AM Thanks Mill and Bill, I knew it was prob a very simple thing...hehe I do apprish again...
Sort
quos deus vult peredere prius dementat
Sortarius 08-23-2001, 12:20 PM Ok, say I have the following just like Bill suggested...
h = Image1(0).Height
w = Image1(0).Width
X = 100
Y = 100
ndx = 1
For s = 0 To 9
For i = 0 To 9
Load Image1(ndx)
Image1(ndx).Top = Y + s * h
Image1(ndx).Left = X + i * w
Image1(ndx).Visible = True
ndx = ndx + 1
Next
Next
I then added...
Private Sub Image1_Click(Index As Integer)
Text2.Text = Image1(Index).Index
Set Image1(Index).Picture = ImageList1.ListImages(2).Picture
End Sub
Because I wanted to be able to extract the value of where the place I clicked was.
Now then, since this is a 10x10 grid, is there a way to set the grid index number manually...like 1.1, 1.5, 3.9, etc? If so, then I could just use the decimal point as a seperator for a kind of a x, y coordinates.
Sort
quos deus vult peredere prius dementat
BillSoo 08-23-2001, 12:55 PM The grid index number is an integer, so that kind of scheme isn't possible. However, you can easily convert from index to rows/columns and vice versa.
If your array runs from 1 to 100 and your rows and columns run from 1 to 10, you could use:
From ndx to Row/column:
row = (ndx-1) \ 10 + 1
col = (ndx - 1) mod 10 +1
From Row/Column to ndx
ndx = (Row - 1) * 10 + col
Incidentally, this is why I prefer 0 to 99 and rows/cols 0 to 9...it simplifies the math:
row = ndx \ 10
col = ndx mod 10
ndx = row * 10 + col
"I have a plan so cunning you could put a tail on it and call it a weasel!" - Edmund Blackadder
Sortarius 08-23-2001, 01:04 PM Bill, your code just keeps on being sooooo much shorter than mine. I had just figured out a way to make coordinates...but mine is...well...a few lines longer. <g> Thank you very much though. hehe I think Ill use your version.
If (Text2.Text >= 1) And (Text2.Text <= 10) Then
Text3.Text = "1, "
ElseIf (Text2.Text >= 11) And (Text2.Text <= 20) Then
Text3.Text = "2, "
ElseIf (Text2.Text >= 21) And (Text2.Text <= 30) Then
Text3.Text = "3, "
ElseIf (Text2.Text >= 31) And (Text2.Text <= 40) Then
Text3.Text = "4, "
ElseIf (Text2.Text >= 41) And (Text2.Text <= 50) Then
Text3.Text = "5, "
ElseIf (Text2.Text >= 51) And (Text2.Text <= 60) Then
Text3.Text = "6, "
ElseIf (Text2.Text >= 61) And (Text2.Text <= 70) Then
Text3.Text = "7, "
ElseIf (Text2.Text >= 71) And (Text2.Text <= 80) Then
Text3.Text = "8, "
ElseIf (Text2.Text >= 81) And (Text2.Text <= 90) Then
Text3.Text = "9, "
ElseIf (Text2.Text >= 91) And (Text2.Text <= 100) Then
Text3.Text = "10, "
End If
If (Right(Text2.Text, 1) = 0) Then
Text3.Text = Text3.Text & "10"
Else
Text3.Text = Text3.Text & Right(Text2.Text, 1)
End If
quos deus vult peredere prius dementat
|