How to pass objects like shape as a parameters to a function in VB6 plz explain with example.
Printable View
How to pass objects like shape as a parameters to a function in VB6 plz explain with example.
Try something like this:
Code:Option Explicit
Private Enum ShapeStyles
Rectangle = VBRUN.ShapeConstants.vbShapeRectangle
Square = VBRUN.ShapeConstants.vbShapeSquare
Oval = VBRUN.ShapeConstants.vbShapeOval
[Circle] = VBRUN.ShapeConstants.vbShapeCircle
[Rounded Rectangle] = VBRUN.ShapeConstants.vbShapeRoundedRectangle
[Rounded Square] = VBRUN.ShapeConstants.vbShapeRoundedSquare
End Enum
Private Sub Form_Load()
Shape1.Shape = ShapeStyles.[Rounded Rectangle]
End Sub
Private Sub Command1_Click()
ChangeShape Shape1, ShapeStyles.Oval
End Sub
Private Sub ChangeShape(shp As Shape, newShape As Integer)
Shape1.Shape = newShape
End Sub
Why would you define an Enum that is the same as an existing built-in Enum? And then pass such values as Integers instead of as the Enum type?
Because it is much simpler to use and much better than ordinary integer values. Does that explain?