PDA

View Full Version : Help for noob desperately needed please


soundsgood
04-03-2009, 03:21 AM
Hello All,

I'm having serious problems trying to do something most of you will probably find simple,
The end result I am trying to achieve is to read a text file to table or string, take the text from an input, find the row in the text file matching the input text and display the whole row in a paragraph box.

Here is what I have so far, I am a more or less total noob, and this is probable rubbish but I have been trying for days.


nMac = Input.GetText("Input1")


tFileContents = TextFile.ReadToTable("AutoPlay\\Docs\\master-data-file.txt")




for nMac in tFileContents do
count = Table.Count(tFileContents)
for loop = 1, count do

result = String.Find(tFileContents[loop], nMac, 1, false);
if result ~= -1 then
result1 = Table.Remove(tFileContents, loop, result);
Paragraph.SetText("Paragraph1", result1);
end
end
end






if result ~= 0 then
Paragraph.SetText("Paragraph1" , "Not Yet Registered");


end


What I'm getting is that it kind of works then throws me an error at the end that String.Find(tFileContents[loop], is wrong........

and I have simply run out of ideas

Thankyou
J

Desrat
04-03-2009, 03:42 AM
Try this...

--get string from input
nMac = Input.GetText("Input1")

--read file to table
tFileContents = TextFile.ReadToTable("AutoPlay\\Docs\\master-data-file.txt")

--for loop to run through the table
for i,v in tFileContents do

--check if the line contains the same as the input field
nFind = String.Find(tFileContents[i], nMac, 1, false);

--if nFind is not -1 then it was found and this is the line we want
if nFind ~= -1
Paragraph.SetText("Paragraph1", tFileContents[i]);

--break out of the loop
break;

else --line doesnt contain the same info
Paragraph.SetText("Paragraph1" , "Not Yet Registered");


end

end

soundsgood
04-03-2009, 05:45 AM
Fantastic,

Thankyou so much, and for explaining how you did it too

Thanks again :yes:yes:yes