Avatar of Aleks
Aleks
Flag for United States of America asked on

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")=""
VB ScriptASPWeb Development

Avatar of undefined
Last Comment
Aleks

8/22/2022 - Mon
Big Monty

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 Liss

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

ASKER
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
All of life is about relationships, and EE has made a viirtual community a real community. It lifts everyone's boat
William Peck
Big Monty

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##"
Aleks

ASKER
That's a negative   :(
Big Monty

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")=""
Get an unlimited membership to EE for less than $4 a week.
Unlimited question asking, solutions, articles and more.
Aleks

ASKER
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 ?
Aleks

ASKER
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 Monty

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
This is the best money I have ever spent. I cannot not tell you how many times these folks have saved my bacon. I learn so much from the contributors.
rwheeler23
Aleks

ASKER
It is .. let me move it see if that solves the issue.
ASKER CERTIFIED SOLUTION
Big Monty

Log in or sign up to see answer
Become an EE member today7-DAY FREE TRIAL
Members can start a 7-Day Free trial then enjoy unlimited access to the platform
Sign up - Free for 7 days
or
Learn why we charge membership fees
We get it - no one likes a content blocker. Take one extra minute and find out why we block content.
Not exactly the question you had in mind?
Sign up for an EE membership and get your own personalized solution. With an EE membership, you can ask unlimited troubleshooting, research, or opinion questions.
ask a question
Aleks

ASKER
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
Aleks

ASKER
This worked !

sTS=GetMmDdYyyyHhMmSs(Now)

Can I get rid of the script ?
Get an unlimited membership to EE for less than $4 a week.
Unlimited question asking, solutions, articles and more.
Aleks

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

ASKER
Great follow up !