Regd VB code small issue

  • It changes the file name from BD.txt to something like BD_20080724_061523.txt (you can skip the seconds if you don't need to be that precise).

    This is my code but i get error on line 41 which i have highlighted it so please what would be the error in this code very urgent plz

    '**********************************************************************

    ' Visual Basic ActiveX Script

    '************************************************************************

    Function Main()

    Set Fso = CreateObject("Scripting.FileSystemObject")

    Dim aYear, aMonth, aDay, aDate, aHour, aMin, aTime, aSec

    ' Format date portion of string......

    aYear = Year(Now())

    aMonth = Month(Now())

    if len(aMonth) = 1 then

    aMonth = "0" & aMonth

    end if

    aDay = Day(Now())

    if len(aDay) = 1 then

    aDay = "0" & aDay

    end if

    aDate = aYear & aMonth & aDay

    ' Format time portion of string......

    aHour = Hour(Now())

    if len(aHour) = 1 then

    aHour = "0" & aHour

    end if

    aMin = Minute(Now())

    if len(aMin) = 1 then

    aMin = "0" & aMin

    end if

    aSec = Second(Now())

    if len(aSec) = 1 then

    aSec = "0" & aSec

    end if

    aTime = aHour & aMin & aSec

    CopyToSpec = "c:\Output\BD_" & aDate & "_" & aTime & ".txt"

    CopyFromSpec = "c:\Output\BD.txt"

    [font="Arial Black"] Fso.CopyFile CopyFromSpec, CopyToSpec[/size][/font]

    Fso.DeleteFile CopyFromSpec

    Main = DTSTaskExecResult_Success

    End Function

    Thanks,
    Chinna

    Its the Journey which gives you Happiness not the Destination-- Dan Millman

  • I'm guessing the "" is just formatting, but if not, remove that. Also, check if the account you're running the script under has permission to the [font="Courier New"]C:\Output[/font] folder.

    Fso.CopyFile CopyFromSpec, CopyToSpec

  • It might help if you told us what the error is. Also why don't you just rename the file:

    Dim oFile

    oFile = FSO.GetFile(CopyFromSpec)

    oFile.Name = CopyToSpec

  • Dim oFile

    oFile = FSO.GetFile(CopyFromSpec)

    oFile.Name = CopyToSpec

    Hello Jack but where exactly should i use this code as i dnt know much abt vb....plz let me know...in this code it doesnt even show my path ...so do i need to include this code in my previous code ..plz let me know...

    Thanks,
    Chinna

    Its the Journey which gives you Happiness not the Destination-- Dan Millman

  • Replace your problem code and the delete that follows it with the code I provided.

Viewing 5 posts - 1 through 4 (of 4 total)

You must be logged in to reply to this topic. Login to reply