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
Adding TAB Stops
Moderators: FourthWorld, heatherlaine, Klaus, kevinmiller, robinmiller
Re: Adding TAB Stops
Hi.
Try this:
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?
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
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?
-
- Posts: 25
- Joined: Mon Oct 18, 2010 6:32 pm
Re: Adding TAB Stops
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
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
Re: Adding TAB Stops
Hi Steven,
1.
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
Best
Klaus
1.
"tabStops" is a property of a Livecode field object and you cannot apply this to a file.Set the tabStops of ("file:" & MyText) to 240
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

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
...
Klaus