PDA

View Full Version : [SOLVED] ImageControl Retrieve Values on Memory



xman2000
05-19-2017, 09:44 AM
Hi Partners,

I want pass the coords X,Y mouse Pointer and color values of ImageControl to Other Procedure Not im same ImageControl.
i able to get the values, but not retrieve on memory and pass to other procedure.

thank you.

Sample File attached below !

19222





Private Sub Image1_MouseDown(ByVal Button As Integer, ByVal Shift As Integer, ByVal x As Single, ByVal y As Single)


'''======================================================
Call GetCursorPos(pLocationFrom)
'''======================================================



End Sub
Private Sub Image1_MouseUp(ByVal Button As Integer, ByVal Shift As Integer, ByVal x As Single, ByVal y As Single)

Dim lColour, LastColour As Long


Dim ImageWidth As Long
Dim ImageHeight As Long
Dim ArtWidth As Long
Dim ArtHeight As Long
Dim ExcelArt As Worksheet
Dim MinX, MaxX, MinY, MaxY As Long
Dim ScalingFactor As Integer

lDC = GetWindowDC(0)

ArtWidth = Range("Width").Value
ArtHeight = Range("Height").Value

Dim lColour1Image1 As Long
Dim PixelX1 As Long
Dim PixelY1 As Long
PixelX1 = pLocationFrom.x
PixelY1 = pLocationFrom.y
lColour1Image1 = GetPixel(lDC, PixelX1, PixelY1)

Range("K20").Value = PixelX1
Range("K21").Value = PixelY1
Range("K22").Interior.Color = lColour1Image1
Range("K23").Value = lColour1Image1


Application.ScreenUpdating = True
Application.DisplayAlerts = True


End Sub

SamT
05-19-2017, 03:40 PM
Two methods
1: Module Level Variables


Dim Var1 As String
Dim Var2 As String
Dim Var3 As String

Sub 1()
Var1 = X
Var2 = Y
Var3 = Z
End Sub

Sub 2()
Dim Result as String

Result = Var1 & var2 & Var3
End Sub

Method 2: Passing Parameters


Sub 1
Dim Var1
Dim Var2
Dim Var3

Var1 = X
Var2 = Y
Var3 = Z

Sub2 Var1, var2, var3 'Call Sub 2 and pass variables

End Sub

Sub 2(VarA as String, VarB as String, VarC as String)
Dim Result as String

Result = VarA & VarB & VarC
End Sub

In both methods, Result = "XYZ"

xman2000
05-19-2017, 07:18 PM
SamT,

thank you very much!

xman2000
05-20-2017, 12:10 PM
Hi SamT and Partners,

i stiil with same problem,I did not explain it correctly.

i need click on the ImageControl, retrieve the values of MousePointer in memory, and click on other Commandbutton and use the previous values of previous click.
i know use the values of range of cels but not know use from memory.

thanks.



'''Method 2: Passing Parameters


Sub PassaValorMacroParte1()
Dim Var1 As String
Dim Var2 As String
Dim Var3 As String

Var1 = "x"
Var2 = "y"
Var3 = "Z"

PassaValorMacroParte2 Var1, Var2, Var3 'Call Sub 2 and pass variables

End Sub
=========================================================================== ===============
Sub PassaValorMacroParte2(VarA As String, VarB As String, VarC As String)
Dim Result As String

Result = VarA & VarB & VarC

MsgBox Result

End Sub

mdmackillop
05-20-2017, 01:00 PM
Can you clarify what is your intention. Is it to make a corresponding point in another image the same colour when you click on the source image?

xman2000
05-20-2017, 01:35 PM
Can you clarify what is your intention. Is it to make a corresponding point in another image the same colour when you click on the source image?

Hi, mdmackillop (http://www.vbaexpress.com/forum/member.php?87-mdmackillop) ,

my intention is use the previous values of previous IMageControl1 in Other ImageControl2 when you click on the source image2.
i need compare the values of Colors and use the X,Y Coords too.


Like this:

Click on Image1.Picture, get the vlaues as store in memory (procedure, array etc)
Ckick o Image2.Picture an Get the values of Image2.Picture and compare (colors) with previous values of Image1.Picture (and use previous and active coords X,Y)

i not want store the values on range of cels at this time

Like Pseudocode1:
Image1_MouseUp (x,y, color) to Image2_MouseDown (x,y, color)

Like Pseudocode2:
If ColorImageControl1.PIcture = ColorImageControl2.PIcture then

SamT
05-20-2017, 04:38 PM
You want like this?

Dim Img1MouseX As Single
Dim Img1MouseY As Single
Dim Img1Color As Variant


Private Sub Image1_MouseUp(ByVal Button As Integer, ByVal Shift As Integer, ByVal X As Single, ByVal Y As Single)
Img1MouseX = X
Img1MouseY = Y
Img1Color = Image1.PixelLocation(X, Y).Color

If Image2.PixelLocation(Img1MouseX, Img1MouseY).Color = Img1Color Then
End Sub


I have no idea How To. I suspect you have to add the UserForm Top/Left, the Image1 Top/Left and img1Mouse X/Y, then access Windows Screen API to find the Pixel Color. Easier to Use Image_MouseUp to go directly to Windows API, Then add/subtract Tops/Lefts, Xs/Ys.

If you want to check if Image1.Picture and Image2.Picture are the same Picture, that is different code

xman2000
05-20-2017, 07:22 PM
Hi, SamT,

my sample file and code at my first post shows how get the pixel color and coordinates. Only click over the picture and the informations goes to range of cels.
but i need store the informations in memory after click over the picture and uses in next click over second picture to compare colors.

only need store the information on memory, other options different of copy to Clipboard ??

your last code only works to Vb.Net not VBA.
In VBA is necessary click over the picture each time to get the values of coordinates of MousePointer, this informations of MousePointer disappear after clik, not possible get the informations withous click with mousePoint over the picture, i think.

SamT
05-21-2017, 04:01 AM
but i need store the informations in memory after click over the picture and uses in next click over second picture to compare colors.See my post #2, method 1

xman2000
05-21-2017, 07:57 AM
See my post #2, method 1

Hi, SamT,
Excuse me


I forgot to test your first code because I was doing other tests and because I thought the result would be the same.


Method1 is exactly what I need, however, I will combine Method1 and Metho2 in a more complex way because I will put it in the procedure of Image1.picture and Image2.picture

I have advanced knowledge of Office Vba but I am not an expert, I have many basic knowledge gaps.

thank you SamT and mdmackillop (http://www.vbaexpress.com/forum/member.php?87-mdmackillop) too,
Solved!!!