VBA – Draw with Excel – Competiton Challenge

At the beginning of January 2015, the Software University has decided to carry out an IT Olympiad. The competition problems and their solutions in C# are available here.

In this article, I will present a way to resolve the second problem in Excel instead of C#. Pretty much it is a standard drawing problem, in which you get a number for an input and you return a picture. Like this:

pic

As far as I am more or less into VBA, I have decided to try to resolve it, using Excel formula. As you see, the picture consists of two parts – the roof and the square. The roof could be considered also from two parts – the last line, where you have space and star after each other and the rest. Knowing this, it is time to code…

With the function draw_a_house(n) in Excel, we receive the house. Two additional marks are important. You need font SimHei or Consolas and Wrap Text should be activated. But it really looks impressive:

draw_a_house

How it is done? I can bet that in C# it can be done with 5 or 6 times less code, but in VBA I had to define functions such as string_builder and once I was ready and it was working I was quite ok with it. The code is here:

Available also in GitHub here.

Enjoy it! 🙂

About

VBA Developer

Tagged with: , , ,