Problem with VB Script

Aleks
Aleks used Ask the Experts™
on
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")=""
Comment
Watch Question

Do more with

Expert Office
EXPERT OFFICE® is a registered trademark of EXPERTS EXCHANGE®
Big MontyWeb Ninja at large

Commented:
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 dirt
Most Valuable Expert 2017
Distinguished Expert 2018

Commented:
Where do the last 3 lines appear? They should be in a sub or function rather then by themselves as they appear to be.

Author

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
CompTIA Cloud+

The CompTIA Cloud+ Basic training course will teach you about cloud concepts and models, data storage, networking, and network infrastructure.

Big MontyWeb Ninja at large

Commented:
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##"

Author

Commented:
That's a negative   :(
Big MontyWeb Ninja at large

Commented:
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")=""

Author

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 ?

Author

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 large

Commented:
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

Author

Commented:
It is .. let me move it see if that solves the issue.
Web Ninja at large
Commented:
either that or change the line to:

sTS=GetMmDdYyyyHhMmSs(Now)

Author

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

Author

Commented:
This worked !

sTS=GetMmDdYyyyHhMmSs(Now)

Can I get rid of the script ?

Author

Commented:
Seems like I need the script, but the above change made it work !  thanks so much !

Author

Commented:
Great follow up !

Do more with

Expert Office
Submit tech questions to Ask the Experts™ at any time to receive solutions, advice, and new ideas from leading industry professionals.

Start 7-Day Free Trial