Adding TAB Stops

LiveCode is the premier environment for creating multi-platform solutions for all major operating systems - Windows, Mac OS X, Linux, the Web, Server environments and Mobile platforms. Brand new to LiveCode? Welcome!

Moderators: FourthWorld, heatherlaine, Klaus, kevinmiller, robinmiller

Post Reply
stevewhyte
Posts: 25
Joined: Mon Oct 18, 2010 6:32 pm

Adding TAB Stops

Post by stevewhyte » Thu May 01, 2014 2:33 pm

Hi,

I have created a LiveCode program which sends the result of a search to a text file which is saved in a location of the users choice.

Is it possible to add TabStops to the data placed into the text file so it appears neatly in columns when the saved text file is opened up?

My code is below and the 3rd last line shows what I am attempting to do. The data displays ok in the Output2 field but I want the data neatly displayed in a text file using tabStops. Not too sure if this is possible but any help would be gratefully appreciated.

Many thanks,

Steven



Global OutputContents, MyText, ArrayCountry, ArrayCapital, ArrayPopulation, Position

on mouseUp
initialise
write_file OutputContents, MyText, ArrayCountry, ArrayCapital, ArrayPopulation, Position
end mouseUp

on initialise
// Initialise the variables to null
Put "" into OutputContents
Put "" into MyText
end initialise


on write_file @OutputContents, @MyText, ArrayCountry, ArrayCapital, ArrayPopulation, Position
// Ask the user to choose a where they want to save their file
Ask file "Please choose a where you want to save the file: "
IF the result is not "cancel" THEN
Put it into MyText
END IF

// Put the search result of the output field into a block variable called OutputContents
Put "Country" & TAB & "Capital City" & TAB & "Population" into line 1 of OutputContents
Put ArrayCountry[position] & TAB & ArrayCapital[position] & TAB & ArrayPopulation[position] into line 2 of OutputContents

// Put the contents of the variable into the file variable MyText
Put OutputContents into URL ("file:" & MyText)
Set the tabStops of ("file:" & MyText) to 240
Answer "File Saved"
end write_file

dunbarx
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 10309
Joined: Wed May 06, 2009 2:28 pm

Re: Adding TAB Stops

Post by dunbarx » Thu May 01, 2014 3:06 pm

Hi.

Try this:

Code: Select all

on mouseup
put "AA" & tab & "BB" & tab & "CC" & return & "DD & tab & "EE" & tab & "FF" into temp
set the clipBoardData to temp
end mouseUp
Now open an excel spreadsheet, or whatever, and paste into a cell.

Craig Newman
EDIT.

I did not read your handler til after I posted. It seems you already know you can insert a tab character into a string.

But perhaps the problem is that you have your tab delimited data in line 2 of the variable, but are writing the entire variable? What happens if you only output line 2?

stevewhyte
Posts: 25
Joined: Mon Oct 18, 2010 6:32 pm

Re: Adding TAB Stops

Post by stevewhyte » Thu May 01, 2014 3:20 pm

Hi Craig,

Thanks for your reply. I'm essentially writing to a blank text file. In the code, the file is created the data from the LiveCode field is added to the text file and then it is saved and closed.

However, when I open it, the data isn't tabulated and is all over the place.

I tried your line of code to no avail.

If you have any other suggestions, that would be appreciated...

Many thanks,

Steven

Klaus
Posts: 14182
Joined: Sat Apr 08, 2006 8:41 am
Contact:

Re: Adding TAB Stops

Post by Klaus » Thu May 01, 2014 3:26 pm

Hi Steven,

1.
Set the tabStops of ("file:" & MyText) to 240
"tabStops" is a property of a Livecode field object and you cannot apply this to a file.

2. Nevertheless you cannot define the actual tab width that will appear when you open
a "simple" text file in any TEXT editor.

As Craig said, you need to add the tabs to your text BEFORE you write it to file.

3. Better script something like this to avoid unpleasant surprises 8)

Code: Select all

...
Ask file "Please choose a where you want to save the file: "
  IF the result = "cancel" THEN
     ## Do NOT carry on in this case!
     exit to top
  END IF
...
Best

Klaus

Post Reply