Author Topic: Data Shape and Text input field mutually exclusive  (Read 4237 times)

0 Members and 1 Guest are viewing this topic.

Machine

  • Jr. Member
  • **
  • Posts: 18
Re: Data Shape and Text input fields synced and interchangeable
« Reply #15 on: May 27, 2021, 07:16:30 AM »
I really hope Mods/Admin won't mind me digging out this thread...

I decided to tackle this problem again, this time with VBA, since the initial solutions is not the most elegant one.


VBA:
Code
Option Explicit
Global TheTextInEdit As Boolean
Global ShapeDataInEdit As Boolean

Public Sub TheTextChanged(shp As Visio.Shape, field As String)
    ''Prevent from running this function when the other one is in work
    If (ShapeDataInEdit) Then Exit Sub
    TheTextInEdit = True
   
    Dim sel As Selection: Set sel = ActiveWindow.Selection
   
    If sel.PrimaryItem.Characters <> sel.PrimaryItem.Cells(field).ResultStr("") Then
        sel.PrimaryItem.Cells(field).FormulaU = Chr(34) & sel.PrimaryItem.Text & Chr(34)
    End If
   
    TheTextInEdit = False
End Sub

Public Sub ShapeDataChanged(shp As Visio.Shape, field As String)
    'Prevent from running this function when the other one is in work'
    If (TheTextInEdit) Then Exit Sub
    ShapeDataInEdit = True
   
    Dim sel As Selection: Set sel = ActiveWindow.Selection
   
    If sel.PrimaryItem.Text <> sel.PrimaryItem.Cells(field).ResultStr("") Then
        sel.PrimaryItem.Text = sel.PrimaryItem.Cells(field).ResultStr("")
    End If
   
    ShapeDataInEdit = False
End Sub

If anyone have cleaner/faster solution, please write it below.