How do I Display Tab Delimited Text in a Table Field?

This lesson will show you how to display tab delimited text in a LiveCode table field.

What We Will Work With

What We Will Work With

On the left is a stack window with a button for selecting a text file (1) and a field for displaying the text file (2). The field is named "MyText".

On the right is a file (3) containing two columns of data. The left column is the name of a cheese (4) and the right column is a year (5). The two columns are separated by the TAB character (6). This is normally invisible, I have made it visible for the purposes of this lesson.

The Button Script

The Button Script

The button script is pretty straight forward. It simply prompts the user for a file, loads the file contents into a variable and then assigns the variable to the text property of the field.

==========

Copy & Paste

==========

on mouseUp
	answer file "Select text file"
	if the result is not "cancel" then
		put it into theFilePath
		put URL ("file:" & theFilePath) into theTabDelimitedText
		set the text of field "MyText" to theTabDelimitedText
	end if
end mouseUp

The Result

The Result

Selecting a file displays the text as seen above. Notice that both columns of data are displayed but the data is not separated into separate columns visually.

The tabStops Property

The tabStops Property

In a field table columns are defined by the presence of the TAB character in the text. You can control the spacing of columns by adjusting the tabStops property. Select the field (1) and open the Table pane of the property inspector (2). Notice that the Tab stops field is empty (3).

Enter 200 into the Tab stops field and press the Return or Enter key. Now the 2nd column is indented 200 pixels from the left of the field.

2 Comments

Trevix

I have problems setting the TextAlign in a tabbed field. Doesn't work and looks funny. Is that a bug?

Elanor Buchanan

Hi Trevix

It looks like it might be this bug

https://quality.livecode.com/show_bug.cgi?id=10615

I'll flag it with the Development Team. You can add your email address to the CC list on the report to be notified when the status of the bug changes.

Kind regards

Elanor

Add your comment

This site is protected by reCAPTCHA and the Google Privacy Policy and Terms of Service apply.