PDA

View Full Version : reading "on" or "off" in a text file


Dmaxer
08-26-2005, 05:47 PM
I’m trying to read in data from a text file
If I have the data in the format below with just “On” it works fine

46080 On ch=1 n=65 v=0
46080 On ch=1 n=65 v=100
61440 On ch=1 n=65 v=0

But I now need the change my code so it will read this format


15360 Off ch=1 n=65 v=0
15360 On ch=1 n=65 v=100
30720 Off ch=1 n=65 v=0
30720 On ch=1 n=65 v=100

Heres part of the code Im using


QTime = readValue dpFileStream -- Time = ticks
nop = readChars dpFileStream 1 -- dont use this data
nop = readChars dpFileStream 1 -- dont use this data
nop = readChars dpFileStream 1 -- dont use this data
nop = readChars dpFileStream 1 -- dont use this data
nop = readChars dpFileStream 1 -- dont use this data
nop = readChars dpFileStream 1 -- dont use this data
nop = readChars dpFileStream 1 -- dont use this data
nop = readChars dpFileStream 1 -- dont use this data
nop = readChars dpFileStream 1 -- dont use this data
nop = readChars dpFileStream 1 -- dont use this data
note = readValue dpFileStream -- Note value
nop = readChars dpFileStream 1 -- dont use this data
nop = readChars dpFileStream 1 -- dont use this data
notevol = readValue dpFileStream -- note volume value


before I was just using the last value for on off info but now I need to know
if there’s a On or Off in the line

Can this be done , if so can someone help me out Please

Thanks for Reading

shibumenon
08-27-2005, 08:38 AM
curTime = #()
onnn_offf = #()
chVal = #()
nValue = #()
vValue = #()

dpFileStream = openfile "c:\\testCGTalk.txt"

i = 1

while (not eof dpFileStream) do
(
CurTime[i] = readValue dpFileStream
onnn_offf[i] = readchars dpFileStream 3
if onnn_offf[i][3] == " " then onnn_offf[i] = substring onnn_offf[i] 1 2
skiptoString dpFileStream "ch="
chVal[i] = readValue dpFileStream
skiptoString dpFileStream "n="
nValue[i] = readValue dpFileStream
skiptoString dpFileStream "v="
vValue[i] = readValue dpFileStream

i += 1
)



This code should store all the values you require including the on-offs.
I've used array variables to store them. so that you can retreive and store values from multiple lines in one go. You could instead use float and string variables for single line values.

hope that helps
- shibu

Dmaxer
08-27-2005, 12:48 PM
thanks aaaachoooo I will give that a go :)

CGTalk Moderation
08-27-2005, 12:48 PM
This thread has been automatically closed as it remained inactive for 12 months. If you wish to continue the discussion, please create a new thread in the appropriate forum.