2015-04-20 4 views
0

Я недавно начал использовать vb.net для программирования. Я пытаюсь получить координаты X-Y всех фигур в visio в файл csv. Я нашел код VBA от Russell Christopher, в котором код делает именно то, что мне нужно, но он находится в VBA. Я пробовал переписывать код на VB.net, но поскольку я новичок, я не знаю всего синтаксиса. Может кто-нибудь здесь, пожалуйста, помогите мне в этом. Вот код, который мне нужно преобразовать.Получение координат X-Y для форм visio с использованием 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 

End Sub

на основе проб и ошибок я понял, что не существует такого понятия, как «открытый» в vb.net. Я смог успешно конвертировать до тех пор, пока не начнется инструкция «open».

Любая помощь будет действительно оценена.

Спасибо, - Miki

+0

Ok до сих пор я преобразовал все, кроме этого: 'oPath.Points 0.5, oPoints я = 0 Do Хотя я

+0

Может ли кто-нибудь помочь в этом? –

ответ

1

я понял, то ответ сам. Думаю, я разместил его здесь, чтобы было полезно, если кто-то ищет подобную вещь в будущем.

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 

Оставшаяся часть кода остается неизменной.

Смежные вопросы