SoftTree Technologies SoftTree Technologies
Technical Support Forums
RegisterSearchFAQMemberlistUsergroupsLog in
Problem generating string with date timestamp

 
Reply to topic    SoftTree Technologies Forum Index » 24x7 Scheduler, Event Server, Automation Suite View previous topic
View next topic
Problem generating string with date timestamp
Author Message
rodney



Joined: 07 May 2010
Posts: 3
Country: United States

Post Problem generating string with date timestamp Reply with quote
I'm trying to create a string that will be used as file name that includes a date time stamp, but it isn't being generated propely.

Variable "formdate" contains the date time stamp, and has the correct value.

When I try to concatenate the actual file name, held in the variable "final", instead of the date timestamp being inserted, the text "formdate" is appended to variable.

Here's the code:

Quote:
dim cttime string
dim ctdate string
dim ArrngFile string
dim ArrngFileNew string

dim formdate string
dim ctdatetime string
dim HistFold string
dim Final string


now(cttime)
today(ctdate)

datetime(ctdate, cttime, ctdatetime)
format(ctdatetime, "mmddyyyy_hhmmss", formdate)

ConcatEx("\\\\", "Server", "\\EAS\\Server\\Log\\", HistFold)

ConcatEx(HistFold, "ArrngFileNew", "_", formdate,final )


Here's what actually happens:

"formdate" is set to a date timestamp, like "05072010_161028", as expected.

After the last concatenation, "final" should be set to: "\\Server\EAS\Server\Log\ArrngFileNew_ 05072010_161028"

However, it's not, it's set to: "\\Server\EAS\Server\Log\ArrngFileNew_ formdate".

For the life of me I don't know why.

Thanks in advance.
Fri May 07, 2010 4:18 pm View user's profile Send private message
SysOp
Site Admin


Joined: 26 Nov 2006
Posts: 7952

Post Reply with quote
Code:
// this code sample is for Server, FileName, and ArrngFileNew declared as variables and not constant strings as in the original example

Dim Server string
Dim FileName string
Dim ArrngFileNew string

// ... somewhere we populate Server and ArrngFileNew variables
// ...

ConcatEx( "\\\\", Server, "\\EAS\\Server\\Log\\", ArrngFileNew, "_@T"mmddyyyy_hhmmss"", FileName )
// display results
MessageBox( FileName )


And in case Server and ArrngFileNew are not variables and known in advance, the entire script can be reduced to 1 line
Code:
MessageBox( "\\\\Server\\EAS\\Server\\Log\\ArrngFileNew_@T"mmddyyyy_hhmmss"" )

Fri May 07, 2010 5:11 pm View user's profile Send private message
rodney



Joined: 07 May 2010
Posts: 3
Country: United States

Post Reply with quote
I started off using this technique, "@T"mmddyyyy_hhmmss", but it didn't work the way I expected it to either.

When the script starts it makes the date time substitution, and my first file is created with the date timestamp as expected. However, when I attempt to create a second file, the script continues to use the date timestamp it generated the first time, causing me to recieve a file already exists error. Is there something I need to do to cause it to generate a new date timestamp using this method?

The weird thing is we are using the code I posted originally in another job, and it works in that job.

Any other suggestions?
Mon May 10, 2010 9:40 am View user's profile Send private message
SysOp
Site Admin


Joined: 26 Nov 2006
Posts: 7952

Post Reply with quote
That's the expected behavior. Macro-variables are substituted with the their values before the script run is started. If you use multiple references to date/time macro-variables in the same script, they will all get the same value.

If you need real-time values then you original approach is correct; although you shouldn't expect different values. The time resolution here using the specified format is 1 second. The script can run fast enough to produce the same time values. To avoid that issue, add Wait(1) before consecutive Now(...) call.

Here is your original code modified. Don't enclose variable names in double quotes.

Code:
dim cttime string
dim ctdate string
dim ArrngFile string
dim ArrngFileNew string

dim formdate string
dim ctdatetime string
dim HistFold string, "\\\\Server\\EAS\\Server\\Log\\"
dim Final string


now(cttime)
today(ctdate)

datetime(ctdate, cttime, ctdatetime)
format(ctdatetime, "_mmddyyyy_hhmmss", formdate)

ConcatEx(HistFold, ArrngFileNew, formdate, final )

Mon May 10, 2010 9:59 am View user's profile Send private message
rodney



Joined: 07 May 2010
Posts: 3
Country: United States

Post Reply with quote
Thanks, your code worked perfectly, although I don't see any significant difference between what you did and what I did. And while the variable name was enclosed in double quotes, it should just be interpreted as a string, right?

Although, the bizarre thing is now I can run the original code I posted as is and it works fine.

At any rate, thanks a lot!
Mon May 10, 2010 10:20 am View user's profile Send private message
Display posts from previous:    
Reply to topic    SoftTree Technologies Forum Index » 24x7 Scheduler, Event Server, Automation Suite All times are GMT - 4 Hours
Page 1 of 1

 
Jump to: 
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum


 

 

Powered by phpBB © 2001, 2005 phpBB Group
Design by Freestyle XL / Flowers Online.