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