Set Value via Drag&Drop (VBA)
Using an element (i.e. "Numerical value") it is possible to link VBA Drag & Drop events. Thus it is possible to drag the actual value of a value (displayed in an numerical element, switch, .. ) to a value which is displayed in another element.
Following VBA Makros are available:
DragBegin VBA macro that should be executed, when dragging begins.
DragDrop VBA macro that should be executed, when the mouse button is released.
DragOver VBA macro that should be executed, when the cursor is moved over the element, while the left button is pressed down.
Below you can find an instruction (including the VBA macros) to realize the setting of variable values via Drag&Drop (see also screen Macros_ElementProp.jpg which shows the element configuration)
VBA Code in ModuleElement
VBA Code:
Option Explicit
Dim obElem_DragBegin As Element
Dim obPicture As DynPicture
Dim obElements As Elements
Dim bDropEnabled As Boolean
'#########################################################################################################
'Start draging -> get information about the "start" element
Public Sub DragBegin_Select(obElem As Element, vPosX As Variant, vPosY As Variant)
Set obElem_DragBegin = obElem
End Sub
'#########################################################################################################
'Drop Event -> if validation is correct, then write the value to the target element
Public Sub DragDrop_Variable(obElem As Element, vPosX As Variant, vPosY As Variant)
If DragOver_SelectVar(obElem) = False Then Exit Sub
'write the value of the source variable to the target variable
obElem.ItemVariable(0).Value = obElem_DragBegin.ItemVariable(0).Value
End Sub
'#########################################################################################################
'Hover Event -> Validation if the variable (start element) can be droped to the target element
Public Function DragOver_SelectVar(obElem As Element) As Boolean
Dim bSelected As Boolean
Dim i As Integer
bSelected = True
'Enable DragDrop...
If (Not obElem_DragBegin Is Nothing) Then
'check if a variable is linked at the target element
If obElem.CountVariable = 0 Then
bSelected = False
DragOver_SelectVar = bSelected
Exit Function
'check if linked variables are of the same datatype (i.e. UINT -> UINT)
ElseIf obElem.ItemVariable(0).DataType <> obElem_DragBegin.ItemVariable(0).DataType Then
bSelected = False
End If
End If
bDropEnabled = bSelected
DragOver_SelectVar = bSelected
End Function
This is a migrated post! Originally posted on 04.12.2008 by user herberto. Please be aware that information can be outdated.