View Full Version : Text File, Strings, ???
tbybee
12-10-2003, 11:14 PM
Can someone explain the whole string, table and text file thing. I'm creating a cd app that would list numerous unique numbers. I need to pull these unique numbers from a data file (.txt), so as not to have to update the actual AMS project. When the user mouses over the number, then field 2 of the record would show, when they click the number then it would open a separate document, which is stored in field 3. Is it possible to accomplish this using a text file? If so, can you give me easy instructions??? :-)
Thanks,
Tony
TJ_Tigger
12-11-2003, 09:43 AM
Where to start. A string is just that a bunch of characters strung together, where as a table is indexed. I think of a simple table as having two columns and multiple rows. Each row has an index and a value, like this.
index value
1 info one
2 info two
3 info three
A text file can be read into either a string or a table. When you read a text file into a string the entire contents of the text file become one potentially large string. When you read a text file into a table each line in the text file becomes a row in the table.
It sounds like you would want to use the action that will read your text file into a table. Once you get used to them tables are great to work with.
Depending on your data there are ways to read the information from a text file, extract the information you need and then to populate that information to your AMS project.
If your data were in this format in the text file:
number;;name;;filename.ext
123;;M&Ms;;m&ms.txt
234;;Mars;;mars.txt
345;;Milkyway;;milkyway.txt
456;;Reeses Pieces;;reesesp.txt
567;;Reeses Peanut Butter Cups;;rpbc.txt
678;;Three Muskateers;;3muskateers.txt
You could read this text file into table and then from that table read the line you want into a variable and extract the different pieces. Those pieces you could then use to populate your screen. Use the number to populate a Label on the screen and when you mouse over, you display the name portion of the string and when they click you open the text file in a paragraph object.
Play around and you will be suprised how quickly things come together.
There are a couple of posts on the forums that talk about tables and reading csv files into a table and how a table can have more than one column (a table within a table).
I hope that this helps to get you started.
Tigg
tbybee
12-12-2003, 06:48 AM
Hey Tigg. Thanks for the information. I'll start playing around with it and see what I can come up with. I appreciate the detail post.
Best Regards!!
AaronCooper
02-08-2004, 04:09 PM
Once you assign a variable one of the line how do you extract the right part?
123;;M&Ms;;m&ms.txt
like part 1, or 3?
Originally posted by TJ_Tigger
Where to start. A string is just that a bunch of characters strung together, where as a table is indexed. I think of a simple table as having two columns and multiple rows. Each row has an index and a value, like this.
index value
1 info one
2 info two
3 info three
A text file can be read into either a string or a table. When you read a text file into a string the entire contents of the text file become one potentially large string. When you read a text file into a table each line in the text file becomes a row in the table.
It sounds like you would want to use the action that will read your text file into a table. Once you get used to them tables are great to work with.
Depending on your data there are ways to read the information from a text file, extract the information you need and then to populate that information to your AMS project.
If your data were in this format in the text file:
number;;name;;filename.ext
123;;M&Ms;;m&ms.txt
234;;Mars;;mars.txt
345;;Milkyway;;milkyway.txt
456;;Reeses Pieces;;reesesp.txt
567;;Reeses Peanut Butter Cups;;rpbc.txt
678;;Three Muskateers;;3muskateers.txt
You could read this text file into table and then from that table read the line you want into a variable and extract the different pieces. Those pieces you could then use to populate your screen. Use the number to populate a Label on the screen and when you mouse over, you display the name portion of the string and when they click you open the text file in a paragraph object.
Play around and you will be suprised how quickly things come together.
There are a couple of posts on the forums that talk about tables and reading csv files into a table and how a table can have more than one column (a table within a table).
I hope that this helps to get you started.
Tigg
Corey
02-08-2004, 04:39 PM
Hi guys. Actually the better way is to store your data as a table in a .lua file, i.e. plain text but with a LUA extension, such as this:
myCDs = {
cd213672 = { artist = "Frank Sinatra", category = "Easy Listening", priceCode = "B"},
cd209837 = { artist = "Foday Musa Suso", category = "World Music", priceCode = "A"},
cd348754 = { artist = "The Rolling Stones", category = "Rock and Roll", priceCode = "C" }
};
And then simply use a require action to grab that data at runtime (use dofile if you wish to do it more than once) such as this:
require(_DesktopFolder.."\\data.lua");
Then you can just refer to your data like this
myCDs["cd348754"]["artist"]
And so forth, i..e to display that info in a dialog you would go:
Dialog.Message("Your Data", myCDs["cd348754"]["artist"]);
There's a training CD on this which I'm just finishing off now, this will be out soon and it's perfect for anyone who is not 100% comfortable using tables and functions to handle data. Basically this CD takes you from zero to 90 in 6.0. :)
Corey Milner
Creative Director, Indigo Rose Software (http://www.indigorose.com)
vBulletin® v3.8.4, Copyright ©2000-2009, Jelsoft Enterprises Ltd.