Jump to content

Correct me, please !


This topic is 6961 days old. Please don't post here. Open a new topic instead.

Recommended Posts

Hi to all friends,

I need a correct english name for a function.

It returns a number, chosen by the position assigned to any individual character, for all characters of the Text.

E1 ValuedByPosition ( "1" ; "9876543210" ; 0) returns "8"

E2 ValuedByPosition ( "111" ; "9876543210" ; 0) returns "8 8 8 "

The result is in the format: Number Space NumberSpace ...

so I can add all the numbers with:

Evaluate ( Substitute ( result ; " "; " + " ) & "0")

I was thinking:

ValuedByPosition ( Text ; PositionedText ; StartValue )

or

SetTextValue ( Text ; PositionedText ; StartValue )

... but my English is so bad ...

This is the function:

ValuedByPosition ( Text ; PositionedText ; StartValue )

Let

([

Length = Length ( Text );

NextText = Right ( Text ; Length - 1);

Char = Left ( text; 1);

Position = Position ( PositionedText ; Char; 1; 1) - 1//so we can start from "0" without using negative numbers for StartValue

] ;

If (Length ; Replace ( Char ; 1 ; 1 ; Position + StartValue ) & " " & ValuedByPosition (NextText ; PositionedText ; StartValue) ;"")

)

Can anyone help ?

(You can change any word of this post, if You think that is better)

Link to comment
Share on other sites

Hi, Ender

thank you for your replay !

CharacterPositions isn't the exact doing of the function !

The function assign a value (what s.o. want) to a set of characters...

And I wanted to assign 8 to 1, so the startValue was setted to "0".

By the way can you correct my misspellings ?

Link to comment
Share on other sites

Hi Daniele,

I don't have a name for you - SetTextValue() seems OK to me - just a couple of notes:

1. Since you only deal with a single character at a time, your range is limited to 10 values, from 0 to 9. So all you seem to be doing is swap one number for another, (e.g. 0 becomes 9, 1 becomes 8, etc.), and add a space.

This could be achieved by much simpler methods, for example:

Substitute (

[ "0" ; "9 " ] ;

[ "1" ; "8 " ] ;

...

2. I would avoid naming variables with names that are also Filemaker functions, such as Length and Position. Although it is allowed, I find it can be confusing.

I also prefer to start variables names with lower-case characters, e.g. char or nextText. This is the convention in JavaScript, and I hope it will become one in FMP as well.

Link to comment
Share on other sites

Hi, Michael

I wished your replay !

2)I agree to all you said

1)the range isn't so limited:

what about: ABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789 ? (those are 36 values)

I had to do what you suggest now to me in my CheckCF CF and was very bad to look!

You said that SetTextValue is good but "PositionedText" is good too ?

Link to comment
Share on other sites

I thought you wanted to treat the result as number. Evaluate ( "A + B + 0" ) will not produce much of a result.

In any case, this is still a one-to-one match function: for every single character of Text, there is a corresponding single character (with added space) in PositionedText. It is hard to see what advantage a custom function offers over Substitute().

Link to comment
Share on other sites

Hi, Michael

OK, I'm going to explain me better ! ( or so I wish to do !)

I thought you wanted to treat the result as number. Evaluate ( "A + B + 0" ) will not produce much of a result.

Yes, the result is a number by position of the character & a space.

E1 ValuedByPosition ( "Michael" ; "ABCDEFGHIJKLMNOPQRSTUVWXYZ" ; 0) returns "12 8 2 7 0 4 11 "

E2 ValuedByPosition ( "zapped" ; "ABCDEFGHIJKLMNOPQRSTUVWXYZ" ; 0) returns "25 0 15 15 4 3 "

(Note that this function isn't case sensitive and that the result contains values greater than "9")

So Evaluate(25+0+15+15+4+3+0) produce a result ! (62)

In any case, this is still a one-to-one match function: for every single character of Text, there is a corresponding single character (with added space) in PositionedText. It is hard to see what advantage a custom function offers over Substitute().

The substitute() function is case sensitive and, worse, it give some result that is difficult to override.

Try this:

Substitute ( "192054"; ["0";"1"]; ["1";"0"]; ["2";"5"]; ["3";"7"]; ["4";"9"]; ["5";"13"]; ["6";"15"]; ["7";"17"]; ["8";"19"]; ["9";"21"])

The result is: "0 21 13 0 13 21 " (that is wrong !!)

But: ValuedByPosition ( "192054" ; "10CDE2G3I4KLM5O6Q7S8U9WXYZ" ; 0)

gives: "0 21 5 1 13 9 " (that is correct !!) (NOT TO MENTION THE COMPACTNESS)

And how can you obtain "Michael" = "12 8 2 7 0 4 11 " with Substitute() function ? How long it will be the formula ?

Link to comment
Share on other sites

Ok, that really clarifies what you're after. This is indeed coding, so you should probably name it TextToCode, or EncodeText or something similar.

And perhaps you could simplify it to something like:

FunctionName ( text ; alphabet ; startValue )

Let

( [

len = Length ( text ) ;

nextText = Right ( text ; len - 1 ) ;

char = Left ( text ; 1) ;

pos = Position ( alphabet ; char ; 1 ; 1 ) - 1 + startValue

] ;

Case (

len ;

pos & " " & FunctionName ( nextText ; alphabet ; startValue )

)

)

Link to comment
Share on other sites

hi to all

thank you very much for your precious advices !

So the function will be: Encode ( text ; code ; startValue )

Ciao

/* Encode function

Author

Daniele Raybaudi and friends

Format

Encode ( text ; code ; startValue )

Parameters

text - any text expression or text field

code - a string of positioned characters

startValue - the number to assign to the first character of code

Data type returned

text

Description

Returns a number, chosen by the position assigned to any individual character, for all characters of the Text.

It add also a space between numbers.

March 25, 2005

*/

Let

( [

len = Length ( text ) ;

nextText = Right ( text ; len - 1 ) ;

char = Left ( text ; 1) ;

pos = Position ( code ; char ; 1 ; 1 ) - 1 + startValue

] ;

Case (

len ;

pos & " " & Encode ( nextText ; code ; startValue )

)

)

Link to comment
Share on other sites

This topic is 6961 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 account

Sign in

Already have an account? Sign in here.

Sign In Now
×
×
  • Create New...

Important Information

By using this site, you agree to our Terms of Use.