# Typical sample
[GstarCAD 2012](../../Index.md) → [Developer Reference](../%28Developer%20Reference%29.md) → [VBA Migration Guide](%28VBA%20Migration%20Guide%29.md)
**Original codes**
> ```
> Sub AddHatch()
> ' This example creates an associative gradient hatch in model space.
>
> Dim hatchObj As AcadHatch
> Dim patternName As String
> Dim PatternType As Long
> Dim bAssociativity As Boolean
>
> ' Define the hatch
> patternName = "CYLINDER"
> PatternType = acPreDefinedGradient
> bAssociativity = True
>
> ' Create the associative Hatch object in model space
> Set hatchObj = ThisDrawing.ModelSpace.AddHatch(PatternType, patternName, bAssociativity, acGradientObject)
> Dim col1 As AcadAcCmColor, col2 As AcadAcCmColor
> Set col1 = AcadApplication.GetInterfaceObject("AutoCAD.AcCmColor.17")
> Set col2 = AcadApplication.GetInterfaceObject("AutoCAD.AcCmColor.17")
> Call col1.SetRGB(255, 0, 0)
> Call col2.SetRGB(0, 255, 0)
> hatchObj.GradientColor1 = col1
> hatchObj.GradientColor2 = col2
>
> ' Create the outer boundary for the hatch (a circle)
> Dim outerLoop(0 To 0) As AcadEntity
> Dim center(0 To 2) As Double
> Dim radius As Double
> center(0) = 3: center(1) = 3: center(2) = 0
> radius = 1
> Set outerLoop(0) = ThisDrawing.ModelSpace.AddCircle(center, radius)
>
> ' Append the outerboundary to the hatch object, and display the hatch
> hatchObj.AppendOuterLoop (outerLoop)
> hatchObj.Evaluate
> ThisDrawing.Regen True
> End Sub
> ```
Step1 : Modify class name
> ```
> Sub AddHatch()
> ' This example creates an associative gradient hatch in model space.
>
> Dim hatchObj As GcadHatch
> Dim patternName As String
> Dim PatternType As Long
> Dim bAssociativity As Boolean
>
> ' Define the hatch
> patternName = "CYLINDER"
> PatternType = acPreDefinedGradient
> bAssociativity = True
>
> ' Create the associative Hatch object in model space
> Set hatchObj = ThisDrawing.ModelSpace.AddHatch(PatternType, patternName, bAssociativity, acGradientObject)
> Dim col1 As GcadAcCmColor, col2 As GcadAcCmColor
> Set col1 = GcadApplication.GetInterfaceObject("AutoCAD.AcCmColor.17")
> Set col2 = GcadApplication.GetInterfaceObject("AutoCAD.AcCmColor.17")
> Call col1.SetRGB(255, 0, 0)
> Call col2.SetRGB(0, 255, 0)
> hatchObj.GradientColor1 = col1
> hatchObj.GradientColor2 = col2
>
> ' Create the outer boundary for the hatch (a circle)
> Dim outerLoop(0 To 0) As GcadEntity
> Dim center(0 To 2) As Double
> Dim radius As Double
> center(0) = 3: center(1) = 3: center(2) = 0
> radius = 1
> Set outerLoop(0) = ThisDrawing.ModelSpace.AddCircle(center, radius)
>
> ' Append the outerboundary to the hatch object, and display the hatch
> hatchObj.AppendOuterLoop (outerLoop)
> hatchObj.Evaluate
> ThisDrawing.Regen True
> End Sub
> ```
Step2 : Modify enumeration value
> ```
> Sub AddHatch()
> ' This example creates an associative gradient hatch in model space.
>
> Dim hatchObj As GcadHatch
> Dim patternName As String
> Dim PatternType As Long
> Dim bAssociativity As Boolean
>
> ' Define the hatch
> patternName = "CYLINDER"
> PatternType = gcPreDefinedGradient
> bAssociativity = True
>
> ' Create the associative Hatch object in model space
> Set hatchObj = ThisDrawing.ModelSpace.AddHatch(PatternType, patternName, bAssociativity, gcGradientObject)
> Dim col1 As GcadAcCmColor, col2 As GcadAcCmColor
> Set col1 = GcadApplication.GetInterfaceObject("AutoCAD.AcCmColor.17")
> Set col2 = GcadApplication.GetInterfaceObject("AutoCAD.AcCmColor.17")
> Call col1.SetRGB(255, 0, 0)
> Call col2.SetRGB(0, 255, 0)
> hatchObj.GradientColor1 = col1
> hatchObj.GradientColor2 = col2
>
> ' Create the outer boundary for the hatch (a circle)
> Dim outerLoop(0 To 0) As GcadEntity
> Dim center(0 To 2) As Double
> Dim radius As Double
> center(0) = 3: center(1) = 3: center(2) = 0
> radius = 1
> Set outerLoop(0) = ThisDrawing.ModelSpace.AddCircle(center, radius)
>
> ' Append the outerboundary to the hatch object, and display the hatch
> hatchObj.AppendOuterLoop (outerLoop)
> hatchObj.Evaluate
> ThisDrawing.Regen True
> End Sub
> ```
Step3 : Modify automation interface
> ```
> Sub AddHatch()
> ' This example creates an associative gradient hatch in model space.
>
> Dim hatchObj As GcadHatch
> Dim patternName As String
> Dim PatternType As Long
> Dim bAssociativity As Boolean
>
> ' Define the hatch
> patternName = "CYLINDER"
> PatternType = gcPreDefinedGradient
> bAssociativity = True
>
> ' Create the associative Hatch object in model space
> Set hatchObj = ThisDrawing.ModelSpace.AddHatch(PatternType, patternName, bAssociativity, gcGradientObject)
> Dim col1 As GcadAcCmColor, col2 As GcadAcCmColor
> Set col1 = GcadApplication.GetInterfaceObject("GcadVba.GcadAcCmColor.1")
> Set col2 = GcadApplication.GetInterfaceObject("GcadVba.GcadAcCmColor.1")
> Call col1.SetRGB(255, 0, 0)
> Call col2.SetRGB(0, 255, 0)
> hatchObj.GradientColor1 = col1
> hatchObj.GradientColor2 = col2
>
> ' Create the outer boundary for the hatch (a circle)
> Dim outerLoop(0 To 0) As GcadEntity
> Dim center(0 To 2) As Double
> Dim radius As Double
> center(0) = 3: center(1) = 3: center(2) = 0
> radius = 1
> Set outerLoop(0) = ThisDrawing.ModelSpace.AddCircle(center, radius)
>
> ' Append the outerboundary to the hatch object, and display the hatch
> hatchObj.AppendOuterLoop (outerLoop)
> hatchObj.Evaluate
> ThisDrawing.Regen True
> End Sub
> ```
> ---
>
> **Note**:
> The codes to be migrated is emphasized in red color and the one has been migrated is emphasized in blue color.
> It is recommended that you firstly run and verify your vba project.
>
>
> ---
## Other versions with matching text
[GstarCAD 2011](../../../2011/Developer%20Reference/VBA%20Migration%20Guide/Typical%20sample.md)