Consulting

Results 1 to 10 of 10

Thread: ImageControl Retrieve Values on Memory

  1. #1
    VBAX Regular
    Joined
    Feb 2016
    Posts
    74
    Location

    ImageControl Retrieve Values on Memory

    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 !

    GetPixel-StoreValueXMan1.zip


    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

  2. #2
    VBAX Sage SamT's Avatar
    Joined
    Oct 2006
    Location
    Near Columbia
    Posts
    7,814
    Location
    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"
    I expect the student to do their homework and find all the errrors I leeve in.


    Please take the time to read the Forum FAQ

  3. #3
    VBAX Regular
    Joined
    Feb 2016
    Posts
    74
    Location
    SamT,

    thank you very much!

  4. #4
    VBAX Regular
    Joined
    Feb 2016
    Posts
    74
    Location
    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

  5. #5
    Administrator
    VP-Knowledge Base
    VBAX Grand Master mdmackillop's Avatar
    Joined
    May 2004
    Location
    Scotland
    Posts
    14,489
    Location
    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?
    MVP (Excel 2008-2010)

    Post a workbook with sample data and layout if you want a quicker solution.


    To help indent your macros try Smart Indent

    Please remember to mark threads 'Solved'

  6. #6
    VBAX Regular
    Joined
    Feb 2016
    Posts
    74
    Location
    Quote Originally Posted by mdmackillop View Post
    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 ,

    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
    Last edited by xman2000; 05-20-2017 at 01:53 PM.

  7. #7
    VBAX Sage SamT's Avatar
    Joined
    Oct 2006
    Location
    Near Columbia
    Posts
    7,814
    Location
    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
    I expect the student to do their homework and find all the errrors I leeve in.


    Please take the time to read the Forum FAQ

  8. #8
    VBAX Regular
    Joined
    Feb 2016
    Posts
    74
    Location
    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.

  9. #9
    VBAX Sage SamT's Avatar
    Joined
    Oct 2006
    Location
    Near Columbia
    Posts
    7,814
    Location
    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
    I expect the student to do their homework and find all the errrors I leeve in.


    Please take the time to read the Forum FAQ

  10. #10
    VBAX Regular
    Joined
    Feb 2016
    Posts
    74
    Location
    Quote Originally Posted by SamT View Post
    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 too,
    Solved!!!

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •