I want to read a text file line by line and put each word/phase into a variable. Each line has a series of words/phrases which are each separated by a comma(,). How do I do this. eg. line1=h,o,w,t,o line2=o,t,w,t,o after reading line 1: var1=h var2=o var3=w var4=t var5=o after reading line 2: var1=o var1=t var1=w var1=o var1=h
if you know how to do this please answer this topic or send the code to nimbus59@one.net.au
Posts: 448
Score: 0
Joined: 1/11/2005
From: USA
Status: offline
I'm still working on getting the array items broken out into variables. You can at least see how you can put the different letters in an array. My test.txt file had the following line: h,o,w,t,o.
Const ForReading = 1 Set objFSO = CreateObject("Scripting.FileSystemObject") Set objFile = objFSO.OpenTextFile("c:\temp\test.txt", ForReading)
arrTest = Split(objFile.ReadLine, ",") i = 0
For Each Letter In arrTest Wscript.Echo arrTest(i) i = i + 1 Next objFile.Close
You can assign the array items to variables as is but you would need to know how many Index Numbers the array is going to have ahead of time. This is done as so: Var1 = arrTest(0) Var2 = arrTest(1) etc.
Ok, I under stand the part about it being split up by commas ... but, why on earth would you want these words/phrases stored under static variables instead of doing something like putting it in a dynamic array?
I mean ... it can be done ... but inorder to have a diffrent variable for each word/phrase you would either have to know before hand how many words/phrases there where ... or you would have to write some totaly bogus script that writes another script based on how many words/phrases there are
here is a Basic FreeSyntax example
The code above follows no syntax and is just for short hand demonstration purposes ... but it shows that you can make a script that will take all the words/phrases and give the unique and static variable ... but why? Why would you want them all to be static variables ... you cant use them as static variables ... your best bet is putting them in an array and using them from there.