locked
Title of Created File Problem RRS feed

  • Question

  • Hello everyone.  Sorry I've been asking so many questions but I would like to get this program done :).  Ok, so...  My program (Import ID: XFK429) takes user input and writes a text document based on that input.  I need to make sure it is being named (today's date asked in program).txt.  But, it doesn't save the file so I can't double check.  Please help :).

     

    Thanks,

    Tom

    Monday, June 21, 2010 4:58 PM

Answers

  • The program actually works! The problem probably is on file naming. If you put date as xx\xx\xxxx then the directory will be having trouble creating new file with that name, because the file name cannot contain certain character such as '\'. So when I put just number, '6212010' it would create 6212010.txt in my Program.Directory folder which is : "C:\Users\[USERNAME]\AppData\Local\temp\HourRecorder\Peter".

    Additionally, you want to check the FIle.CreateDirectoriy lines because there is redundancy.  

    • Marked as answer by litdev Tuesday, June 22, 2010 11:05 PM
    Monday, June 21, 2010 5:57 PM

All replies

  • The program actually works! The problem probably is on file naming. If you put date as xx\xx\xxxx then the directory will be having trouble creating new file with that name, because the file name cannot contain certain character such as '\'. So when I put just number, '6212010' it would create 6212010.txt in my Program.Directory folder which is : "C:\Users\[USERNAME]\AppData\Local\temp\HourRecorder\Peter".

    Additionally, you want to check the FIle.CreateDirectoriy lines because there is redundancy.  

    • Marked as answer by litdev Tuesday, June 22, 2010 11:05 PM
    Monday, June 21, 2010 5:57 PM
  • Probably you are entering a date with "/" such as "21/6/2010", which will cause problems since when this is a path the "/"s will be interpreted as folders (that don't exist) and hence not save the file.

    See that in last post on one of your earlier threads .

    I would set the date by hand and not ask the user for it, since it is today, and form it with hiphens, not slashes.

    today = Clock.Year+"-"+Clock.Month+"-"+Clock.Day

    You also don't need to ask the user for the date at the end if it also today, in this case you could use Clock.Date since the "/" don't matter inside the file.

    You don't need the line Program.Delay(2786) - for dubegging purposes I would add TextWindow.WriteLine(namefile) after namefile is set to check what it is doing.

    Monday, June 21, 2010 6:01 PM
  • Awesome you guys rock!  But to make it easier I think it would be better to make the file name a random number, a serial.  How do I make the file produce a random number to use as the file name?
    Monday, June 21, 2010 6:10 PM
  • Use Math.GetRandomNumber(max) - experiment a bit - it gives a random number between 1 and max.  You can thne generate any kind of random number from this e.g. a 6 digit random number or fractional random numbers by applying some arithmatic to the result.

    I wouldn't use random numbers for file names - you could occasionally get a duplicate - especially if the random number generator seed is not reset.  This would over-write an earlier file - date is a good way to ensure unquiness and helps to order the files sensibly.

    A big number that is always guaranteed unique is Clock.ElapsedMilliseconds (milliseconds since 1900).  It has the advantage that multiple files generated on the same day would create new unique files.

    Monday, June 21, 2010 6:17 PM
  • Use Math.GetRandomNumber(max) - experiment a bit - it gives a random number between 1 and max.  You can thne generate any kind of random number from this e.g. a 6 digit random number or fractional random numbers by applying some arithmatic to the result.

    I wouldn't use random numbers for file names - you could occasionally get a duplicate - especially if the random number generator seed is not reset.  This would over-write an earlier file - date is a good way to ensure unquiness and helps to order the files sensibly.

    A big number that is always guaranteed unique is Clock.ElapsedMilliseconds (milliseconds since 1900).  It has the advantage that multiple files generated on the same day would create new unique files.

    Is there a way to make it reset so there are no duplicates?
    Monday, June 21, 2010 6:45 PM
  • No, a random number is random - it has equal chance to be anythnig, including a recent value.  You can check all of the values you have used in the past, but I would suggest using a date related number such as Clock.ElapsedMilliseconds or some other date related string that will ALWAYS be unique.
    Monday, June 21, 2010 6:58 PM
  • So it would be:

     

    today = Clock.ElapsedMilliseconds

    ?

    Monday, June 21, 2010 8:13 PM
  • Yep, if you want a guaranteed unique name - they also will be sequentially numbered by date/time.
    Monday, June 21, 2010 8:22 PM
  • Hello Tom,

    show program id FMH189. I think that is what you mean.

    Best regards

    Martmen

    Monday, June 21, 2010 10:15 PM