Assign an object reference to a variable [Solved] 追蹤

0
Avatar
Matt Baker

Is it possible to assign an object reference to a variable to save typing the Format.Objects("Name here") each time?

Similar to the following:

Dim graphicItems(3)
graphicItems(0) = Format.Objects("Graphic 1")
graphicItems(1) = Format.Objects("Graphic 2")
graphicItems(2) = Format.Objects("Graphic 3")
graphicItems(3) = Format.Objects("Graphic 4")

For Each item In graphicItems
    item.Width = 3.5
    item.Height = 3.5
    item.X = 0.0
Next

 

Or:

Function graphicItem (graphic)
    Select Case graphic
    Case 1
        graphicItem = Format.Objects("Graphic 1")
    Case 2
        graphicItem = Format.Objects("Graphic 2")
    Case 3
        graphicItem = Format.Objects("Graphic 3")
    End Select
End Function

When I try to assign an object to a variable (assuming its a reference in VB), it returns Error 6900: Operation not supported for this object type.

1 意見

0
Avatar
Matt Baker
評論操作 永久連結

Solved using the Set keyword

Dim graphicItems(3)
Set graphicItems(0) = Format.Objects("Graphic 1")
Set graphicItems(1) = Format.Objects("Graphic 2")
Set graphicItems(2) = Format.Objects("Graphic 3")
Set graphicItems(3) = Format.Objects("Graphic 4")

For Each item In graphicItems
    item.Width = 3.5
    item.Height = 3.5
    item.X = 0.0
Next

登入寫評論。