[comp.sys.mac.hypercard] behaviour of "it"

marc@cogsci.ed.ac.uk (Marc Moens) (09/12/90)

(This is 1.2.5)
I have two stacks, one called Publications, the other called
Abstracts.  Each card in the Publications stack has brief details of a
single techreport; the card has the name of that techreport -- e.g.
r22a.  Each card in the Abstracts stack has more detailed information
about a single techreport, also on a single card; the card has the
name of that techreport -- e.g. r22a.

I wanted to create a button on the Publications cards that would take
you to the appropriate card (i.e. the card of the same name) in the
Abstracts stack. I tried the following:

	get the name of this card
	go to it in stack "abstracts"

Getting the name of the card sets `it' to, for example, 'card "r22a"'.
I was then hoping the second line would get instantiated to

	go to card "r22a" in stack "abstracts"

But that doesn't seem to be the case. I don't get an error message; 
nothing at all happens.

I discovered I can get round the problem by doing something like

	get the name of this card
	go to stack "abstracts"
	go to it

This works, but doesn't seem to be very clean. Am I missing something?


An absolute beginner

-------------------------------------------------------------------
Marc Moens 	   Phone: +44 31 667 1011 x6444 | University of Edinburgh
UUCP:   ...!uunet!mcvax!ukc!its63b!cogsci!marc  | Centre for Cognitive Science
ARPA:   marc%cogsci.ed.ac.uk@nsfnet-relay.ac.uk | 2 Buccleuch Place
JANET:  marc@uk.ac.ed.cogsci                    | Edinburgh EH8 9LW Scotland

chh9@quads.uchicago.edu (Conrad Halton Halling) (09/15/90)

In article <1867@scott.ed.ac.uk> marc@cogsci.ed.ac.uk (Marc Moens) writes:

> [stuff deleted]
>I wanted to create a button on the Publications cards that would take
>you to the appropriate card (i.e. the card of the same name) in the
>Abstracts stack. I tried the following:
>
>	get the name of this card
>	go to it in stack "abstracts"
>
>Getting the name of the card sets `it' to, for example, 'card "r22a"'.
>I was then hoping the second line would get instantiated to
>
>	go to card "r22a" in stack "abstracts"
>
>But that doesn't seem to be the case. I don't get an error message; 
>nothing at all happens.

There are at least three ways to solve this problem.

First, some of what was said isn't true.  If you have this handler in a
button --

on mouseUp
  get the name of this card
  go to it of stack "abstracts"
end mouseUp

-- you will get an alert box that says "Can't understand arguments to
command go".  Note also that 'go to card "XXX" in stack "YYY"' is bad syntax;
it has to be 'card "XXX" of stack "YYY"'. (OF, not IN, if that's too
subtle for you).

Here's solution number one (the easiest):

on mouseUp
  get the short name of this card
  go to cd it of "abstracts"
end mouseUp

Solutions two and three use the "do" command:

on mouseUp
  get the name of this card
  do "go to " & it & "of " & quote & "abstracts" & quote
end mouseUp

on mouseUp
  do "go to " & the name of this card & " of " & quote & "abstracts" & quote
end mouseUp

Solution three is simply a faster version of solution two.

The "do" command will often help you out of sticky situations like this
in which you want what is contained in a variable to be used in a
HyperCard command.



--
Conrad Halling
chh9@midway.uchicago.edu