Adam worked for a company that sold check printing machines. It was not a particularly large company, but the machines were cutting edge when it came to the latest and greatest technologies to prevent check fraud. So while the company was doing well enough, until now the company was selling equipment solely in the United States. At least, that is, until one of the more enterprising sales people decided to ‘branch out’.

In this case, the branch was a small Mexican bank. It was not known how the salesperson even made contact with the bank. There were rumors flying around that it involved a drunken night in Cabo and a lost wager in a cock fight. And maybe a tiger in a bathroom. But none of this is germane to Adam’s story.

In order to install the machine that had already been promised, there had to be a modification made to the software that operated it. Specifically, it need to be able to print the checks in Spanish. For Adam, that would be no problem…so long as the checks had a value less than 29 pesos. Adam’s grasp of Spanish didn’t go much beyond that level.

Fortunately, the nephew of the owner of the company (or was it the second cousin of the wife of the owner…it’s so hard to keep that straight) was fluent in Spanish AND VB.NET. So the task to write the translation component was contracted out.

After a week, the completed module was sent back to Adam, who ran it through some unit tests. It appeared to be working. Well it appeared to be working up to 29 pesos. But Adam did notice something odd with the formatting on the decimal portion.

To get to the bottom of this (as well as to perform the requisite audit on code that was going into production), Adam reviewed the source code for the module. What he saw caused the same reaction as one gets when Wolverine cleans a school blackboard.

Because of the nepotism involved, Adam felt that a written review would cover most of his butt. So he added his comments to the code directly.

' First off, the method name is not particularly descriptive of what
' method does. But beyond that, it takes the value as string. Does
' the coder expect that the check values are being manipulated as 
' strings?
Public Function SpanishMoney(ByVal num As String) As String
  Dim dollars As Decimal
  Dim cents As Integer
  Dim dollars_result As String
  Dim cents_result As String

' Interesting that the case is hardcoded in a variable. As opposed
' being flexible by allowing it to be passed in to the method

  Dim WordCase As String = "U"

' Nice conversion from a string to an integer to a decimal. No reason
' to go straight to decimal. Yes, the purpose is to get just the
' dollar portion, but really?
  dollars = CInt(num)

'### Convert the decimal to the equivilent string of words
  dollars_result = Words_1_all(dollars)

' I’m guessing that Words_1_all doesn’t know how to handle a value
' of zero? And I’m not bilingual, but I’m pretty certain that the
' Spanish word for 0 is not ‘zero’ but is cero.
  If Len(dollars_result) = 0 Then dollars_result = "zero"

' Interesting that they decided to check for the string and not
' the numeric value that has already been converted
  If dollars_result = "uno" Then
     dollars_result = dollars_result & " peso"
     dollars_result = dollars_result & " pesos"
  End If

'### Cents
' There is enough boxing and conversion in this statement for me to
' open a gift wrapping business
  cents = CInt((num - dollars) * 100.0#)

' Make sure a zero outputs two significant digits, but 1 through 9
' output only one. This is the source of the problem I noted
  If cents = 0 Then
     cents_result = "00/100 MONEDA NACIONAL"
     cents_result = cents & "/100 MONEDA NACIONAL"
  End If

'### Combine the results.
  SpanishMoney = dollars_result & " con " & cents_result

' Check to see if anyone has hacked the program to change the 
' hard coded case value

  If WordCase = "U" Then
     SpanishMoney = SpanishMoney.ToUpper
  End If
End Function

By the time he was finished, Adam had the urge to go scrub his hands with soap. Or maybe just wash out his eyes. But he had done his part (what little that was) and passed his comments on to his boss. Hopefully his boss would take them seriously. But more importantly, Adam hoped that the salesperson didn’t decide to take a vacation to Russia or China any time in the near future.

[Advertisement] BuildMaster allows you to create a self-service release management platform that allows different teams to manage their applications. Explore how!