Showing results 1 to 6 of 6

Thread: Select trend profile from VBA

  1. #1
    Join Date
    26.10.2009
    Posts
    20

    Frage Select trend profile from VBA

    Is it possible to select a trend profile during runtime from VBA? I have the Control element -> Profile -> Profile selection Combobox in an extended trend picture. I would like to be able to select a profile from VBA.

    I found this which works for getting the name of the currently selected profile: http://www.copadata.com/forums/showthread.php?t=216 Maybe it is possible to go the other way: set the text and fire the selection changed event?

  2. #2
    Join Date
    28.07.2008
    Posts
    64

    Default Re: Select trend profile from VBA

    Quote Originally Posted by mvj View Post
    Is it possible to select a trend profile during runtime from VBA? I have the Control element -> Profile -> Profile selection Combobox in an extended trend picture. I would like to be able to select a profile from VBA.

    I found this which works for getting the name of the currently selected profile: http://www.copadata.com/forums/showthread.php?t=216 Maybe it is possible to go the other way: set the text and fire the selection changed event?
    This it is not possible in the way you want do to. What exactly would you like do to?

    The ETM profil is just to save filter settings in the RT. Maybe you can use the RTFunction PictureSwich to set static the filter settings by using the DynProperties.

    To set the filter settings dynamically with VBA will be possible in zenon 6.50 .

  3. #3
    Join Date
    26.10.2009
    Posts
    20

    Default Re: Select trend profile from VBA

    I would like to have dynamic profiles in runtime - changeable by the user in runtime. For this the ETM profile is great.

    But the problem is that the profile only seems to be selectable from the combobox. I would like to be able to select one of these profiles from VBA.

    The following code can select a profile in the combobox

    Public Declare Function SendMessage Lib "user32" Alias "SendMessageA" (ByVal hwnd As Long, ByVal wMsg As Long, ByVal wParam As Long, lParam As Any) As Long
    
    Sub Profile_Select()
      Dim zPIC As DynPicture
      Dim ret As Long
      Dim hwnd As Long
    
      Set zPIC = zenOn.Projects.Item("DEP02").DynPictures.Item("pic_LOCALTREND")
      hwnd = zPIC.Elements.Item("Control element_1").hwnd
    
      ret = SendMessage(hwnd, &H14F, 1, 0)  ' CB_SHOWDROPDOWN, 1 to show
      ret = SendMessage(hwnd, &H14E, 3, 0)  ' CB_SETCURSEL,    3 is wanted index
      ret = SendMessage(hwnd, &H201, 0, -1) ' WM_LBUTTONDOWN
      ret = SendMessage(hwnd, &H202, 0, -1) ' WM_LBUTTONUP
      ret = SendMessage(hwnd, &H14F, 0, 0)  ' CB_SHOWDROPDOWN, 0 to hide
    End Sub
    But unfortunately it does not activate the profile.

    Besides the above a also tried something similar to this: http://www.codenewsgroups.net/group/...opic15499.aspx
    But that doesn't seem to work either I got the following code:
    Public Declare Function GetWindow Lib "user32" (ByVal hwnd As Long, ByVal wCmd As Long) As Long
    Public Declare Function GetWindowLong Lib "user32" Alias "GetWindowLongA" (ByVal hwnd As Long, ByVal nIndex As Long) As Long
    Public Const WM_COMMAND = &H111
    Const CBN_SELCHANGE = &H1
    Public Const GW_HWNDNEXT = 2
    Public Const GW_CHILD = 5
    Public Const GWL_ID = (-12)
    Public Const CB_SELECTSTRING As Long = &H14D
    
    Sub Profile_Select2()
      Dim DRHwnd As Long
      Dim PosID As Long
      Dim zPIC As DynPicture
      Dim ret As Long
      Dim hwnd As Long
    
      Set zPIC = zenOn.Projects.Item("DEP02").DynPictures.Item("pic_LOCALTREND")
      hwnd = zPIC.Elements.Item("Control element_1").hwnd
    
      ' Get the parent of the combobox, this path is found using Winspector Spy
      DRHwnd = Application.hwnd
      DRHwnd = GetWindow(DRHwnd, GW_CHILD)
      DRHwnd = GetWindow(DRHwnd, GW_CHILD)
      DRHwnd = GetWindow(DRHwnd, GW_HWNDNEXT)
      DRHwnd = GetWindow(DRHwnd, GW_HWNDNEXT)
      DRHwnd = GetWindow(DRHwnd, GW_HWNDNEXT)
      DRHwnd = GetWindow(DRHwnd, GW_CHILD)
      
      SendMessage hwnd, CB_SELECTSTRING, -1, ByVal "Temp" ' "Temp" is a profile name - this works
      PosID = GetWindowLong(hwnd, GWL_ID) ' this gives the same id as Winspector Spy
      ret = SendMessage(DRHwnd, WM_COMMAND, CBN_SELCHANGE * &H10000 Or PosID, hwnd) ' this does nothing... according to Winspector Spy the message is received by the parent
    End Sub

    Any suggestions?

  4. #4
    Join Date
    30.05.2007
    Location
    Salzburg
    Posts
    880

    Default Re: Select trend profile from VBA

    I did some test on this... unfortunately I also did not succeed.
    -> i was able to select the desired RT-profile but it was not possible to load it.

    Regards,
    Herbert

  5. #5
    Join Date
    26.10.2009
    Posts
    20

    Default Re: Select trend profile from VBA

    Are we sending the wrong message to the combobox?

    Is there any other way to achieve the same thing?

  6. #6
    Join Date
    30.05.2007
    Location
    Salzburg
    Posts
    880

    Default Re: Select trend profile from VBA

    In zenon 6.50 there exists a new function for loading (and also manage) profiles in der Runtime. Thus with function substituting via VBA you will be able to select the desired RT Profile.

    For zenon version < 6.50 i do not see a solution for the functionality you are looking for

    Regards,
    Herbert

Similar Threads

  1. Select and Select before operate
    By markclemens in forum zenon Energy Edition
    Replies: 7
    Last Post: 22nd January 2016, 11:12
  2. Online Trend
    By hermos in forum zenon Supervisor
    Replies: 1
    Last Post: 15th October 2009, 06:11
  3. Trend Graph
    By nurul in forum zenon Supervisor
    Replies: 5
    Last Post: 12th August 2009, 04:21
  4. Trend Line
    By rloureiro in forum zenon Supervisor
    Replies: 2
    Last Post: 16th December 2008, 10:52

Posting Rules

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