PDA

View Full Version : Why dont work?


sermak
03-15-2008, 08:18 AM
I write to a textFile.. i now i want read the names in the txt, and put inside the one ComboBox... e assumes the names...


on Show
result = TextFile.ReadToString("E:\\teste.txt");
result1 = ComboBox.AddItem("ComboBox3", result, "")

stickck
03-15-2008, 10:09 AM
in your text file, make each item you want in your combobox / listbox as a new line.

item1
item2
item3
etc...

then when you import the text file to a table.

tResult = TextFile.ReadToTable("E:\\teste.txt");
for i, j in tResult do
ComboBox.AddItem("ComboBox3", j,"" )
end


if you get a listing of numbers in the combobox, then change the j to an i on the line
ComboBox.AddItem("ComboBox3", i, "")

hope that helps

chris

Intrigued
03-15-2008, 10:10 AM
Here is an example of populating (filling up) a ComboBox with the contents from a text (.txt) file.

Note: That the contents is saved as a table (for each line of text in the file it gets an index ("i" in my example below), e.g. 1, 2, 3 and the line of text is stored in the value ("v" in my example below), e.g. "Hey all".

This code was put in the On Show event area for my example:

tblTextFile = TextFile.ReadToTable("C:\\Documents and Settings\\bubba\\Desktop\\test.txt")

for i,v in tblTextFile do
ComboBox.AddItem("ComboBox1", v)
end

stickck
03-15-2008, 10:18 AM
Here is an example of populating (filling up) a ComboBox with the contents from a text (.txt) file.

Note: That the contents is saved as a table (for each line of text in the file it gets an index ("i" in my example below), e.g. 1, 2, 3 and the line of text is stored in the value ("v" in my example below), e.g. "Hey all".

This code was put in the On Show event area for my example:

tblTextFile = TextFile.ReadToTable("C:\\Documents and Settings\\bubba\\Desktop\\test.txt")

for i,v in tblTextFile do
ComboBox.AddItem("ComboBox1", v)
end

There you go!

two answers at the same time with the same results

chris

Intrigued
03-15-2008, 10:23 AM
It's interesting too... to look back in time when I was looking for answers like those myself in 2003, early 2004. Though I tried to ask as little as possible and learn on my own, when folks like Worm and the I.R. dev/support team did help me with something, boy what a relief and I still appreciate those times of help.

I feel, "the person that thinks he/she knows it all, still has twice as far to go as the one that knows they do not know it all." (random blurb ;-))

sermak
03-15-2008, 10:30 AM
stickck and Intrigued, thanks for your help... really works...
yes.. is the other way to same result.. thanks.. :D

Intrigued
03-15-2008, 10:33 AM
stickck and Intrigued, thanks for your help... really works.

Intrigued, i put in my project the code that stickck show me.. because i dont no why i cant understand very well you code.. sorry, but thanks for you give other solution for my problem

No problem and I undestand. Which ever you feel comfortable with and ultimately gets the job completed properly.

*tips hat to stickck* :-)

sermak
03-15-2008, 10:41 AM
i change my comment, because i see with more attention and your code is not complicated... we complicated everything when the things is so easy... lol :D

rexzooly
03-15-2008, 11:58 AM
Intrigued hey can you explain a little how it works

if each line is a index but where dose it get the list show to the user
i feel like a twit now as some other things way hire then this i can do bit
a lot of think just go out of my head can you do me a simple example when
you get some free time please.


thanks.:yes

Intrigued
03-15-2008, 08:30 PM
Np.... I'm still learning myself.

Lets say you have three lines in a plain old text (.txt) file:

Hey all
How is the weather your way?
Lets go and do some ATVing!

Now, lets take a look at that code I posted earlier today:


-- This line takes each line in the text file and puts it into an AMS (LUA) table. And each line of text has a index number (1 for the first line, 2 for the second line, and 3 for the third line).

tblTextFile = TextFile.ReadToTable("C:\\Documents and Settings\\bubba\\Desktop\\test.txt")


-- In the 'for..do' portion of the loop, we are going to do something for each
-- line of text. 1= index number and Hey all=value (i,v in my loop)
-- 1 Hey all
-- 2 How is the weather your way?
-- 3 Lets go and do some ATVing!
for i,v in tblTextFile do

-- Now, we add the value (v=Hey all, etc.) to the combobox object
-- for each pass through the loop.
-- The loop goes three times because there is only three lines of text
ComboBox.AddItem("ComboBox1", v)
end



I hope that helps and was what you were after.

rexzooly
03-15-2008, 08:55 PM
Np.... I'm still learning myself.

Lets say you have three lines in a plain old text (.txt) file:

Hey all
How is the weather your way?
Lets go and do some ATVing!

Now, lets take a look at that code I posted earlier today:


-- This line takes each line in the text file and puts it into an AMS (LUA) table. And each line of text has a index number (1 for the first line, 2 for the second line, and 3 for the third line).

tblTextFile = TextFile.ReadToTable("C:\\Documents and Settings\\bubba\\Desktop\\test.txt")


-- In the 'for..do' portion of the loop, we are going to do something for each
-- line of text. 1= index number and Hey all=value (i,v in my loop)
-- 1 Hey all
-- 2 How is the weather your way?
-- 3 Lets go and do some ATVing!
for i,v in tblTextFile do

-- Now, we add the value (v=Hey all, etc.) to the combobox object
-- for each pass through the loop.
-- The loop goes three times because there is only three lines of text
ComboBox.AddItem("ComboBox1", v)
end



I hope that helps and was what you were after.




Thanks that really dose help :) might have to play around this at some
point.

:yes

top dollor

stickck
03-15-2008, 11:11 PM
*tips hat to stickck* :-)

I learned from the best.... You guys here on the forum! My first question ever on the forum was extremely stupid now looking back. Corey helped me out back then. Thanks for the kudos Intrigued:D

One of the best things about AMS is that your can get the same results with several different scripts.

Here's another way to fill your combobox...

results = TextFile.ReadToTable(_SourceFolder.."\\AutoPlay\\Docs\\Stuff.txt")
min = 1
max = Table.Count(results)
for count = min, max do
ComboBox.AddItem("ComboBox1", results[count], "")
end


or even just keep the table in LUA format in your txt file and use the LoadScript like this...

your text file will have this in it....

tList = {}
tList[1] = "First Item"
tList[1] = "Middle Item"
tList[1] = "Last Item"


Or this...

tList = {"First Item", "Middle Item", "Last Item"}

Then use this to run the lua script into your app....

Application.LoadScript(_SourceFolder.."\\AutoPlay\\Docs\\Your_LUA_Script_File.LUA")

A LUA file is just a TXT file with LUA Scripts in it. You can open them with Wordpad / Notepad.

The cool thing about this last option (Application.LoadScript()) is that you can add other script to the file later on without having to change your app.

I guarantee that there are other ways yet to do this.

Later

Chris