[comp.sys.mac.hypercard] Pasting text with tabs into a field: How is it done?

bjornl@milton.u.washington.edu (Bjorn Levidow) (10/04/90)

I'm trying to use the FileToField XCMD in the Dartmouth 3.1 collection
to put a text field with tab in it into a field.  The problem is that
all of the tabs get stripped out and I'm left with one long line of data.
I'd like to be able to replace the tabs with spaces or commas if possible.
I've tried to write a TabKey handler in the field, but that produces some
strange results.  Any and all help would be appreciated.  Thanks in advance.

===============================================================================
\  Bjorn Levidow                    |   Romance is unreal...it's the essence  /
\  Dept. of Psychology              |   of life, but not the reality of it.   /
\  University of Washington         |               ---Robyn Hitchcock        /
\  Seattle, WA  98195               |   It's mine!  All mine!                 /
\  bjornl@u.washington.edu          |   I'm independently thoughtful!         /
===============================================================================

jdevoto@Apple.COM (Jeanne A. E. DeVoto) (10/04/90)

In article <8561@milton.u.washington.edu> bjornl@milton.u.washington.edu
(Bjorn Levidow) writes:
>I'm trying to use the FileToField XCMD in the Dartmouth 3.1 collection
>to put a text field with tab in it into a field.  The problem is that
>all of the tabs get stripped out and I'm left with one long line of data.
>I'd like to be able to replace the tabs with spaces or commas if possible.

I'm not familiar with the FileToField XCMD; however, here is a way to
do what you want in HyperTalk:

  on getFile myFile               -- get contents of file with substitution
    open file myFile
    repeat until it is empty   -- in other words, until there ain't no more
      read from file myFile for 16834          -- maximum length
      repeat while it contains tab
        put "," into char offset(tab,it) of it -- substitute , for 1st tab
      end repeat
      put it after field "Destination"
    end repeat
    close file myFile
  end getFile

Note that the above handler will trigger an error if the file contains
more than 30,000 characters or so (the maximum number of characters for
a field). You may want to handle this in any number of ways -- disallowing
the transaction and emptying the field, or creating a new field to hold
the overflow, or whatever.
-- 
========= jeanne a. e. devoto ========================================
 jdevoto@apple.com     |  You may not distribute this article under a
 jdevoto@well.sf.ca.us |  compilation copyright without my permission.
______________________________________________________________________
 Apple Computer and I are not authorized      |        CI$: 72411,165
 to speak for each other.                     |

gwowen@gpu.utcs.utoronto.ca (George Owen) (10/05/90)

In article <45362@apple.Apple.COM> jdevoto@Apple.COM (Jeanne A. E. DeVoto) writes:
>    open file myFile
>    repeat until it is empty   -- in other words, until there ain't no more
>      read from file myFile for 16834          -- maximum length
>                                ^^^^^
>   ...etc
>
>Note that the above handler will trigger an error if the file contains
>more than 30,000 characters or so (the maximum number of characters for
           ^^^^^^

     ... um , I'm a little confised about the max number of chars per field

     ... as you see one number is 16 K and the other states about 30 K ...


     ... WHICH IS IT !!!!!!!   ARRRRRGGGHHHH      :-)


         - G -


***************************************************************************
*                 George Owen (gwowen@gpu.utcs.utoronto.ca)               *
* University of Toronto  -  Computing Services  -  Toronto , Canada       *
*                                                                         *
* " Individuality is ok as long as we're all doing the same thing "       *
*                                                                         *
*                                               - Frank Burns , M*A*S*H*  *
***************************************************************************

taylorj@yvax.byu.edu (10/06/90)

In <8561@milton.u.washington.edu>, bjornl@milton.u.washington.edu (Bjorn
Levidow) writes:

>I'm trying to use the FileToField XCMD in the Dartmouth 3.1 collection
>to put a text field with tab in it into a field.  The problem is that
>all of the tabs get stripped out and I'm left with one long line of data.
>I'd like to be able to replace the tabs with spaces or commas if possible.
>I've tried to write a TabKey handler in the field, but that produces some
>strange results.  Any and all help would be appreciated.  Thanks in advance.

HyperCard automatically strips all tabs from fields, but it wont bother them if
they're in a variable.  So the only way you can do anything with tabs is to
change them to something else BEFORE you put the text in a field.  Since the
FileToField XCMD goes straight from the file to the field it is useless if you
want to handle special characters.  I suggest you use the script Jeanne posted.


Jim Taylor
Microcomputer Support for Curriculum   |
Brigham Young University               |   Bitnet: taylorj@byuvax.bitnet
101 HRCB, Provo, UT  84602             |   Internet: taylorj@yvax.byu.edu

jdevoto@Apple.COM (Jeanne A. E. DeVoto) (10/06/90)

In article <1990Oct5.153806.22574@gpu.utcs.utoronto.ca>
gwowen@gpu.utcs.utoronto.ca (George Owen) writes:
>>    open file myFile
>>    repeat until it is empty   -- in other words, until there ain't no more
>>      read from file myFile for 16834          -- maximum length
>>                                ^^^^^
>>   ...etc
>>
>>Note that the above handler will trigger an error if the file contains
>>more than 30,000 characters or so (the maximum number of characters for
>           ^^^^^^
>     ... um , I'm a little confised about the max number of chars per field
>     ... as you see one number is 16 K and the other states about 30 K ...
>     ... WHICH IS IT !!!!!!!   ARRRRRGGGHHHH      :-)

16834 characters is the most you can read in from a file in one swoop;
so the repeat loop is needed in case the file is larger than 16K. 30000
is the maximum number of characters you can put in a field, so if the
file is larger than 30K, not all of it will fit in the field, and an error
will be generated when the field overflows.

Sorry about the confusion.
-- 
========= jeanne a. e. devoto ========================================
 jdevoto@apple.com     |  You may not distribute this article under a
 jdevoto@well.sf.ca.us |  compilation copyright without my permission.
______________________________________________________________________
 Apple Computer and I are not authorized      |        CI$: 72411,165
 to speak for each other.                     |

lin@diemen.utas.edu.au (Zhen Jie Lin) (10/10/90)

Bjorn Levidow write:

>I'm trying to use the FileToField XCMD in the Dartmouth 3.1 collection
>to put a text field with tab in it into a field.  The problem is that
>all of the tabs get stripped out and I'm left with one long line of data.
>I'd like to be able to replace the tabs with spaces or commas if possible.
>I've tried to write a TabKey handler in the field, but that produces some
>strange results.  Any and all help would be appreciated.  Thanks in advance.

The following is one way to copy data with tabs from external file into a text
field in HC, by replacing comma (or anything else) with tabs:

on doMenu x
  global finishDoMenu
  put false into finishDoMenu
  if x is "paste text" then tabToComma
  if finishDoMenu then exit doMenu
  pass doMenu
end doMenu

on tabToComma
  global finishDoMenu
  send "doMenu paste text" to hyperCard
  
  if the visible of the message then  --check whether pasting into msg box
    put the rect of the message into box
    put item 1 of box into x1
    put item 3 of box into x2
    put item 2 of box into y1
    put item 4 of box into y2
    
    put item 1 of the clickLoc into x
    put item 2 of the clickLoc into y
    if x>=x1 and x<=x2 and y>= y1 and y<=y2 then
      put true into finishDoMenu  --skip pasting data into msg box
      exit tabToComma
    end if
  end if
  
  put the Number of the selectedField into fldNo
  get the name of the selectedField
  if word 1 of it is "card" then           --paste data into cd fld
    repeat until offset(tab,cd fld fldNo) = 0
     put "," into char offset(tab,cd fld fldNo) of cd fld fldNo
    end repeat
  else                                     --paste data into bg fld
    repeat until offset(tab,fld fldNo) = 0
      put "," into char offset(tab,fld fldNo) of fld fldNo
    end repeat
  end if
  put true into finishDoMenu
*****

Hope this helps.

Zhenjie Lin
University of Tasmania
Australia
.