code works here, but not there

Started by perry59, October 09, 2019, 01:38:02 AM

Previous topic - Next topic

0 Members and 1 Guest are viewing this topic.

perry59

Working on some layer management stuff. I have two areas in my code where I am putting RGB values into the layers table color cell.
The first area is an update, where the user selects a color from a combo box to change the currently selected layers color. This code is working fine and puts an unquoted RGB value into the cell. "Viscolor" is defined as a string.

RGBcolor = row.Cells(8).Style.BackColor 'get background color of selected row's color cell in the datagridview
visColor = "RGB(" & RGBcolor.R.ToString & "," & RGBcolor.G.ToString & "," & RGBcolor.B.ToString & ")"  'convert it to a string
visLayer.CellsC(Visio.VisCellIndices.visLayerColor).Formula = "" & visColor & "" 'and put it in the layer tables color cell

The other area is where a new layer is added to the document. The code is identical to the above (with a few futile attempts to get it working commented out), but is not working. "Layerobject" is a custom class and returns a string identical to "viscolor" shown above. Initially it returned the string with the extra quotes but that failed and I started manually fiddeling with the return value trying to get it to work>

'visLayer.CellsC(Visio.VisCellIndices.visLayerColor).Formula = layerobject.colorstr  'error #NAME
visLayer.CellsC(Visio.VisCellIndices.visLayerColor).Formula = "" & layerobject.colorstr & "" 'error #NAME but the string is identical to the  update function!
'visLayer.CellsC(Visio.VisCellIndices.visLayerColor).Formula = """ & layerobject.colorstr & """ 'no error but puts this in cell =" & layerobject.colorstr & "
'visLayer.CellsC(Visio.VisCellIndices.visLayerColor).Formula = """" & layerobject.colorstr & """" 'no error buts puts this in cell ="RGB=(0,255,0)", should not be quoted


Why is it that a line of code will work fine in one area of the program, but fail somewhere else?
How do I force a string into a cell sans quotes?
On a side note, I've also seen some nameless layers which I can't remove via the shapesheet.
Thanks for any help!

wapperdude

Not enought code to tell what you're doing.  Cannot tell what how you're identifying the layer you're working with.  The name error is probably you haven't assigned an existing layer.  The syntax of your code looks wrong.  See sample below

Here's simple code snippet:

Sub Macro2()
    Dim vsoLayer1 As Visio.Layer
    Dim layClr As String

    Set vsoLayer1 = ActiveWindow.Page.Layers.Item(1)
'    vsoLayer1.CellsC(visLayerColor).FormulaU = "RGB(255,255,0)"   'direct
   
    layClr = "RGB(125,0,255)"
    vsoLayer1.CellsC(visLayerColor).FormulaU = layClr  'using string variable
End Sub


Visio 2019 Pro

perry59

Well, I found the issue.
The sub that worked was returning the string "RGB(255,0,0)"
The "bad" sub was returning "RGB= (255,0,0)", an obvious difference. Fixed the errant code and all is well.
BTW, I see nothing wrong with my syntax, this is vb.net, not vba. Indeed microsoft's own examples shows this same syntax.