[Last Call] Learn how to a build a cloud-first strategyRegister Now

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 592
  • Last Modified:

What is wrong with this vb-script

Hi!

Have this vb-script
Gives me this error message ?
VBScript compilation error: Name redifined

' VBSCRIPT
' Created by : Tor Erik Berg - Zoftzircus
' Date : 06 Aug 2012
' Versjon 1.0
' 
' Script have this actions:
'
' 1. Emty directory \Nyimport
' 2. Locate csv-file file in \Vectura
' 3. Rename csv-file VBxxxxx.csv to artikkler_ddmmyy -> dd = day  mm=month  yy=year
' 4. Copy the  artikkler_ddmmyy.csv file to Archive
' 5. Rename artikkler_ddmmyy.csv to artikkler.csv
' 2. Locate csv-file file in \Vectura
' 3. Rename csv-file VSxxxxx.csv to fakturalinjer_ddmmyy -> dd = day  mm=month  yy=year
' 4. Copy the  fakturalinjer_ddmmyy.csv file to Archive
' 5. Rename fakturalinjer_ddmmyy.csv to fakturalinjer.csv
'
' Define folders involved, and file base name to process
'
Dim strBaseDir
Dim strDestDir1
Dim strDestDir2
Dim strArchive
Dim strMatchstat1
Dim strMatchstat2

strBaseDir = "I:\DataExchange\NO\Vectura\"
strDestDir1 = "I:\DataExchange\NO\Vectura\varebok\"
strDestDir2 = "I:\DataExchange\NO\Vectura\varesalg\"
strArchive =  "I:\DataExchange\NO\Vectura\Archive\"
strMatchstat1 = "VB"
strMatchstat2 = "VS"

Dim filenobj1
' create objects varebok
Set filenobj1 = CreateObject("Scripting.FileSystemObject")

' Locate new varebok file
Dim varebokFile
varebokFile = ""

For Each objFile In filenobj1.GetFolder(strDestDir1).Files
   If UCase(Left(objFile.Name, Len(strMatchstat1))) = UCase(strMatchstat1) Then
      varebokFile = objFile.Path 
   End If
Next

' Rename varebok
Dim objartikkler
Set objartikkler = CreateObject("Scripting.FileSystemObject") 
objartikkler.MoveFile varebokFile, strDestDir1 & "artikkler_" & Date & ".csv"

varebokFile = strDestDir1 & "artikkler_" & Date & ".csv"

' Copy file to Archive/varebok
Dim filenobj2
Set filenobj2 = CreateObject("Scripting.FileSystemObject")
filenobj2.CopyFile varebokFile, strArchive

' Rename varebok
Dim objartikkler2
Set objartikkler2 = CreateObject("Scripting.FileSystemObject") 
objartikkler2.MoveFile varebokFile, strDestDir1 & "artikkler.csv" 
varebokFile = strDestDir1 & "artikkler.csv" 


' create objects fakturalinjer
Dim filenobj2
Set filenobj2 = CreateObject("Scripting.FileSystemObject")


' Locate new fakturalinjer file
fakturaFile = ""

For Each objFile In filenobj2.GetFolder(strDestDir2).Files
   If UCase(Left(objFile.Name, Len(strMatchstat2))) = UCase(strMatchstat2) Then
      fakturaFile = objFile.Path 
   End If
Next

' Rename fakturalinjer
Set objartikkler = CreateObject("Scripting.FileSystemObject") 
objartikkler.MoveFile fakturaFile, strDestDir2 & "fakturalinjer_" & Date & ".csv"

fakturaFile = strDestDir2 & "fakturalinjer_" & Date & ".csv"

' Copy file to Archive/fakturalinjer
Dim filenobj1
Set filenobj1 = CreateObject("Scripting.FileSystemObject")
filenobj1.CopyFile fakturaFile, strArchive

' Rename fakturalinjer
Set objartikkler = CreateObject("Scripting.FileSystemObject") 
objartikkler.MoveFile fakturaFile, strDestDir2 & "fakturalinjer.csv" 
fakturaFile = strDestDir2 & "artikkler.csv" 

Open in new window



What is wrong ?
0
team2005
Asked:
team2005
  • 2
1 Solution
 
lesliem-saCommented:
Hi,
You declared the variable filenobj2 on line 56 and then again on line 68.
Also variable filenobj1 on line 34 and again on line 88.

you should remark out lines 68 and 88.

Regards,
Leslie
0
 
team2005Author Commented:
Hi!

Aha, thanks
0
 
team2005Author Commented:
Thanks
0

Featured Post

Granular recovery for Microsoft Exchange

With Veeam Explorer for Microsoft Exchange you can choose the Exchange Servers and restore points you’re interested in, and Veeam Explorer will present the contents of those mailbox stores for browsing, searching and exporting.

  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now