Problem with VB Script

I have a script that should rename a file I uploaded. Goes like this:

If (CStr(Request.QueryString("GP_upload")) <> "") Then
  Dim REUF_renameMask
  Dim sTS
  sTS=sTimeStamp
  REUF_renameMask = DoTrim(Session("FirmId"),2)+"_"+DoTrim(Session("QnrId"),2)+ "_"+sTS+"_"+"##name##"+".##ext##"
  RenameUploadedFiles pau_thePath, pau_nameConflict, REUF_renameMask
end if

--

All of it works fine other than the sTS portion of it which should add the time stamp. Here is my script for it, which works just fine. Only the timestamp for some reason is not being added. Perhaps the syntax in the rename mask is incorrect?

-- This works fine --

Function GetMmDdYyyyHhMmSs(sDate)
      GetMmDdYyyyHhMmSs=""
      If sDate="" OR IsNull(sDate) OR IsEmpty(sDate) Then Exit Function
      If Not IsDate(sDate) Then Exit Function
      Dim sRetVal,sVal
      sRetVal=""
      sVal=DatePart("m",sDate)
      If Len(sVal)=2 Then sRetVal=sVal Else sRetVal="0"&sVal End If
      sVal=DatePart("d",sDate)
      If Len(sVal)=2 Then sRetVal=sRetVal&sVal Else sRetVal=sRetVal&"0"&sVal End If
      sRetVal=sRetVal&DatePart("yyyy",sDate)
      sVal=DatePart("h",sDate)
      If Len(sVal)=2 Then sRetVal=sRetVal&sVal Else sRetVal=sRetVal&"0"&sVal End If
      sVal=DatePart("n",sDate)
      If Len(sVal)=2 Then sRetVal=sRetVal&sVal Else sRetVal=sRetVal&"0"&sVal End If
      sVal=DatePart("s",sDate)
      If Len(sVal)=2 Then sRetVal=sRetVal&sVal Else sRetVal=sRetVal&"0"&sVal End If
      GetMmDdYyyyHhMmSs=sRetVal
End Function
Dim sOldFileName,sNewFileName,sTimeStamp,oFSO
sTimeStamp=GetMmDdYyyyHhMmSs(Now)
Session("attchfilename")=""
LVL 1
AleksAsked:
Who is Participating?

[Product update] Infrastructure Analysis Tool is now available with Business Accounts.Learn More

x
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

Big MontyWeb Ninja at largeCommented:
you're using vbScript, but the line below is using javascript:

REUF_renameMask = DoTrim(Session("FirmId"),2)+"_"+DoTrim(Session("QnrId"),2)+ "_"+sTS+"_"+"##name##"+".##ext##"

should be

REUF_renameMask = DoTrim(Session("FirmId"),2)&"_" & DoTrim(Session("QnrId"),2) & "_"&sTS&"_"+"##name##"&".##ext##"
Martin LissOlder than dirtCommented:
Where do the last 3 lines appear? They should be in a sub or function rather then by themselves as they appear to be.
AleksAuthor Commented:
I used :     REUF_renameMask = DoTrim(Session("FirmId"),2)&"_" & DoTrim(Session("QnrId"),2) & "_"&sTS&"_"+"##name##"&".##ext##"

as recommended but the sTS part is not being added to the name.

I end up with something like this:  2_1407__Todo.txt

Which is the firmid + Qnrid + name + ext ... missing the sTS
Become a CompTIA Certified Healthcare IT Tech

This course will help prep you to earn the CompTIA Healthcare IT Technician certification showing that you have the knowledge and skills needed to succeed in installing, managing, and troubleshooting IT systems in medical and clinical settings.

Big MontyWeb Ninja at largeCommented:
missed a plus sign, essentially, all plus signs should be converted to ampersign's. try:

REUF_renameMask = DoTrim(Session("FirmId"),2)&"_" & DoTrim(Session("QnrId"),2) & "_"&sTS&"_"&"##name##"&".##ext##"
AleksAuthor Commented:
That's a negative   :(
Big MontyWeb Ninja at largeCommented:
where in the page is the IF statement being run, before or after the code below:

Dim sOldFileName,sNewFileName,sTimeStamp,oFSO
sTimeStamp=GetMmDdYyyyHhMmSs(Now)
Session("attchfilename")=""
AleksAuthor Commented:
I tried showing this up on my ASP page:  <%=response.write(sTS)%>

Shows nothing. So maybe no value is being retrieved from the variable above ?
AleksAuthor Commented:
This is the full script:

---

Function GetMmDdYyyyHhMmSs(sDate)
      GetMmDdYyyyHhMmSs=""
      If sDate="" OR IsNull(sDate) OR IsEmpty(sDate) Then Exit Function
      If Not IsDate(sDate) Then Exit Function
      Dim sRetVal,sVal
      sRetVal=""
      sVal=DatePart("m",sDate)
      If Len(sVal)=2 Then sRetVal=sVal Else sRetVal="0"&sVal End If
      sVal=DatePart("d",sDate)
      If Len(sVal)=2 Then sRetVal=sRetVal&sVal Else sRetVal=sRetVal&"0"&sVal End If
      sRetVal=sRetVal&DatePart("yyyy",sDate)
      sVal=DatePart("h",sDate)
      If Len(sVal)=2 Then sRetVal=sRetVal&sVal Else sRetVal=sRetVal&"0"&sVal End If
      sVal=DatePart("n",sDate)
      If Len(sVal)=2 Then sRetVal=sRetVal&sVal Else sRetVal=sRetVal&"0"&sVal End If
      sVal=DatePart("s",sDate)
      If Len(sVal)=2 Then sRetVal=sRetVal&sVal Else sRetVal=sRetVal&"0"&sVal End If
      GetMmDdYyyyHhMmSs=sRetVal
End Function
Dim sOldFileName,sNewFileName,sTimeStamp,oFSO
sTimeStamp=GetMmDdYyyyHhMmSs(Now)
Session("attchfilename")=""

--
Big MontyWeb Ninja at largeCommented:
ok, where is the code located in relation to the code you just posted?

If (CStr(Request.QueryString("GP_upload")) <> "") Then
  Dim REUF_renameMask
  Dim sTS
  sTS=sTimeStamp
  REUF_renameMask = DoTrim(Session("FirmId"),2)+"_"+DoTrim(Session("QnrId"),2)+ "_"+sTS+"_"+"##name##"+".##ext##"
  RenameUploadedFiles pau_thePath, pau_nameConflict, REUF_renameMask
end if

Open in new window


if it's located BEFORE it, the variable sTimeStamp won't be populated
AleksAuthor Commented:
It is .. let me move it see if that solves the issue.
Big MontyWeb Ninja at largeCommented:
either that or change the line to:

sTS=GetMmDdYyyyHhMmSs(Now)

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
AleksAuthor Commented:
That did not resolve the issue unfortunately.

Attached is the order in which I have the code. I have a JavaScript page and the script is way below the rename code and that one works fine.

How can I display the value of sTS on my page. To see if it is even being set ?
code.txt
AleksAuthor Commented:
This worked !

sTS=GetMmDdYyyyHhMmSs(Now)

Can I get rid of the script ?
AleksAuthor Commented:
Seems like I need the script, but the above change made it work !  thanks so much !
AleksAuthor Commented:
Great follow up !
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
VB Script

From novice to tech pro — start learning today.