Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations TouchToneTommy on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Index to image array

Status
Not open for further replies.

philipad

Technical User
Feb 12, 2006
23
CY
Hi

I am using an array of images and I want each image to have an index number or any other way to find it and use it.To make it more clear:

Image(i).left=500
Image(i).top=600

Like I can find that image searching which image has top position 600, is there another way to assign a number, like the top and left position, so I can find it?
 
If it is a control array then it already has an index number. It's the Index Property, in the example above it's the value of 'i'

If I have misunderstood what you need then please clarify

________________________________________________________________
If you want to get the best response to a question, please check out FAQ222-2244 first.
'If we're supposed to work in Hex, why have we only got A fingers?'
Drive a Steam Roller
 
Thanks for the reply. Sorry I didn't make it clear. Yes I have the index i but I want another index that is specified by another loop of function.

The image can be two dimensional array but I don't know how to create it and declare it.

Or I can have the image(i) been equal to a value so I can find it later by checking if the image(i) is equal to this value.

 
Sorry I'm having a dim day! I'm only aware of one-dimensional arrays for controls. You can access any of the controls in a control array by specifying an index value.

If you mean a grid layout when you say 2 dimensional then the images will still be referenced by their Index property. If you have an array of 12 images called image(0) to image1(11) arranged as 3 rows of 4 you can still reference the last one as Image1(11)

Each will have it's own events and the Index is referenced in the event:
Code:
Private Sub Image1_Click(Index As Integer)
MsgBox Index
End Sub

If I still haven't got it, can you give more detail about exactly what you want to do and I'll try again

________________________________________________________________
If you want to get the best response to a question, please check out FAQ222-2244 first.
'If we're supposed to work in Hex, why have we only got A fingers?'
Drive a Steam Roller
 

Is "Image" the name of an ARRAY variable, or the name of an Image Control?

I mean, are you doing something like this?:

Dim Image(100) as Variant ' or As Image

Set Image(0)=myFirstImageContol

Set Image(1)=mySecondImageContol

Image(0).Left = 500

 
Image control. It has the index (i) but it is difficult to use this index for my purpose, so I want it to have another index:

Image5(i,j)

i and j are each specified by different loops or functions.

Is it possible to do that?
how?
 
To ask my question again, is this then a rectangular grid of image controls? If so you can derive the x and y coords using integer division and modulo arithmetic.

Assuming an Image control array Image1(0) to Image1(11) arranged as 4 rows of 3:

myRow = i \ 3 ' first row is row 0
myCol = i Mod 3 ' first col is 0

________________________________________________________________
If you want to get the best response to a question, please check out FAQ222-2244 first.
'If we're supposed to work in Hex, why have we only got A fingers?'
Drive a Steam Roller
 
If i and j indexes cannot be done with logical offsets then possibly use a UDT and assign the indexes whatever you want:

Public Type typeImage
myImageIDX_i(100) As Image
myImageIDX_J(100) As Image
End Type
Dim myImages As typeImage

Loop through the images and set myImages.myImageIDX_i to the each of the images using the image's own index, and myImageIDX_J to each of the images using the j index.

Dim img As VB.Image
Dim j As Integer
j = 9
For Each img In MEZ_001.findIMAGE
j = j + 1
Set myImages.myImageIDX_i(img.Index) = img
Set myImages.myImageIDX_J(j) = img
Next img

Now you could use:
Debug.? myImages.myImageIDX_i(i).Index
Debug.? myImages.myImageIDX_i(j).Index
 
>For Each img In MEZ_001.findIMAGE
[smile]
That should read:
For Each img In YourImageControl
 
>>but it is difficult to use this index for my purpose

perhaps this question can be best answered if you give more detail as to what you want your end result to be.
 
The program functions as follows:

On Text1 I enter a number and then I press the Command1 button. The program takes the number and separate it to its digits. For example 23 will be 2 and 3. The second digit represents one of three images: Image3 for 1, Image4 for 2 and Image5 for 3. For the first digit there is a top and left position stored in two arrays. For example if the value of the second array is 2 then we have:

tabletop(2)= 600
tableleft(2)=700

This represents shows the position in which one of the image must appear. For example for 23 (2 and 3) Image5 will go to position 2 i.e. 600 from top and 700 from right.

What I want to do is by entering a number with last digit zero for example 20, all the images that appeared in position 2 (the first digit) must be deleted (not visible)....

hope that makes sense....

Anyone can help?

CODE:

Dim tableLeft(1 To 6) As Single
Dim tableTop(1 To 6) As Single
Dim b(100) As Single
Dim i As Integer
Dim j As Integer
Dim k As Integer
Dim m As Integer
Dim c As Integer


Private Sub Command1_Click()

b(m) = Text3.Text
m = m + 1

a = b(m - 1)
Text2.Text = Right(a, 1)
Text1.Text = Left(a, 1)
If Text2.Text = 1 Then
Call sub1
Else
If Text2.Text = 2 Then
Call sub2
Else
If Text2.Text = 3 Then
Call sub3
End If
End If
End If

End Sub

Private Sub Command2_Click()
c = Text4.Text
Label1.Caption = b(c - 1)
End Sub

Private Sub Form_Load()
tableLeft(1) = 1680
tableLeft(2) = 1680
tableLeft(3) = 3120
tableLeft(4) = 1320
tableLeft(5) = 2160
tableLeft(6) = 3120
tableTop(1) = 1320
tableTop(2) = 1920
tableTop(3) = 1680
tableTop(4) = 2520
tableTop(5) = 2400
tableTop(6) = 2400
i = -1
j = -1
k = -1
m = 0
c = 1

End Sub


Public Sub sub1()
i = i + 1
a = Val(Text1.Text)
Image3(i).Left = tableLeft(a)
Image3(i).Top = tableTop(a)
Image3(i).Visible = True
End Sub

Public Sub sub2()
j = j + 1
a = Val(Text1.Text)
Image4(j).Left = tableLeft(a)
Image4(j).Top = tableTop(a)
Image4(j).Visible = True
End Sub

Public Sub sub3()
k = k + 1
a = Val(Text1.Text)
Image5(k).Left = tableLeft(a)
Image5(k).Top = tableTop(a)
Image5(k).Visible = True
End Sub
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top