Re: How to VB Script in FM ? -
07-13-2010
, 11:25 AM
Learn filemaker and scripting. (A macro is called a script here)
No seriously. There is nothing in your code that can't be resolved with fmp,
fields, variables and a script.
The script would probably end up being a lot shorter.
Without knowing which version you have,
your file setup (tables and fields involved)
AND
without you perhaps understanding the basics about filemaker
there is no use in going into details
but I'll get you going
fmp has one field: chaine
if this is set up being a number then you can leave out any number checking
(done at field level)
If you also enforce a 12 digits length (also at field level) no length
checking is needed within the script.
the checksum best is done with a custom function. But these only can be
implemented with the Advanced filemaker version.
Otherwise you'l have to write a loop here (as you have done with the macro.)
The last part would probably best fold into one nested Case/IF calculation
field
Hey wait one sec. I just solved it without any script. Just a couple of
intermediate calculations, ending in
one final calc, formatted as text, layed out as a textfield with the choosen
font. (provided you have the advanced version of 9, 10 or 11)
And if you are wondering if this is true, yes it is, I know because i have
done something very similar.
--
Keep well / Hou je goed
Ursus
"Hingel" <hingel (AT) gmail (DOT) com> schreef in bericht
news:5373baf5-a3fb-4a78-8b98-9f00cec4e662 (AT) e5g2000yqn (DOT) googlegroups.com...
Hi All,
I'm looking for a long time and I found a free ttf font for barcode
printing, but I have a macro running in Excel, how to convert this
macro to Filemaker.
Thanks,
-----MACRO----
Public Function ean13$(chaine$)
'Cette fonction est régie par la Licence Générale Publique Amoindrie
GNU (GNU LGPL)
'This function is governed by the GNU Lesser General Public License
(GNU LGPL)
'V 1.1.1
'Paramètres : une chaine de 12 chiffres
'Parameters : a 12 digits length string
'Retour : * une chaine qui, affichée avec la police EAN13.TTF, donne
le code barre
' * une chaine vide si paramètre 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$ = ""
'Vérifier qu'il y a 12 caractères
'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 clé de contrôle
'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 deuxième 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 séparateur 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 |