Jump to content
ch53

postition fails if occurrence is variable

Recommended Posts

Several forum contributions quoted "position" formulations containing variables for occurrences.  I am at a loss why my simple script (FM 17, win10) containing a loop (stepwise increasing $i) which includes

Set Variable [$colon[$i]; Value: Position ( Filme::Besetzung; ":"; 1; $i)]

doesn't yield any result - unless I use numbers rather than the variable, testwise. (I wonder how to paste lines from the script here.) I assume I made an amateurish mistake and am looking forward to receiving advice of someone more experienced.

 

Share this post


Link to post
Share on other sites
2 hours ago, ch53 said:

I wonder how to paste lines from the script here.

You can print the script to PDF and copy/paste from there. Or - much better - post a small file that shows the problem (and nothing else).

 

Share this post


Link to post
Share on other sites

I don't detect anything wrong with the script (other than that it doesn't do anything with the variables it populates). But that could be because I am reading the script, instead of running it. How did you determine that it "doesn't yield any result"?

Share this post


Link to post
Share on other sites

Thanks! In this part of the script, I meant to set $colon[1...$i] to contain the positions of ":" in the text "Filme:Besetzung", and $absatz the respective positions of the paragraph symbol.When I run data viewer in watch mode, $a and $i are correctly displayed, but nothing is given for $colon[$i] or $absatz[$i] unless I explicitly watch $colon[3], for example, to check the basic formulation, and then get the correct position number I counted in the text. It seemed so simple...

Share this post


Link to post
Share on other sites

I am afraid I cannot reproduce the problem you report. I am attaching a simple file I made. In the last pause of the script, I see this in the Current pane of the Data Viewer:

image.png.d200578c0848fb460d3dca9701f1a484.png

and this in the Watch pane:

image.png.31ca012853567a44d0c8a345e9cae3d3.png

 

testing.fmp12

Share this post


Link to post
Share on other sites

More thanks! I restarted FM, and the computer, but both didn't help. Please find attached screenshots of the data viewer for loop runs 1 through 4. For now, I give up...

test01-04.pdf

Share this post


Link to post
Share on other sites

OK! Now I tried it, and everything appears to be fine; same results as you showed. Can you possibly suggest anything else (apart from reinstalling the software)?

Share this post


Link to post
Share on other sites

More news: I ran the script on my old win7 PC, and it worked perfectly. Thus, I reckon I'll have to reinstall FM17, after all - but thanks anyway for your help and patience!

Share this post


Link to post
Share on other sites

I am glad you got it sorted. As an aside, I am not sure what exactly you're trying to accomplish here, but I suspect there is a simpler way.

 

Share this post


Link to post
Share on other sites

Yes, probably you're right! In the text field the script is meant to work on, each line contains an actor's name, and the respective character in a movie, arranged in various ways, e.g. separated by a specific word ("as") or a colon, or with brackets around the characters. Sometimes, the names are first, sometimes the characters. I want to extract the names only and put them in a repetition field. (I know, users are discouraged to apply this feature, but I'd like nevertheless to keep this structure, rather than unravel and reorganize it.) The entire script has grown over time, with ever more versions of how names and roles are assembled in the movies' informations; that is why it certainly is somewhat discombobulated.

Share this post


Link to post
Share on other sites

I too would recommend against using a repeating field for this. Splitting lines of text into separate related records is very easy, and you don't need to create repeating variables or find the positions of carriage returns for this. Just do something like:

Set Variable [ $n; Value:ValueCount ( YourTable::Textfield ) ] 
Loop
Set Variable [ $i; Value:$i + 1 ]
  Exit Loop If [ $i > $n ]
  Set Variable [ $line; Value:GetValue ( YourTable::Textfield ; $i ) ]

At this point the $line variable will hold the current line and you can go to the child table, create a new record and populate the name field with the name extracted from the $line variable. I am not sure how exactly to do the extraction, since you've listed several options but did not provide any rules for distinguishing among them. 

 

Share this post


Link to post
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.


  • Who Viewed the Topic

    1 member has viewed this topic:
    splatto 
×
×
  • Create New...

Important Information

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