Forums > MaxMSP

Problems writing a list of numbers separated by commas to text file

April 10, 2009 | 4:43 pm

Hi.

I am trying to use the text object to output data to a text file, which will later be read by a visual basic script in excel. HOwever the vba part is not important for this question, I am just expplaining why i need the data to be in a certain format.

i will have 5 numbers between 1 and 20 that will be changing due to certain things in the patch and I need to figure out how I can send these numbers in a list separated by commas to the text object.

say the numbers are 5 4 8 7 3, i would need 5, 4, 8, 7, 3 to be sent to the text file, and then say the numbers changed to 5 4 8 7 4 I would then need 5, 4, 8, 7, 4 to be sent to the text file. I am thinking of having the message being sent to the clear object to clear the text file and then to the text object and then to the write object so that each time the data is changed the old data gets deleted and then the new data gets entered, although if there is a way how it would only replace the data in the file that is different that woul dbe even better.

I know that if i had the numbers being generated and sent to a number box that would create the list of numbers that I want, i just do not know how to then put them into a list separated by commas. I have tried using the pack object but it just seems to create a list without commas. I have also tried to use the append object with a commas after so it sets out the number followed by a comma but that doesn’t appear to work either. Does anyone know how i can do this?

Thanks very much in advance!



baz
April 10, 2009 | 5:06 pm

I had a quick look and don’t see any text storing objects that don’t remove commas. The help for message shows how to create a message with commas, but that doesn’t help you much.

I used to use bbedit for such text-mangling operations. Haven’t used it in ages, but I assume it will work. It is only OSX:

http://www.barebones.com/products/bbedit/


April 10, 2009 | 5:08 pm

Try using [sprintf] and escaping the comma using a like in the patch below. You could also get the [trigger] to send a "write some/destination/file.csv" message to save it to disk.

lh

– Pasted Max Patch, click to expand. –


baz
April 10, 2009 | 5:21 pm

Hey lh,
That "symout" thing in sprintf would have come in handy in my past. Gotta look at help patches more carefully I guess.
Cheers,
b


April 10, 2009 | 5:51 pm

Mate!!! Thank you so much, I am so happy now! All about the bristol massive!!!


Viewing 5 posts - 1 through 5 (of 5 total)