String Art Add-In v1.0 Examples

In the last post we went through the steps I used to create the first version of the String Art add-in. Now it’s time to look at a couple of examples which make use of it.

The first thing you need is a copy of the add-in, which you can either create yourself using the information in the previous post or you can download from here.

Open up a new Excel workbook and then open up the VBA IDE. Go to Tools > References > Browse > change the Files of type dropdown to Microsoft Excel Files and then browse to the folder containing the String Art v1.0 add-in. Select the add-in and click on Open. You should now see StringArt ticked in the available references.

Next create a standard code module (Insert > Module) and paste in the below code:

Option Explicit

'StringArt v1.0 Examples

Sub DrawRegularPolygonSectionByBothCornerPoints1()

    Dim clsCentrePoint As StringArt.cPoint
    Dim clsCornerPoint1 As StringArt.cPoint
    Dim clsCornerPoint2 As StringArt.cPoint
    Dim clsRegPol As StringArt.cRegularPolygon

    Set clsCentrePoint = StringArt.CreatePoint
    Set clsCornerPoint1 = StringArt.CreatePoint
    Set clsCornerPoint2 = StringArt.CreatePoint
    Set clsRegPol = StringArt.CreateRegularPolygon

    'define the coordinates of centrepoint
    'and end points of both axes
    clsCentrePoint.X = 130: clsCentrePoint.Y = 200
    clsCornerPoint1.X = 0: clsCornerPoint1.Y = 250
    clsCornerPoint2.X = 260: clsCornerPoint2.Y = 250

    'draw and join our two axes
    clsRegPol.DrawSectionByBothCornerPoints _
                        wstTarget:=Sheet1, _
                        clsCentrePoint:=clsCentrePoint, _
                        clsCornerPoint1:=clsCornerPoint1, _
                        clsCornerPoint2:=clsCornerPoint2, _
                        lngPointsPerAxis:=15, _
                        lngAxisJoinStyle:=Cobweb, _
                        varLineColor:=RGB(44, 10, 246) 'bluish

End Sub

Sub DrawRegularPolygonSectionByBothCornerPoints2()

    Dim clsCentrePoint As StringArt.cPoint
    Dim clsCornerPoint1 As StringArt.cPoint
    Dim clsCornerPoint2 As StringArt.cPoint
    Dim clsRegPol As StringArt.cRegularPolygon

    Set clsCentrePoint = StringArt.CreatePoint
    Set clsCornerPoint1 = StringArt.CreatePoint
    Set clsCornerPoint2 = StringArt.CreatePoint
    Set clsRegPol = StringArt.CreateRegularPolygon

    'define the coordinates of centrepoint
    'and end points of both axes
    clsCentrePoint.X = 100: clsCentrePoint.Y = 100
    clsCornerPoint1.X = 0: clsCornerPoint1.Y = 100
    clsCornerPoint2.X = 100: clsCornerPoint2.Y = 0

    'draw and join our two axes
    clsRegPol.DrawSectionByBothCornerPoints _
                        wstTarget:=Sheet1, _
                        clsCentrePoint:=clsCentrePoint, _
                        clsCornerPoint1:=clsCornerPoint1, _
                        clsCornerPoint2:=clsCornerPoint2, _
                        lngPointsPerAxis:=5, _
                        lngAxisJoinStyle:=Matrix, _
                        varLineColor:=RGB(237, 19, 19) 'reddish

End Sub

Sub DrawRegularPolygonSectionByBothCornerPoints3()

    Dim clsCentrePoint As StringArt.cPoint
    Dim clsCornerPoint1 As StringArt.cPoint
    Dim clsCornerPoint2 As StringArt.cPoint
    Dim clsRegPol As StringArt.cRegularPolygon

    Set clsCentrePoint = StringArt.CreatePoint
    Set clsCornerPoint1 = StringArt.CreatePoint
    Set clsCornerPoint2 = StringArt.CreatePoint
    Set clsRegPol = StringArt.CreateRegularPolygon

    'define the coordinates of centrepoint
    'and end points of both axes
    clsCentrePoint.X = 200: clsCentrePoint.Y = 100
    clsCornerPoint1.X = 150: clsCornerPoint1.Y = 150
    clsCornerPoint2.X = 250: clsCornerPoint2.Y = 150

    'draw and join our two axes
    clsRegPol.DrawSectionByBothCornerPoints _
                        wstTarget:=Sheet1, _
                        clsCentrePoint:=clsCentrePoint, _
                        clsCornerPoint1:=clsCornerPoint1, _
                        clsCornerPoint2:=clsCornerPoint2, _
                        lngPointsPerAxis:=15, _
                        lngAxisJoinStyle:=Parabolic

End Sub

When you run the code you should get an output like this on Sheet1.

It’s a simple start but it’s not going to be long before we add more methods which can draw and combine more patterns.

Advertisements

About Colin Legg

RAD Developer Microsoft MVP - Excel 2009 - 2014
This entry was posted in Microsoft Excel, Microsoft Office and tagged , . Bookmark the permalink.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s