Access JumpStart 2.0 | Blog

A Rapid Development Framework for Microsoft Access

I enjoyed doing yesterday’s code kata. See that here: https://www.accessjumpstart.com/super-simple-code-kata/

So the goal was to write a function to convert an integer into a string and had 3 different situations to test.

The majority of the code in yesterday’s writing was boiler plate test code from RubberDuckVBA preparing lots of functions and features I didn’t need. So the Test code itself could have been boiled down to much simpler code, I just ran with what was given in the boiler plate when I had RubberDuckVBA build the test module.

The function itself was so simple because VBA already does this conversion implicitly for us.

If you say something like:

Dim myString As String 
myString = Cint(123)  ' Use Cint to make sure the number is actually an integer

Then myString will contain the string representation that you use to define the integer: “123”

I simply used this behavior to take a function that took an Integer as a parameter and returned a string type result.

There are other ways to explicitly convert an integer to a string like using the CStr function or using the concatenation operator “&” to do something like: 123 & “” which will convert the result into a string.

I’m sure there’s lots of other ways to do this too. So many ways that you could think of that you could probably have a whole web site devoted to it. Not that anyone would.

But basically, in this case, the coding kata was almost more about writing tests than the actual code.

So what’s next? I could definitely repeat this exercise a number of times and if I had no previous Access or VBA knowledge, this would help me solidify a few concepts, like:

  1. Writing tests: using RubberDuckVBA, or creating a simpler testing framework, or learning a new testing framework. You could just use debug.print statements to test your code without having any kind of testing framework.
  2. Writing functions: figuring out how to write functions you can call from the Immediate window or from some other module window. Then determining how to write a function to take a parameter and return a value.

That could definitely benefit a brand new Access / VBA user to repeat the exercise from scratch about 10 times. By the end of the 10th time, you’d have no problem writing a basic function and using it.

After you feel comfortable with a kata, it is time to move on to a different kata. Maybe another very simple kata, or maybe a more advanced kata. Sounds like it might be advantageous for me to create some more VBA code katas. What do you think? Have you used code katas before?

Sign up For a Daily Email Adventure in Microsoft Access

Every business day (typically M-F), I'll send you an email with information about my ongoing journey as an advanced Access application developer. It will be loaded with my tips and musings.

    We won't send you spam. Unsubscribe at any time.