+ Reply to Thread
Results 1 to 11 of 11

Generate a 6 digits code based on filename and time of generation?

  1. #1
    Registered User
    Join Date
    08-17-2009
    Location
    England
    MS-Off Ver
    Excel 2003
    Posts
    31

    Generate a 6 digits code based on filename and time of generation?

    Morning,

    I need to enter a revision string into a file.
    Basically, I need to combine the filename and its generation time and then encode it into a string (i.e. a 6 digits HEX code or 6 digits using [0-9][a-z][A-Z]) so it would generate a pretty much unique revision number.

    So, is there any function that you can think of that would do something similar?
    If not, what is the best to tackle this?
    Generate a CRC or md5sum?

    What would be in your opinion a quick and efficient way to solve this tricky one?

    Thanks in advance.
    Ludo
    Last edited by Coume; 08-21-2009 at 04:43 AM.

  2. #2
    Forum Contributor
    Join Date
    02-23-2006
    Location
    Near London, England
    MS-Off Ver
    Office 2003
    Posts
    770

    re: Generate a 6 digits code based on filename and time of generation?

    Could you not just use a central register and increment the number by 1 each time? (ie. take the next available number?)
    If you find the response helpful please click the scales in the blue bar above and rate it
    If you don't like the response, don't bother with the scales, they are not for you

  3. #3
    Registered User
    Join Date
    08-17-2009
    Location
    England
    MS-Off Ver
    Excel 2003
    Posts
    31

    re: Generate a 6 digits code based on filename and time of generation?

    Unfortunately, I don't think so.

    The "Master file" will be used by all my colleagues to generate our local pricelist, selecting their own template on their own computer.
    Hence why I was thinking of using the template filename and the date/time to generate a unique string

  4. #4
    Forum Contributor
    Join Date
    02-23-2006
    Location
    Near London, England
    MS-Off Ver
    Office 2003
    Posts
    770

    re: Generate a 6 digits code based on filename and time of generation?

    The issue will be, the shorter your filename, the less chance of true 'uniqueness'.

    I would be tempted to have a filename made up something like this:

    Please Login or Register  to view this content.
    It will be a long filename, but it does mean that even if the unlikely event of different people in different locations save a file with the same name, on the same day of the same month of the same year, at the same hour, minute and second as each other, there are still 1000 possible different filenames they could end up with.

    It all depends how far you want to take things really. You might find just stamping it with the date and time to the nearest second is good enough for your purposes

  5. #5
    Registered User
    Join Date
    08-17-2009
    Location
    England
    MS-Off Ver
    Excel 2003
    Posts
    31

    re: Generate a 6 digits code based on filename and time of generation?

    Ok, I found a quite easy way to hash the filename

    Please Login or Register  to view this content.
    The results are always using [A-Z] in the following format:
    W-JMYAIK
    W-IBPTEN
    W-YOYCCE
    W-EAGHDF


    But now, I struggle to enter the UNIX timestamp to generate a unique quote number.
    If I use a function in a cell, it works great:
    =Quote(CONCATENATE("N:\Flash Memory\Volume pricing\Templates\England.xls",TEXT( NOW()*86400-DATE(1970,1,1)*24*60*60,"0000000000")))
    where the concatenation gives the following result N:\Flash Memory\Volume pricing\Templates\England.xls1250790305

    So ideally, I need to modify my quote function to simply use as follow:
    = quote("N:\Flash Memory\Volume pricing\Templates\England.xls")
    and it automatically adds the UNIX timestamp within the script

    Please Login or Register  to view this content.
    Any idea on how to add this bloody timestamp and concatenate it to the text variable

    Thanks in advance for any pointer/solution/etc.
    Ludo

  6. #6
    Forum Contributor
    Join Date
    02-23-2006
    Location
    Near London, England
    MS-Off Ver
    Office 2003
    Posts
    770

    Post re: Generate a 6 digits code based on filename and time of generation?

    Let me know how this works out for you:

    Please Login or Register  to view this content.
    You can test it in a saved workbook like this:
    Please Login or Register  to view this content.
    It gives me a message box with something like "Book1.xls1250726400"

  7. #7
    Forum Moderator Leith Ross's Avatar
    Join Date
    01-15-2005
    Location
    San Francisco, Ca
    MS-Off Ver
    2000, 2003, & 2010
    Posts
    23,258

    Re: Generate a 6 digits code based on filename and time of generation?

    Hello Coume,

    Here is another method. It creates a six digit hew value using the current date and time. Since this a UDF, you can use this on a worksheet as well.
    Please Login or Register  to view this content.
    Sincerely,
    Leith Ross

    Remember To Do the Following....

    1. Use code tags. Place [CODE] before the first line of code and [/CODE] after the last line of code.
    2. Thank those who have helped you by clicking the Star below the post.
    3. Please mark your post [SOLVED] if it has been answered satisfactorily.


    Old Scottish Proverb...
    Luathaid gu deanamh maille! (Rushing causes delays!)

  8. #8
    Registered User
    Join Date
    08-17-2009
    Location
    England
    MS-Off Ver
    Excel 2003
    Posts
    31

    Re: Generate a 6 digits code based on filename and time of generation?

    Quote Originally Posted by Phil_V View Post
    Let me know how this works out for you:

    Please Login or Register  to view this content.
    Thanks a lot Phil.

    I will have to wait tomorrow to test it once I'm at work as I only have Linux computers at home but looking at the code, it does seem to do exactly what I am after!

    Cheers,
    Ludo

  9. #9
    Registered User
    Join Date
    08-17-2009
    Location
    England
    MS-Off Ver
    Excel 2003
    Posts
    31

    Re: Generate a 6 digits code based on filename and time of generation?

    Quote Originally Posted by Leith Ross View Post
    Hello Coume,

    Here is another method. It creates a six digit hew value using the current date and time. Since this a UDF, you can use this on a worksheet as well.
    Please Login or Register  to view this content.
    Hello Leith,

    Thanks. That's an interesting code.

    I will have to think on how I could mix the time with a string (filename) and still be able to generate a 6-digit result but that will wait tomorrow back @ work

    Thanks
    Ludo

  10. #10
    Registered User
    Join Date
    08-17-2009
    Location
    England
    MS-Off Ver
    Excel 2003
    Posts
    31

    Re: Generate a 6 digits code based on filename and time of generation?

    Quote Originally Posted by Phil_V View Post
    Please Login or Register  to view this content.
    Morning Phil,

    After testing, it does not work.

    Every second when you generate the timestamp, the result should be different, but it always gives me the save result 1250812800

    This script did not consider the hour/min/sec and it was outputting Today's UnixStamp.

    Yesterday result was 1250726400 so if you add 24h x 60 min x 60s (86400); it gives the above result 1250812800

    So after a bit of tinkering, here is a working one for anyone interested

    Please Login or Register  to view this content.
    Thanks
    Ludo

  11. #11
    Forum Contributor
    Join Date
    02-23-2006
    Location
    Near London, England
    MS-Off Ver
    Office 2003
    Posts
    770

    Thumbs up Re: Generate a 6 digits code based on filename and time of generation?

    Ah yes, I forgot about the time element!

    Still, it gave you the chance to have a hands-on fiddle, and I still believe that's the best way to learn

    Glad you got it working.

+ Reply to Thread

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts

Search Engine Friendly URLs by vBSEO 3.6.0 RC 1