【发布时间】:2015-10-13 00:21:48
【问题描述】:
我最近开始使用 vb.net 进行编程。 我正在尝试将 visio 中所有形状的 X-Y 坐标转换为 csv 文件。 我找到了 Russell Christopher 的 VBA 代码,其中的代码完全符合我的需要,但它在 VBA 中。我尝试在 VB.net 中重写代码,但由于我是新手,我不知道所有的语法。任何人都可以在这里帮助我。 这是我需要转换的代码。
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
结束子
基于反复试验,我了解到在 vb.net 中没有“开放”之类的东西。在“open”语句开始之前,我能够成功转换。
任何帮助将不胜感激。
谢谢, - 三木
【问题讨论】:
-
好的,到目前为止,我已经转换了除此之外的所有内容:
oPath.Points 0.5, oPoints i = 0 Do While i < UBound(oPoints) x = Int(oPoints(i)) y = Int(oPoints(i + 1)) i = i + 2它给出了一个错误,我无法转换它。请问这方面有什么帮助吗? -
有人可以帮忙吗?