Reputation: 61
I have recently started using vb.net for programming. I am trying to get the X-Y coordinates of all the shapes in visio into a csv file. I found a VBA code by Russell Christopher in which the code does exactly what I need, but it is in VBA. I tried rewriting the code in VB.net but as I am new, I do not know all of the syntax. Can anyone here please help me on that. Here is the code that I need to convert.
Public Sub WriteTableauPointsFile()
Dim oShape As Visio.Shape
Dim oPath As Visio.Path
Dim oPoints() As Double
'Set the output file to be the same as the source file, but .CSV
oFileName = Left(ActiveDocument.FullName, Len(ActiveDocument.FullName) - 3) & "csv"
'Set the separator character
oSeparator = "|"
'If file already exists, delete it
If Dir(oFileName) <> "" Then
Kill oFileName
End If
'Open the output file and write the header line
oFile = FreeFile
Open oFileName For Append As #oFile
Print #oFile, "ShapeNo" & oSeparator & "ShapeName" & oSeparator & "PathNo" & oSeparator & "PointNo" & oSeparator & "X" & oSeparator & "Y"
'Get all the shapes on the page
ActiveWindow.SelectAll
Set oShapes = ActiveWindow.Selection
'Cycle through the shapes
For Each oShape In oShapes
'Shapes can have multiple paths
For j = 1 To oShape.Paths.Count
Set oPath = oShape.Paths(j)
'Enumerate the points in each path with 0.5 sensitivity for curves
oPath.Points 0.5, oPoints
i = 0
Do While i < UBound(oPoints)
x = Int(oPoints(i))
y = Int(oPoints(i + 1))
i = i + 2
'Write the record for each point
Print #oFile, oShape.Index; oSeparator; oShape.Text; oSeparator; j; oSeparator; i; oSeparator; x; oSeparator; y
Loop
Next j
Next
'Close the file and exit
Close #oFile
End Sub
Based on trial and error I understood that there is no such thing as "open" in vb.net. I was able to successfully convert until the "open" statement starts.
Any help will be really appreciated.
Thanks, - Miki
Upvotes: 0
Views: 1671
Reputation: 61
I figured out the answer myself. Thought I would post it here so that it might be helpful someone looking for similar thing in future.
Dim oPoints() as Double
oPath.Points(0.5, oPoints)
i = 0
Do While i < UBound(oPoints)
x = Int(oPoints(i))
y = Int(oPoints(i + 1))
i = i + 2
Remaining portion of the code remains the same.
Upvotes: 1