numbering 01 to 09

dan m's icon

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

Luke Hall's icon

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

lh

dan m's icon

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

Luke Hall's icon

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

Jean-Francois Charles's icon

An example with a clock:

Max Patch
Copy patch and select New From Clipboard in Max.

Jean-François.

Peter Castine's icon

dan m wrote on Wed, 25 March 2009 01:48forgot 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.

dan m's icon

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

Luke Hall's icon

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

Roman Thilenius's icon

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

Jean-Francois Charles's icon

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

Max Patch
Copy patch and select New From Clipboard in Max.

dan m's icon

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