获取表示为字符串的 ShapeSheet 单元格的值。 此为只读属性。
语法
表达式。ResultStr (UnitsNameOrCode)
表达 一个代表 Cell 对象的变量。
参数
名称 | 必需/可选 | 数据类型 | 说明 |
---|---|---|---|
UnitsNameOrCode | 必需 | Variant | 检索值时要使用的单位。 |
返回值
String
备注
获取 ResultStr 属性与获取单元格的 Result 属性相似。 区别在于 ResultStr 属性返回字符串作为单元格的值,而 Result 属性返回浮点数。
您可以将 UnitsNameOrCode 指定为整数或字符串值。 如果该字符串无效,将生成一个错误。 例如,下列语句全部将 UnitsNameOrCode 设置为英寸。
stringReturned = Cell.ResultStr (visInches)
stringReturned = Cell.ResultStr (65)
stringReturned = Cell.ResultStr (“in”) 其中“in”也可以是表示英寸的任何备用字符串,例如“inch”、“in.”或“intCounter”。
有关有效单位字符串以及对应的自动化常量(整型值)的完整列表,请参阅关于度量单位。
用于表示单元的自动化常量由成员 VisUnitCodes 中的 Visio 类型库声明。
传递零 (0) 就可以获取文本字符串单元格的值。
使用 ResultStr 属性在单位之间转换。 例如,您可以获取一个以英寸为单位的值,然后获取一个以厘米为单位的等效值。
ResultStr 属性对于使用单元格的值填充控件(例如编辑框)很有用。
示例
以下 Microsoft Visual Basic for Applications (VBA) 宏显示了使用 ResultStr 属性获取包含形状的形状数据(以前称为自定义属性)的 ShapeSheet 单元格的值的两种不同方法。
要运行此宏,请打开一个空白绘图和“计算机和显示器(美制单位)”模具,然后插入一个包含标签、文本框和列表框的用户窗体。 将列表框的宽度设置为 150。
注意
美国单位) 模具 (计算机和监视器仅在Visio Professional中可用。
Public Sub ResultStr_Example()
Dim vsoStencil As Visio.Document
Dim vsoMaster As Visio.Master
Dim vsoPages As Visio.Pages
Dim vsoPage As Visio.Page
Dim vsoShape As Visio.Shape
Dim vsoCell As Visio.Cell
Dim intRows As Integer
Dim intCounter As Integer
'Get the Pages collection for the document.
'ThisDocument refers to the current document.
Set vsoPages = ThisDocument.Pages
'Get a reference to the first page of the Pages collection.
Set vsoPage = vsoPages(1)
'Get the Document object for the stencil.
Set vsoStencil = Documents("Comps_U.VSS")
'Get the Master object for the desktop PC shape.
Set vsoMaster = vsoStencil.Masters("PC")
'Drop the shape in the approximate middle of the page.
'Coordinates passed to the Drop method are always in inches.
'The Drop method returns a reference to the new shape object.
Set vsoShape = vsoPage.Drop(vsoMaster, 4.25, 5.5)
'This example shows two methods of extracting shape data.
'The first method retrieves the value of a shape-data item by name.
'Note that Prop.Manufacturer implies Prop.Manufacturer.Value.
Set vsoCell = vsoShape.Cells("Prop.Manufacturer")
'Get the cell value as a string
'and put it into the text box on the form.
UserForm1.TextBox1.Text = vsoCell.ResultStr(Visio.visNone)
'Set the caption of the label.
UserForm1.Label1.Caption = "Prop.Manufacturer"
'The second method of accessing shape data uses
'section, row, cell. This method is best when you want
'to iterate through all the shape data.
intRows = vsoShape.RowCount(Visio.visSectionProp)
'Make sure the list box is cleared.
UserForm1.ListBox1.Clear
'Loop through all the rows and add the value of Prop.Manufacturer
'to the list box. Rows are numbered starting with 0.
For intCounter = 0 To intRows - 1
Set vsoCell = vsoShape.CellsSRC(Visio.visSectionProp, intCounter, visCustPropsValue)
UserForm1.ListBox1.AddItem vsoCell.LocalName & vbTab & _
vsoCell.ResultStr(Visio.visNone)
Next intCounter
'Display the user form.
UserForm1.Show
End Sub
支持和反馈
有关于 Office VBA 或本文档的疑问或反馈? 请参阅 Office VBA 支持和反馈,获取有关如何接收支持和提供反馈的指南。