m.v.peabody Posted July 25, 2007 Posted July 25, 2007 I'm building an image library and think this may be so common that it must have been done already. The image name is imported into a "Name" field, and we would like a "Description" field to be based on the name. The way these files are named is something like "SixWhiteMice.jpg" and I would like FM to recognize capital letters in the middle of a word and put a space before each capital letter. Final result should be Six White Mice in the "Description" field. Has this already been done? I would hate to reinvent this particular wheel. ~ ~ ~ ~ ~ ~ ~ FREEBIE ~ ~ ~ ~ ~ ~ ~ I have a "remove extension" script, which works like this: If [Right ( Layout::Description ; 4 ) = ".eps" or Right ( Layout::Description ; 4 ) = ".EPS" or Right ( Layout::Description ; 4 ) = ".jpg" or Right ( Layout::Description ; 4 ) = ".JPG" or Right ( Layout::Description ; 4 ) = ".pdf" or Right ( Layout::Description ; 4 ) = ".PDF" or Right ( Layout::Description ; 4 ) = ".psd" or Right ( Layout::Description ; 4 ) = ".tif" or Right ( Layout::Description ; 4 ) = ".TIF"] Set Field [Left ( Layout::Description ; Length ( Layout::Description ) - 4 )] End If
Genx Posted July 25, 2007 Posted July 25, 2007 Trim( Substitute( Name ; ["A" ; " A"] ; ["B" ; " B" ] ; ["C" ; " C"] ; ... ; ["Z" ; " Z"] ) ) That's the most efficient way I can think of doing it anyway.
Lee Smith Posted July 25, 2007 Posted July 25, 2007 Custom Functions are only available to you if you have the Advance Edition of FileMaker. Your profile shows only the Regular 8.5. If you have advance, the please change your profile. Also, this does not require a Custom Function. Lee
m.v.peabody Posted July 25, 2007 Author Posted July 25, 2007 Thanks gents. Changing profile. We have Advanced in house, but not on my regular workstation. (Maybe we can get a moderator to move this thread to Scriptmaker.)
Genx Posted July 25, 2007 Posted July 25, 2007 I would've said the calc brain one ( i forget which side of the brain does what though so meh ).
Lee Smith Posted July 25, 2007 Posted July 25, 2007 You can use a script to do this if you want. I'm waiting a file to translate, so I competed genx's calculation for you. Trim( Substitute ( Raw ; ["A";" A"]; ["B";" B"]; ["C";" C"]; ["D";" D"]; ["E";" E"]; ["F";" F"]; ["G";" G"]; ["H";" H"]; ["I";" I"]; ["J";" J"]; ["K";" K"]; ["L";" L"]; ["M";" M"]; ["N";" N"]; ["O";" O"]; ["P";" P"]; ["Q";" Q"]; ["R";" R"]; ["S";" S"]; ["T";" T"]; ["U";" U"]; ["V";" V"]; ["W";" W"]; ["X";" X"]; ["Y";" Y"]; ["Z";" Z"]; [".eps" ; ""]; [".EPS" ; ""]; [".jpg" ; ""]; [".JPG" ; ""]; [".pdf" ; ""]; [".PDF" ; ""]; [".psd" ; ""]; [".tif" ; ""]; [".TIF" ; ""] ) ) Lee :cool:
m.v.peabody Posted July 25, 2007 Author Posted July 25, 2007 I would've said the calc brain one ( i forget which side of the brain does what though so meh ). One side of mine rattles, the other echoes. The voices make it difficult to tell which side is doing which. Thank you again, Lee.
Alexander Zueiv Posted July 25, 2007 Posted July 25, 2007 (edited) // Function: SpaceUp ( TEXT ) // Author: Alexander Zueiv // URL: http://web.mac.com/zueiv/ // Example: TrimAll ( SpaceUp ( "SomeTestText123and456AndXYZAndMore" ) ; 0 ; 1 ) // Result: "Some Test Text 123 and 456 And XYZ And More" Case ( not IsEmpty ( Filter ( Left ( TEXT ; 1 ) ; "ABCDEFGHIJKLMNOPQRSTUVWXYZ" ) ) and not IsEmpty ( Filter ( Middle ( TEXT ; 2 ; 1 ) ; "abcdefghijklmnopqrstuvwxyz" ) ) ; " " & Left ( TEXT ; 1 ) ; not IsEmpty ( Filter ( Left ( TEXT ; 1 ) ; "abcdefghijklmnopqrstuvwxyz" ) ) and not IsEmpty ( Filter ( Middle ( TEXT ; 2 ; 1 ) ; "ABCDEFGHIJKLMNOPQRSTUVWXYZ1234567890" ) ) ; Left ( TEXT ; 1 ) & " " ; not IsEmpty ( Filter ( Left ( TEXT ; 1 ) ; "1234567890" ) ) and not IsEmpty ( Filter ( Upper ( Middle ( TEXT ; 2 ; 1 ) ) ; "ABCDEFGHIJKLMNOPQRSTUVWXYZ" ) ) ; Left ( TEXT ; 1 ) & " " ; Left ( TEXT ; 1 ) ) & If ( Length ( TEXT ) > 1 ; SpaceUp ( Right ( TEXT ; Length ( TEXT ) - 1 ) ) ) // End Function Edited July 25, 2007 by Guest
Alexander Zueiv Posted July 25, 2007 Posted July 25, 2007 Thank you! I've been reading some feeds from this site for a wile, but alas only a few forums are available through RSS. I wish there were more of them so I could be of a better help.
comment Posted July 25, 2007 Posted July 25, 2007 I would say, if we're going to have a CF for this, then let's have one that doesn't require cleaning up and, more importantly, one that would work with any character set that recognizes upper and lower - Cyrillic for example? :girlgiggle: DeCamelizeCF.fp7.zip
Alexander Zueiv Posted July 25, 2007 Posted July 25, 2007 Nice trick! I recall I've been using something like that for a type-ahead portal filter - to remove punctution characters: Let ( [ TEXT = CmpName ; SPACE = " " ; PUNCTS = Substitute ( Filter ( Upper ( TEXT ) ; Lower ( TEXT ) ) ; [ "1" ; "" ] ; [ "2" ; "" ] ; [ "3" ; "" ] ; [ "4" ; "" ] ; [ "5" ; "" ] ; [ "6" ; "" ] ; [ "7" ; "" ] ; [ "8" ; "" ] ; [ "9" ; "" ] ; [ "0" ; "" ] ; [ SPACE ; "" ] ) ; WORDS = Substitute ( TEXT ; [ Middle ( PUNCTS ; 1 ; 1 ) ; SPACE ] ; [ Middle ( PUNCTS ; 2 ; 1 ) ; SPACE ] ; [ Middle ( PUNCTS ; 3 ; 1 ) ; SPACE ] ; [ Middle ( PUNCTS ; 4 ; 1 ) ; SPACE ] ; [ Middle ( PUNCTS ; 5 ; 1 ) ; SPACE ] ; [ Middle ( PUNCTS ; 6 ; 1 ) ; SPACE ] ; [ Middle ( PUNCTS ; 7 ; 1 ) ; SPACE ] ; [ Middle ( PUNCTS ; 8 ; 1 ) ; SPACE ] ; [ Middle ( PUNCTS ; 9 ; 1 ) ; SPACE ] ; [ Middle ( PUNCTS ; 10 ; 1 ) ; SPACE ] ) ] ; SPACE & TrimAll ( WORDS ; 0 ; 3 ) & ¶ & Substitute ( TrimAll ( WORDS ; 0 ; 1 ) ; SPACE ; ¶ ) & "¶ " ) // End Let For the function SpaceUp() multilingual support is of no value since it is created to generate a Field Label from a FieldName which is always in Latin.
comment Posted July 25, 2007 Posted July 25, 2007 FieldName which is always in Latin It doesn't have to be.
Alexander Zueiv Posted July 25, 2007 Posted July 25, 2007 (edited) let's have one that doesn't require cleaning up The point is that FMP very slow works with memory. The more variables you use the slower your code works. At some level of code complexity this slowness becomes very noticeable. So I'd suggest to use nested functions instead of extra variables whenever is possible. An extra variable can speed up a code if it is used to replace several references to the same unstored calc field or some Agregate function. Fortunately, since FMP7 this replacement makes no sense for Case/If/Choose statement - last versions of FMP do not recalculate every Case as did old ones. Edited July 25, 2007 by Guest
comment Posted July 25, 2007 Posted July 25, 2007 The more variables you use the slower your code works. Do you have an example of that? I always try to use a variable when the same expression needs to be used more than once, and sometimes just for clarity. I have recently made a speed comparison between Set Field [ Somefield ; Get (ScriptParameter) ] and Set Field [ Somefield ; Let ( x = Get (ScriptParameter) ; x ) ] and the difference is negligible. In any case, the 'cleaning up' here was just a matter of reversing the direction of the loop.
Alexander Zueiv Posted July 26, 2007 Posted July 26, 2007 (edited) Do you have an example of that? Calculate summaries of these two fields on 100K records: Left ( Right ( Left ( Right ( Left ( Right ( Left ( SerialNum ; 7 ) ; 6 ) ; 5 ) ; 4 ) ; 3 ) ; 2 ) ; 1 ) Let ( [ a = SerialNum ; b = Left ( a ; 7 ) ; c = Right ( b ; 6 ) ; d = Left ( c ; 5 ) ; e = Right ( d ; 4 ) ; f = Left ( e ; 3 ) ; g = Right ( f ; 2 ) ; h = Left ( g ; 1 ) ] ; h ) The results should be the same while the time difference could be up to x2 (7 and 10 seconds on my Intel Core Duo 2GHz). Edited July 26, 2007 by Guest
Alexander Zueiv Posted July 26, 2007 Posted July 26, 2007 It doesn't have to be. It have to be in the same language as function names or else you'd get tired to switch language when typing in a code.
Alexander Zueiv Posted July 26, 2007 Posted July 26, 2007 It have to be in the same language as function names or else you'd get tired to switch language when typing in a code. And if you have a .fp3 file with, say, Russian filed names, it is simpler to trash it than to convert to .fp7
Alexander Zueiv Posted July 26, 2007 Posted July 26, 2007 The more variables you use the slower your code works. Summary Field Tests for three unstored calc fields with 200K records with FMPA8.5 on iMac Intel Core Duo 2Ghz: Let ( [ a = SerialNum ; b = Left ( a ; 7 ) ; c = Right ( b ; 6 ) ; d = Left ( c ; 5 ) ; e = Right ( d ; 4 ) ; f = Left ( e ; 3 ) ; g = Right ( f ; 2 ) ] ; Left ( g ; 1 ) & Right ( g ; 1 ) ) Result: 21-22 seconds; Left ( Right ( Left ( Right ( Left ( Right ( Left ( SerialNum ; 7 ) ; 6 ) ; 5 ) ; 4 ) ; 3 ) ; 2 ) ; 1 ) & Right ( Right ( Left ( Right ( Left ( Right ( Left ( SerialNum ; 7 ) ; 6 ) ; 5 ) ; 4 ) ; 3 ) ; 2 ) ; 1 ) Result: 21-22 seconds; Let ( a = Right ( Left ( Right ( Left ( Right ( Left ( SerialNum ; 7 ) ; 6 ) ; 5 ) ; 4 ) ; 3 ) ; 2 ) ; Left ( a ; 1 ) & Right ( a ; 1 ) ) Result: 17-18 seconds. The tests above show that extra variables make the code work as slow as recalculating values, while a properly used variable can give a noticeable speed up. SpeedTest.fp7.zip
comment Posted July 26, 2007 Posted July 26, 2007 It have to be in the same language as function names or else you'd get tired to switch language when typing in a code. You are describing a personal preference - not a Filemaker limitation. And if you have a .fp3 file with, say, Russian filed names, it is simpler to trash it than to convert to .fp7 Well, that was before Unicode. And it's not as bad as it seems - all you need is a conversion table. I had to do this several times - not with field names, but with text constants - and I survived. I'll take a look at your file - thanks.
Alexander Zueiv Posted July 26, 2007 Posted July 26, 2007 it's not as bad as it seems - all you need is a conversion table Tell me about that! I survived after doing that with various binary files, like Word 6 and Excel 5, FMP3 for Win and WC4, various old OS's, etc. I even once made a patch to allow FMP6 index and sort Armenian text. However, none of these can change my preference that all programming code include field names must be written in plain English: A-z, 0-9, and _. BTW, I don't work for local market, so if I give a Russian name to a field that would be considered as a joke. :)
comment Posted July 26, 2007 Posted July 26, 2007 That happens to be my preference, too. But I see no reason for a German/French/Czech/Turkish/etc. developer to adopt it - especially if they happen to be working with a localized version, where the functions are translated as well. That's why I try to make my formulae indepedent of the local language, date format and such.
Alexander Zueiv Posted July 27, 2007 Posted July 27, 2007 (edited) a localized version, where the functions are translated as well What a hell?! This makes the function Evaluate() almost meaningless. Or do it yet understand English function names? Could you confirm that? Do they also translate the function Let()? If they do, what then should we do with their examples from their Help? ScriptParameter = "a = 5; b = 10" Evaluate("Let ( [" & Get(ScriptParameter) & "]; a + 1 )") Evaluate("Get(CurrentTimeStamp)", [FieldB, FieldC]) Edited July 27, 2007 by Guest
comment Posted July 27, 2007 Posted July 27, 2007 Sorry, I have no idea. I have never worked with a localized version. I only know, from some posts here, that the function names ARE different.
Alexander Zueiv Posted July 29, 2007 Posted July 29, 2007 Fortunately I was wrong: http://filemaker.custhelp.com/cgi-bin/filemaker.cfg/php/enduser/std_adp.php?p_faqid=5353 My appologies to FMI. ;)
Recommended Posts
This topic is 6328 days old. Please don't post here. Open a new topic instead.
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now