Err.509 calc when running a macro with single cell input

I have a macro that takes a cell containing a 12 digit string and outputs a code for a barcode font. It has and does work well in an old version of Open Office but in Libreoffice 7.4 gives an Err.509
The macro is referencing a value in the cell next to it on the same sheet which is the product of another macro.
The code is below - can someone give me an idea of what the problem is or what settings I should change for compatibility?

Many thanks

Public Function ean13$(Optional chaine$)
  'Cette fonction est regie par la Licence Generale Publique Amoindrie GNU (GNU LGPL)
  'This function is governed by the GNU Lesser General Public License (GNU LGPL)
  'V 1.1.1
  'Parametres : une chaine de 12 chiffres
  'Parameters : a 12 digits length string
  'Retour : * une chaine qui, affichee avec la police EAN13.TTF, donne le code barre
  '         * une chaine vide si parametre fourni incorrect
  'Return : * a string which give the bar code when it is dispayed with EAN13.TTF font
  '         * an empty string if the supplied parameter is no good
  Dim i%, checksum%, first%, CodeBarre$, tableA As Boolean
  ean13$ = ""
 ' chaine$="022000612345"
  'Verifier qu'il y a 12 caracteres
  'Check for 12 characters
    If Len(chaine$) = 12 Then
    'Et que ce sont bien des chiffres
    'And they are really digits
    For i% = 1 To 12
      If Asc(Mid$(chaine$, i%, 1)) < 48 Or Asc(Mid$(chaine$, i%, 1)) > 57 Then
        i% = 0
        Exit For
      End If
    Next
    If i% = 13 Then
      'Calcul de la cle de controle
      'Calculation of the checksum
      For i% = 12 To 1 Step -2
        checksum% = checksum% + Val(Mid$(chaine$, i%, 1))
      Next
      checksum% = checksum% * 3
      For i% = 11 To 1 Step -2
        checksum% = checksum% + Val(Mid$(chaine$, i%, 1))
      Next
      chaine$ = chaine$ & (10 - checksum% Mod 10) Mod 10
      'Le premier chiffre est pris tel quel, le deuxieme vient de la table A
      'The first digit is taken just as it is, the second one come from table A
      CodeBarre$ = Left$(chaine$, 1) & Chr$(65 + Val(Mid$(chaine$, 2, 1)))
      first% = Val(Left$(chaine$, 1))
      For i% = 3 To 7
        tableA = False
         Select Case i%
         Case 3
           Select Case first%
           Case 0 To 3
             tableA = True
           End Select
         Case 4
           Select Case first%
           Case 0, 4, 7, 8
             tableA = True
           End Select
         Case 5
           Select Case first%
           Case 0, 1, 4, 5, 9
             tableA = True
           End Select
         Case 6
           Select Case first%
           Case 0, 2, 5, 6, 7
             tableA = True
           End Select
         Case 7
           Select Case first%
           Case 0, 3, 6, 8, 9
             tableA = True
           End Select
         End Select
       If tableA Then
         CodeBarre$ = CodeBarre$ & Chr$(65 + Val(Mid$(chaine$, i%, 1)))
       Else
         CodeBarre$ = CodeBarre$ & Chr$(75 + Val(Mid$(chaine$, i%, 1)))
       End If
     Next
      CodeBarre$ = CodeBarre$ & "*"   'Ajout separateur central / Add middle separator
      For i% = 8 To 13
        CodeBarre$ = CodeBarre$ & Chr$(97 + Val(Mid$(chaine$, i%, 1)))
      Next
      CodeBarre$ = CodeBarre$ & "+"   'Ajout de la marque de fin / Add end mark
      ean13$ = CodeBarre$
    End If
  End If
End Function

Well, there are two sides to everything. LibreOffice Calc can handle wider spreadsheets than its great-grandfather from OpenOffice… And that’s a good thing. But now EAN13 refers to a specific cell on the sheet. And that’s bad for a function that has the same name…

image

Try changing EAN13 in the code to, for example, EAN_13. That helped?

3 Likes

That all makes sense… Thanks for that. Not getting the error now but calculating the checksum incorrectly for some reason - will look further into that.
Many thanks