dbTalk Databases Forums  

What is wrong with this example

comp.databases.filemaker comp.databases.filemaker


Discuss What is wrong with this example in the comp.databases.filemaker forum.



Reply
 
Thread Tools Display Modes
  #1  
Old   
LinuxCub
 
Posts: n/a

Default What is wrong with this example - 02-20-2011 , 02:26 PM






I have a table, tbl1, looking like this:

Id Val
1 a
2 b
3 c
4 d

and FM autocreated a default layout for it, also called "tbl1".

I created a self-join relationship from Id to Id, calling the "shadow"
table "tbl1a", and with the condition between Id and Id being "not
equals".

I created a layout showing fields from "tbl1a", calling the layout
"tbl1a"

I created the following script:

Go to Layout ["tbl1" (tbl1)]
Go to record/request/Page [First]
Loop
Show Custom Dialog ["Outer loop"; tbl1::Id]
Go to Related Record [Show only related records; From table:
"tbl1a"; Using layout: "tbl1a" (tbl1a)]
Go to Layout ["tbl1a" (tbl1a)]
Loop
Show Custom Dialog ["Inner loop"; tbl1:.Id & ", " & tbl1a::Id]
Go to Record/Request/Page [Next; Exit after last]
End Loop
Go to Layout ["tbl1" (tbl1)]
Go to Record/Request/Page [Next; Exit after last]
End Loop

I expect the following output from the invocations of Show Custom
Dialog:
Outer loop 1
Inner loop 1, 2
Inner loop 1, 3
Inner loop 1, 4
Outer loop 2
Inner loop 2, 1
Inner loop 2, 3
Inner loop 2, 4
Outer loop 3
Inner loop 3, 1
Inner loop 3, 2
Inner loop 3, 4
Outer loop 4
Inner loop 4, 1
Inner loop 4, 2
Inner loop 4, 3

But I see this output:

Outer loop 1
Inner loop 1, 2
Inner loop 1, 3
Inner loop 1, 4
Outer loop 2
Inner loop 2, 1
Inner loop 1, 3
Inner loop 1, 4
Outer loop 3
Inner loop 2, 1
Inner loop 1, 2
Inner loop 1, 4
Outer loop 4
Inner loop 2, 1
Inner loop 1, 2
Inner loop 1, 3

Why do the values for tbl1::Id in the inner loop not match what I
expect ?
How come tbl1::Id in the outer loop doesn't match tbl1::Id in the
inner loop ?

Reply With Quote
  #2  
Old   
Agi
 
Posts: n/a

Default Re: What is wrong with this example - 02-21-2011 , 08:52 AM






On Feb 20, 3:26*pm, LinuxCub <linux... (AT) email (DOT) dk> wrote:
Quote:
I have a table, tbl1, looking like this:

Id * * Val
1 * * *a
2 * * *b
3 * * *c
4 * * *d

and FM autocreated a default layout for it, also called "tbl1".

I created a self-join relationship from Id to Id, calling the "shadow"
table "tbl1a", and with the condition between Id and Id being "not
equals".

I created a layout showing fields from "tbl1a", calling the layout
"tbl1a"

I created the following script:

Go to Layout ["tbl1" (tbl1)]
Go to record/request/Page [First]
Loop
* Show Custom Dialog ["Outer loop"; tbl1::Id]
* Go to Related Record [Show only related records; From table:
"tbl1a"; Using layout: "tbl1a" (tbl1a)]
* Go to Layout ["tbl1a" (tbl1a)]
* Loop
* * Show Custom Dialog ["Inner loop"; tbl1:.Id & ", " & tbl1a::Id]
* * Go to Record/Request/Page [Next; Exit after last]
* End Loop
* Go to Layout ["tbl1" (tbl1)]
* Go to Record/Request/Page [Next; Exit after last]
End Loop

I expect the following output from the invocations of Show Custom
Dialog:
Outer loop *1
Inner loop * 1, 2
Inner loop * 1, 3
Inner loop * 1, 4
Outer loop *2
Inner loop * 2, 1
Inner loop * 2, 3
Inner loop * 2, 4
Outer loop *3
Inner loop * 3, 1
Inner loop * 3, 2
Inner loop * 3, 4
Outer loop *4
Inner loop * 4, 1
Inner loop * 4, 2
Inner loop * 4, 3

But I see this output:

Outer loop *1
Inner loop * 1, 2
Inner loop * 1, 3
Inner loop * 1, 4
Outer loop *2
Inner loop * 2, 1
Inner loop * 1, 3
Inner loop * 1, 4
Outer loop *3
Inner loop * 2, 1
Inner loop * 1, 2
Inner loop * 1, 4
Outer loop *4
Inner loop * 2, 1
Inner loop * 1, 2
Inner loop * 1, 3

Why do the values for tbl1::Id in the inner loop not match what I
expect ?
How come tbl1::Id in the outer loop doesn't match tbl1::Id in the
inner loop ?

What is it that you arentrying to achieve? On a forum such as this,
you are best off explaining your goal in laymen's terms.

Reply With Quote
  #3  
Old   
Howard Schlossberg
 
Posts: n/a

Default Re: What is wrong with this example - 02-21-2011 , 10:24 AM



It doesn't give the expected results because of your relationship from
tbl1a back to tbl1. When tbl1a is on record 1, it is going to grab the
first record (in creation order) in tbl1 that is not the same, which is
ALWAYS going to be record 2.

Likewise, when tbl1a is on record 2 or higher, it is going to grab the
first record (in creation order) in tbl1 that is not the same, which is
ALWAYS going to be record 1.

It's a mistake that could have been made in any language.

Here is more likely what you want to do:

Go to Layout ["tbl1" (tbl1)]
Go to record/request/Page [First]
Loop
Set Variable [ $outer; tbl1::Id ]
Show Custom Dialog ["Outer loop"; $outer]
Go to Related Record [Show only related records; From table:
"tbl1a"; Using layout: "tbl1a" (tbl1a)]
Loop
Show Custom Dialog ["Inner loop"; $outer & ", " & tbl1a::Id]
Go to Record/Request/Page [Next; Exit after last]
End Loop
Go to Layout ["tbl1" (tbl1)]
Go to Record/Request/Page [Next; Exit after last]
End Loop

There are perhaps other ways to do it without switching layouts, as
well. For example, you could loop through tbl1a records and then just
grab the full list of related records with the list() function (and then
loop through those variables to assemble data in the way you want).



On 2/20/2011 12:26 PM, LinuxCub wrote:
Quote:
Go to Layout ["tbl1" (tbl1)]
Go to record/request/Page [First]
Loop
Show Custom Dialog ["Outer loop"; tbl1::Id]
Go to Related Record [Show only related records; From table:
"tbl1a"; Using layout: "tbl1a" (tbl1a)]
Go to Layout ["tbl1a" (tbl1a)]
Loop
Show Custom Dialog ["Inner loop"; tbl1:.Id& ", "& tbl1a::Id]
Go to Record/Request/Page [Next; Exit after last]
End Loop
Go to Layout ["tbl1" (tbl1)]
Go to Record/Request/Page [Next; Exit after last]
End Loop

Reply With Quote
  #4  
Old   
Your Name
 
Posts: n/a

Default Re: What is wrong with this example - 02-21-2011 , 01:55 PM



"Howard Schlossberg" <howard (AT) nospam (DOT) fmprosolutions.com> wrote

Quote:
snip

There are perhaps other ways to do it without switching layouts, as
well. For example, you could loop through tbl1a records and then just
grab the full list of related records with the list() function (and then
loop through those variables to assemble data in the way you want).
Or put a Portal "displaying" the Related Records on the Layout, then the
outer loop can go through the Records while the inner loop goes through the
Portal rows.

Of course, it depends on what is trying to be achieved by the looping
(displaying a custom message window for each record / related record is
obviously rather pointless for anything other than testing). There may well
be a an entirely different and better way of doing it.

Helpful Harry )

Reply With Quote
  #5  
Old   
LinuxCub
 
Posts: n/a

Default Re: What is wrong with this example - 02-22-2011 , 04:05 PM



I arrived at the $temporary_variable solution myself, by trial and error, but your explanation is exactly what I needed to get a better understanding of what happened, and I thank you very much for answering.

Reply With Quote
  #6  
Old   
LinuxCub
 
Posts: n/a

Default Re: What is wrong with this example - 02-22-2011 , 04:13 PM



I'm trying to _learn_ Filemaker. That is why it might be more valuable to me to try something, and have people explain to me why I'm doing it wrong (and as you'll see in the thread elsewhere, some people do get what I'm trying to do), than to simply receive a solution, which I might not understand fully.

I'm not interested in http://en.wikipedia.org/wiki/Cargo_cult_programming :-)

Reply With Quote
  #7  
Old   
Your Name
 
Posts: n/a

Default Re: What is wrong with this example - 02-22-2011 , 05:58 PM



In article
<f2c32acc-141b-4020-a0e0-20d4a7cd638a (AT) glegroupsg2000goo (DOT) googlegroups.com>,
comp.databases.filemaker (AT) googlegroups (DOT) com wrote:

Quote:
I'm trying to _learn_ Filemaker. That is why it might be more valuable
to me to try something, and have people explain to me why I'm doing it
wrong (and as you'll see in the thread elsewhere, some people do get
what I'm trying to do), than to simply receive a solution, which I
might not understand fully.

I'm not interested in http://en.wikipedia.org/wiki/Cargo_cult_programming
:-)
It's usually best to say things like: what you're trying to achieve, the
structure of the database, what you have done, why you believe it's not
working, as well as examples of what you want and what you're getting (as
you did with the custome dialog messages).

It also helps to know what version of FileMaker and OS you're using (or
the database will finally use), and whether it will run on an individual
computer, peer-hosted or FileMaker Server hosted.

That way people know the best way to try and help you to do what you want.

Helpful Harry )

Reply With Quote
Reply




Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off



Powered by vBulletin Version 3.5.3
Copyright ©2000 - 2012, Jelsoft Enterprises Ltd.