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
Resultu instead of formulau.
Wapperdude
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
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
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
I'm having trouble visualizing what it is that you're trying to do. Can you up load something?
Wapperdude
I don't know that would help.
that code chunk is part of a much larger project embedded in a stencil.
thanks though :)
perry
I was thinking more of the text that you're trying to modify.
Well, here is a drawing with a single "wire" in it. The field is embedded in the text characters.
thanks
perry
Ah. So you're trying to fetch the formula in the User.GAWireText value cell?
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! :)
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. :(
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
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
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
Either we're not on the same page, or something. I've updated your file to include the code, both versions. Select the wire shape, then run the code. You will see that it returns the formula in the character string. Then, if you want the literal formula that does the actual work, you need one more step and fetch the contents of that formula, which is this case is a User cell.
It's a two step process.
I've provided shapesheet snippets to show both the values and formulas in the relevant shapesheet sections. There is nothing else.
Hope this clarifies what's going in the shapesheet and your wire shape.
Wapperdude
Wow!
now that is weird. the little sub you provided does indeed get the string I am looking for!
but when I paste the appropriate lines into my code, it gets the evaluated string!
there is something else going on here that I am going to have to investigate, just not sure where to look.
Thanks for your patience Wapper, you were right ::)
perry
Quote from: perry59 on March 25, 2015, 07:10:59 PM
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.
I'm not quite sure what the problem is, just an observation why your code ALWAYS updates the field - it compares "GUARD(User.GAWireText)" with "User.GAWireText". They are obviously different.
If you remove "GUARD()" in the condition, or add "GUARD()" to formula then it should stop updating. Hope I understand the issue correctly.
Good catch Nikolay!
True that comparison would NEVER work. Even after fixing it though the comparison fails because the string I am getting with "vsoChars.FieldFormula" is not returning what I expect.
You saw the lengthy discussion between myself and wapperdude, I thought his code did not work until I tried it on its own and found it DID work. For some strange reason, the same lines in my code return something else.
I'll be racking my brain over this during the weekend ???
perry