Forums > MaxMSP

numbering 01 to 09

March 24, 2009 | 11:05 pm

Hi,

apologies for such a silly question, but I have been trying to get a numbering series from 01 to 09, and all I am getting is 1, 2 … 9 (without the 0). I am using these numbers as part of a file naming process. The 0 is important since, as you might know, windows presents files with a 0 (01, 02 etc) before those without it, within the same folder, let’s say. This is important in my application…
I’ve tried sending the incoming numbers (1 to 9) to sprintf 0%ld, expecting to get 01 to 09 at the other end, but it’s not working.. I’ve also tried other methods…How can this be done?
Thanks
d


March 24, 2009 | 11:33 pm

Try [sprintf symout %.2d]. It is documented in the "more examples" subpath in the [sprintf] help file.

lh


March 25, 2009 | 12:48 am

Thanks,
forgot to say i am still using 4.6.3, perhaps you refer to the help file on max 5? I cannot find a ‘more examples’ subpatch in the sprintf help file…
d


March 25, 2009 | 11:33 am

Ah, well it is there in the max 5 helpfile, it must be a new addition. If I remember correctly the functionality is still there in 4.6 even if it isn’t mentioned in the help file.

lh


March 25, 2009 | 12:35 pm

An example with a clock:

– Pasted Max Patch, click to expand. –

Jean-François.


March 25, 2009 | 2:53 pm
dan m wrote on Wed, 25 March 2009 01:48
forgot to say i am still using 4.6.3, perhaps you refer to the help file on max 5? I cannot find a ‘more examples’ subpatch in the sprintf help file…

The More Examples subpatch may be new in Max 5, but the sprintf functionality isn’t.

It’s unfortunate that the reference documents assume familiarity with sprintf syntax. Although this syntax is used in literally dozens of programming languages, a lot of people come to Max with zero programming background. However, if you poke around a bit, you will probably find plenty of sample patches using the technique.

I’ve also just written a list of sources for sprintf syntax on the ‘check for decimal places’ thread.


March 25, 2009 | 4:02 pm

Thanks,

ok, I have installed the demo version of max 5, just to check the help file. I have also opened the clock patch. Dont know if I am doing something wrong, but while it works in max 5, it does not work in max 4.

Furthermore, the help file includes ‘toto’ [sprintf TOTO%.2d]. If I get rid of the word ‘toto’ in max 5, it does not work (it outputs 1, 2 etc).

The clock works fine in max 5, but the same expression in max 4, something like [sprintf set %.2d], does not output the 0 in front of any number…If I add ‘toto’, it works… So it seems the string must begin with something other than 0?

Am I doing something wrong? Has somebody tried this on max 4.x?

I was hoping to get this done without getting into spritnf syntax. It’s just a zero por dios!
d


March 25, 2009 | 4:19 pm

Max automatically removes leading zeroes so you have to use the "symout" argument like thus [sprintf symout %.2d] to make it output a symbol which you can view in a message box rather than a number box.

lh


March 25, 2009 | 5:06 pm

[110.concat- 0] will also do it.


March 25, 2009 | 6:47 pm

And maybe something to try with [combine] (Max5 only):

– Pasted Max Patch, click to expand. –

March 25, 2009 | 8:51 pm

Many thanks!
symout does the job : [sprintf symout %.2d] in max 4.6.3
There was an older version of max in my pc which didnt like symout. Now it’s fine…

d


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