mike@pyrite.SOM.CWRU.Edu (Michael Kerner) (01/11/91)
Well, I trashed the message that some helpful soul sent out, so I don't know who he is, however, it really doesn't help. I don't want a global variable 'cause I want to reset the timer if something happens, which is why I wanted to trap myself in the idle. That is why the screen saver analogy is good - I want to keep counting until either my timer runs out or something happens. Any guesses? Second question: related to files: I'm importing a file edited by an IBM. The file is unformatted by the IBM editor, but two strange things happen with it. Here's the script ... open file "pathname:filename" read from file "pathname:filename" for soManyChars put it into card field "SoAndSo" ... At this point, lines 2 through last of the file have a block preceding them. To prove that all lines have a block in front I scroll to the bottom of the field (by the way, it's a scrolling field), and check the last few lines as well. When the scroll bar is at the bottom of the field, I type first char of line 2 of card field "SoAndSo" into the message box, and guess what? I get the real first character of that line! Oh, maybe HC doesn't recognize the block, so I scroll back up to the top, only now the blocks are ALL GONE, everywhere in the field! Figuring I can use this trick I add set the scroll of field "SoAndSo" to SomeHumungousNumber put the first char of line 2 of field "SoAndSo" into it set the scroll of field "SoAndSo" to 0 only that doesn't work. AAAAUUUUUUGGGGHHH!!! Help, folks! Is there an Apple/Claris tech reading this? I don't believe in UFO's, and I've been scripting in HC for almost three years, so I think I have a reasonable amount of experience with it. Any suggestions folks? Also, I'm using version 1.2.5 - no reason to upgrade to 2.0 until all the bugs (and XCMD's/XFCN's) are upgraded! Since both of these problems are related to new applications network stacks I'm upgrading for our users (about 200 of 'em), I'd appreciate any help... Mike. Body by Nautilus...Brain by Mattel (and don't let that hamper my credibility)
jk3t+@andrew.cmu.edu (Jonathan King) (01/11/91)
mike@pyrite.SOM.CWRU.Edu (Michael Kerner) writes: > Well, I trashed the message that some helpful soul sent out, so I don't know > who he is, however, it really doesn't help. It wasn't me; maybe you were thinking about Chaz Larson (who posted an answer)? And, as you'll see, it really *did* help if you extended the idea just a little bit. > I don't want a global variable > 'cause I want to reset the timer if something happens, which is why I wanted > to trap myself in the idle. But you can access a global variable where ever you want. So, suppose you want to reset the timer when the user pushes a button. Then you put the following in your mouseUp handler: on mouseUp global timer blahblahblah put the ticks into timer end mouseUp And similarly in the other handlers you have that respond to events you care about. In particular, you can reset the timer whenever the user types something by handling keydown messages. A slightly neater way (which will be a teeny bit slower) of doing the above is to write a special handler that resets/increments/checks the timer and call it when you need to. Thus: on mouseUp timer reset doYourDance pass mouseUp end mouseUp on idle timer checktimeout if the result is "timeout" then doYourIdleTask end if pass idle end idle --the following handler, timer, does several different things. --the first argument specifies what you want to do with your timer, --while the second (optional argument) is for resetting the cutoff --variable (how many ticks you want to wait until timing out) --Note that HC will just put empty into newvalue if you call timer --with only one arg. --Also note that returning from a non-function handler sets 'the --result', as demonstrated here. on timer command, newvalue global idletime --the ticks at the last action global cutoff --the number of ticks until overflow if command is "reset" then put the ticks into idletime return empty --everything's fine else if command is "newcutoff" then put newvalue into cutoff return empty else if command is "checktimeout" then if (idletime - the ticks) > cutoff then put the ticks into idletime return "timeout" else return empty end if --for the incredibly neat people in our audience else answer "Illegal argument to timer" with "OK" end if end timer This way, only one handler has access to the timer global variables, which is slightly neater if you're into information hiding, and the name of the handler is more obvious. > That is why the screen saver analogy is good - I > want to keep counting until either my timer runs out or something happens. > > Any guesses? I hope the above helps... > Second question: related to files: I'm importing a file edited by an IBM. > The file is unformatted by the IBM editor, but two strange things happen with > it. Here's the script > [deleted] I don't immediately understand the question, so I'll punt on this one. jking
jkc@Apple.COM (John Kevin Calhoun) (01/12/91)
In article <1991Jan10.170207.23311@usenet.ins.cwru.edu> mike@pyrite.SOM.CWRU.Edu (Michael Kerner) writes: > I'm importing a file edited by an IBM. >The file is unformatted by the IBM editor, but two strange things happen with >it. Here's the script >... >open file "pathname:filename" >read from file "pathname:filename" for soManyChars >put it into card field "SoAndSo" >... > >At this point, lines 2 through last of the file have a block preceding them. That block represents a linefeed character. Many computers expect a carriage return and a linefeed at the end of a line of text to tell them to start a new line. The Macintosh expects only a carriage return. HyperCard automatically strips linefeed characters from fields when they are closed for editing and written to the disk. >To prove that all lines have a block in front I scroll to the bottom of the >field (by the way, it's a scrolling field), and check the last few lines as >well. When the scroll bar is at the bottom of the field, I type >first char of line 2 of card field "SoAndSo" >into the message box, and guess what? I get the real first character of that >line! Oh, maybe HC doesn't recognize the block, so I scroll back up to the >top, only now the blocks are ALL GONE, everywhere in the field! When you clicked on the message box (or chose "Message" from the Go menu, or whatever you did to start typing into the message box), the field was closed for editing, and HyperCard performed its automatic stripping. That's why the linefeeds went away. >Figuring I can use this trick I add >set the scroll of field "SoAndSo" to SomeHumungousNumber >put the first char of line 2 of field "SoAndSo" into it >set the scroll of field "SoAndSo" to 0 > >only that doesn't work. >AAAAUUUUUUGGGGHHH!!! Quiet down, please. I'm trying to get some work done. :-) The trick isn't in the scrolling -- the trick is in getting the field to be closed for editing. You might try this script: lock screen -- no need to watch this open file "pathname:filename" read from file "pathname:filename" for 30000 put it into card field 1 select char 1 to 30000 of card field 1 -- opens the field for editing close file "pathname:filename" unlock screen -- has the side effect of closing the field for editing > Also, I'm using version 1.2.5 - no reason to upgrade >to 2.0 until all the bugs (and XCMD's/XFCN's) are upgraded! Well, I can think of lots of reasons. Reason number 1: IMHO, HyperCard 2.0v2 has fewer bugs than HyperCard 1.2.5. Kevin Calhoun HyperCard Team Apple Computer, Inc.