Where are Inserted Fields Expressions Stored?

Started by perry59, March 24, 2015, 07:57:41 PM

Previous topic - Next topic

0 Members and 1 Guest are viewing this topic.

perry59

I have been trying to get the formula that was previously stuffed into a character string with
"shape.characters.formulau"
however that is returning the string that the formula evaluates to, how do I get the actual formula?
thanks
perry

wapperdude

#1
Resultu instead of formulau.

Wapperdude
Visio 2019 Pro

perry59

#2
Quote from: wapperdude on March 24, 2015, 09:51:11 PM
Resultu instead of formulau.

Wapperdude

according to my vba, there is no "ResultU" for characters. There is a "Text" parameter but it also returns the output of the formula, not the formula itself.
perry

wapperdude

#3
Right.  Sorry. 

So, you want the literal string?  The following ought to retrieve it...
Sub ChgText()
    Dim vsoPage As Visio.Page, vsoShape As Visio.Shape
    Dim vsoCharacters1 As Visio.Characters, vsoStrng As String

    Set vsoCharacters1 = vsoShape.Characters
    vsoStrng = vsoCharacters1.Text                 

End Sub


Wapperdude
Visio 2019 Pro

perry59

#4
Sorry, but that still just gets the text.
I'm trying to get the formula, which is in a field in the characters.

here is the chunk of code I'm having trouble with:

'Add text field --------------------------------------------------------------------------------------------------------------------------
   
    Set vsoCharacters = visShape.Characters
    If vsoCharacters.IsField = True Then
        If vsoCharacters.FieldCategory = 0 Then
            'test = visShape.Characters.FieldFormulaU 'this dont work, its getting the text NOT the formula
            If vsoCharacters.FieldFormulaU <> "GUARD(User.GAWireText)" Then
                visShape.CellsSRC(visSectionObject, visRowLock, visLockTextEdit).FormulaForceU = "0"
                vsoCharacters.Begin = 0
                vsoCharacters.End = 1
                vsoCharacters.AddCustomFieldU "User.GAWireText", visFmtNumGenNoUnits
            End If
        End If
        Else
            visShape.CellsSRC(visSectionObject, visRowLock, visLockTextEdit).FormulaForceU = "0"
            vsoCharacters.Begin = 0
            vsoCharacters.End = 1
            vsoCharacters.AddCustomFieldU "User.GAWireText", visFmtNumGenNoUnits
    End If

I'm trying to test the field first to see if it needs updating, right now it ALWAYS updates because my testing of the formula is not working.
Thanks
Perry

wapperdude

#5
I'm having trouble visualizing what it is that you're trying to do.  Can you up load something?

Wapperdude
Visio 2019 Pro

perry59

#6
I don't know that would help.
that code chunk is part of a much larger project embedded in a stencil.

thanks though :)

perry

wapperdude

#7
I was thinking more of the text that you're trying to modify.
Visio 2019 Pro

perry59

#8
Well, here is a drawing with a single "wire" in it. The field is embedded in the text characters.
thanks
perry

wapperdude

#9
Ah.  So you're trying to fetch the formula in the User.GAWireText value cell?
Visio 2019 Pro

perry59

#10
I'm trying to fetch the value (formula) in the characters field. That may differ from what is in the user.GAWireText cell if I am doing and update of the wire. Its easy to get the text, I want the formula that produced the text.
fetching the value of the user.GAWireText cell is pretty trivial, it is a different cell in a different section and is set explicitly.
When playing with the shape.characters, I can only seem to get the "results" of evaluating an expression. Not the expression being evaluated.
I am at a loss as to how to make it more clear, I want the formula that produced the text, not the text itself.
Thanks
Perry

Note from Visio Guy:
ShapeSheet cells have formulas and values. They aren't the same, so saying you want a "value (formula)" makes no sense at all, and will confuse the Visio nerds on this board! :)

wapperdude

#11
I get it now.  Seeing the wire helped clarify what you were trying to do.  Your last clarification then, just brought it altogether.  That was the good news.  Bad news, at this point, I'm not sure how to grab the "formula" from the character stream.    :(
 
Visio 2019 Pro

wapperdude

#12
Perhaps this will help... In the example you provided, the "field" is User.GAWireText, which evaluates to GX..X-001.  The following code will grab the User.GAWireText.  From there, you can grab the actual formula.

Sub GetFieldVal()

    Dim vsoSting As String
    Dim vsoShape As Visio.Shape

    Set vsoShape = ActiveWindow.Selection(1)
    vsostring = vsoShape.CellsU("Fields.Value").Formula
    MsgBox vsostring

End Sub


I think this should get you moving forward.  Note, you can, obviously, use the longer form CellsSRC(....).

Wapperdude
Visio 2019 Pro

wapperdude

#13
Alternative code:

Sub GetFieldVal()

    Dim vsoString As String
    Dim vsoShape As Visio.Shape
    Dim vsoChars As Visio.Characters
   
    Set vsoShape = ActiveWindow.Selection(1)
    Set vsoChars = vsoShape.Characters
    vsoString = vsoChars.FieldFormula
    MsgBox vsoString

End Sub


Wapperdude
Visio 2019 Pro

perry59

neither of those work :-[
they both return the text which is the result of evaluating the formula.
the second version you show is exactly what is in my code right now, i.e. "vsoChars.FieldFormula"
I guess I will have to be content with forcing an update of the field, even if it has a correct formula.
Thanks
Perry