如何在VB.Net中使用Page.getResults用于Visio Automation

时间:2011-06-07 11:56:14

标签: vb.net vb6 visio

将我的VB代码迁移到VB.net以进行Visio Automation。我在Page.GetResults中收到错误 “指定的数组不是预期的类型”。 我猜错误是Variant但我无法解决。

感谢您的帮助

1 个答案:

答案 0 :(得分:0)

如果您浏览sourcecode of this codeplex project,您将使用Visual Studio 2010找到Page.GetResults的VB示例。它位于名为“VS2010_VB_Samples.vb”的文件中

我在下面列出了源代码。该示例旨在教授如何使用API​​。它不是

    ' CREATE REQUEST
    Dim request = {
           New With { _
            Key .ID = CShort(shape.ID16), _
            Key .Section = CShort(IVisio.VisSectionIndices.visSectionObject), _
            Key .Row = CShort(IVisio.VisRowIndices.visRowXFormOut), _
            Key .Cell = CShort(IVisio.VisCellIndices.visXFormWidth), _
            Key .UnitCode = CShort(IVisio.VisUnitCodes.visNoCast) _
           }, 
          New With { _
            Key .ID = CShort(shape.ID16), _
            Key .Section = CShort(IVisio.VisSectionIndices.visSectionObject), _
            Key .Row = CShort(IVisio.VisRowIndices.visRowXFormOut), _
            Key .Cell = CShort(IVisio.VisCellIndices.visXFormHeight), _
            Key .UnitCode = CShort(IVisio.VisUnitCodes.visNoCast) _
            }
         }

    ' MAP THE REQUEST TO THE STRUCTURES VISIO EXPECTS
    Dim SID_SRCStream = New Short(request.Length * 4 - 1) {}
    Dim unitcodes = New Object(request.Length - 1) {}
    For i As Integer = 0 To request.Length - 1
        SID_SRCStream((i * 4) + 0) = request(i).ID
        SID_SRCStream((i * 4) + 1) = request(i).Section
        SID_SRCStream((i * 4) + 2) = request(i).Row
        SID_SRCStream((i * 4) + 3) = request(i).Cell
        unitcodes(i) = request(i).UnitCode
    Next

    ' EXECUTE THE REQUEST
    Dim flags = CShort(IVisio.VisGetSetArgs.visGetFloats)
    Dim results_sa As System.Array = Nothing
    page.GetResults(SID_SRCStream, flags, unitcodes, results_sa)

    ' MAP OUTPUT BACK TO SOMETHING USEFUL 
    Dim results_doubles = New Double(results_sa.Length - 1) {}
    results_sa.CopyTo(results_doubles, 0)

    ' DISPLAY THE INFORMATION
    shape.Text = String.Format("Results={0},{1}", results_doubles(0), results_doubles(1))