Link to home
Start Free TrialLog in
Avatar of Aleks
AleksFlag 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")=""
Avatar of Big Monty
Big Monty
Flag of United States of America image

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##"
Where do the last 3 lines appear? They should be in a sub or function rather then by themselves as they appear to be.
Avatar of 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
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##"
Avatar of Aleks

ASKER

That's a negative   :(
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")=""
Avatar of 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 ?
Avatar of 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")=""

--
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
Avatar of Aleks

ASKER

It is .. let me move it see if that solves the issue.
ASKER CERTIFIED SOLUTION
Avatar of Big Monty
Big Monty
Flag of United States of America image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of 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
Avatar of Aleks

ASKER

This worked !

sTS=GetMmDdYyyyHhMmSs(Now)

Can I get rid of the script ?
Avatar of Aleks

ASKER

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

ASKER

Great follow up !