Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Getting error # 91 - Object variable not set 1

Status
Not open for further replies.

Keyster86

IS-IT--Management
Jul 23, 2008
50
US
Code:
 FUNCTION Backup(RepSource,RepDest)
		ON ERROR RESUME NEXT
		DIM objSource(1), objDest, objDestCompare
		SET objSource(0)=objFSO.GetFolder(RepSource)
			ErrCheck
		IF NOT objFSO.FolderExists(RepDest) THEN objFSO.CreateFolder(RepDest)
			ErrCheck
		FOR EACH objFile IN objSource(0).Files
			strExt = Right(objFile.Name,4)
			
			SELECT CASE strExt
				CASE ".mp3"
					ErrCheck
					objExplorer.Document.Body.InnerHTML = "Your backup is now being processed" & _    			
						"<br><br>File " & intFileCount & " of " & strCountTheFiles & " has been copied.<br><br>" & _
						"This may take several minutes to complete."
						ErrCheck
					intFileCount = intFileCount + 1
					ErrCheck
					IF IsError(err) = TRUE THEN
						ErrCheck					
						LogIt("Backed up file # " & intFileCount & " Had and error.")	
						ErrCheck
					ELSE
						ErrCheck
						strLogFileName = objFile.Name
						ErrCheck
						LogIt("Backed up file # " & intFileCount & " " & RepSource & "\" & strLogFileName)	
						ErrCheck
						strLogFileName = NOTHING
						ErrCheck
					END IF
				CASE ".wav"
					ErrCheck
					objExplorer.Document.Body.InnerHTML = "Your backup is now being processed" & _    			
						"<br><br>File " & intFileCount & " of " & strCountTheFiles & " has been copied.<br><br>" & _
						"This may take several minutes to complete."
						ErrCheck
					intFileCount = intFileCount + 1
					ErrCheck
					IF IsError(err) = TRUE THEN
						ErrCheck					
						LogIt("Backed up file # " & intFileCount & " Had and error.")	
						ErrCheck
					ELSE
						ErrCheck
						strLogFileName = objFile.Name
						ErrCheck
						LogIt("Backed up file # " & intFileCount & " " & RepSource & "\" & strLogFileName)	
						ErrCheck
						strLogFileName = NOTHING
						ErrCheck
					END IF
				CASE ".gif"
					ErrCheck
					objExplorer.Document.Body.InnerHTML = "Your backup is now being processed" & _    			
						"<br><br>File " & intFileCount & " of " & strCountTheFiles & " has been copied.<br><br>" & _
						"This may take several minutes to complete."
						ErrCheck
					intFileCount = intFileCount + 1
					ErrCheck
					IF IsError(err) = TRUE THEN
						ErrCheck					
						LogIt("Backed up file # " & intFileCount & " Had and error.")	
						ErrCheck
					ELSE
						ErrCheck
						strLogFileName = objFile.Name
						ErrCheck
						LogIt("Backed up file # " & intFileCount & " " & RepSource & "\" & strLogFileName)	
						ErrCheck
						strLogFileName = NOTHING
						ErrCheck
					END IF
				CASE ".MOV"
					ErrCheck
					objExplorer.Document.Body.InnerHTML = "Your backup is now being processed" & _    			
						"<br><br>File " & intFileCount & " of " & strCountTheFiles & " has been copied.<br><br>" & _
						"This may take several minutes to complete."
						ErrCheck
					intFileCount = intFileCount + 1
					ErrCheck
					IF IsError(err) = TRUE THEN
						ErrCheck					
						LogIt("Backed up file # " & intFileCount & " Had and error.")	
						ErrCheck
					ELSE
						ErrCheck
						strLogFileName = objFile.Name
						ErrCheck
						LogIt("Backed up file # " & intFileCount & " " & RepSource & "\" & strLogFileName)	
						ErrCheck
						strLogFileName = NOTHING
						ErrCheck
					END IF
				CASE ".WMV"
					ErrCheck
					objExplorer.Document.Body.InnerHTML = "Your backup is now being processed" & _    			
						"<br><br>File " & intFileCount & " of " & strCountTheFiles & " has been copied.<br><br>" & _
						"This may take several minutes to complete."
						ErrCheck
					intFileCount = intFileCount + 1
					ErrCheck
					IF IsError(err) = TRUE THEN
						ErrCheck					
						LogIt("Backed up file # " & intFileCount & " Had and error.")	
						ErrCheck
					ELSE
						ErrCheck
						strLogFileName = objFile.Name
						ErrCheck
						LogIt("Backed up file # " & intFileCount & " " & RepSource & "\" & strLogFileName)	
						ErrCheck
						strLogFileName = NOTHING
						ErrCheck
					END IF
				CASE ".WMA"
					ErrCheck
					objExplorer.Document.Body.InnerHTML = "Your backup is now being processed" & _    			
						"<br><br>File " & intFileCount & " of " & strCountTheFiles & " has been copied.<br><br>" & _
						"This may take several minutes to complete."
						ErrCheck
					intFileCount = intFileCount + 1
					ErrCheck
					IF IsError(err) = TRUE THEN
						ErrCheck					
						LogIt("Backed up file # " & intFileCount & " Had and error.")	
						ErrCheck
					ELSE
						ErrCheck
						strLogFileName = objFile.Name
						ErrCheck
						LogIt("Backed up file # " & intFileCount & " " & RepSource & "\" & strLogFileName)	
						ErrCheck
						strLogFileName = NOTHING
						ErrCheck
					END IF
				CASE ".AVI"
					ErrCheck
					objExplorer.Document.Body.InnerHTML = "Your backup is now being processed" & _    			
						"<br><br>File " & intFileCount & " of " & strCountTheFiles & " has been copied.<br><br>" & _
						"This may take several minutes to complete."
						ErrCheck
					intFileCount = intFileCount + 1
					ErrCheck
					IF IsError(err) = TRUE THEN
						ErrCheck					
						LogIt("Backed up file # " & intFileCount & " Had and error.")	
						ErrCheck
					ELSE
						ErrCheck
						strLogFileName = objFile.Name
						ErrCheck
						LogIt("Backed up file # " & intFileCount & " " & RepSource & "\" & strLogFileName)	
						ErrCheck
						strLogFileName = NOTHING
						ErrCheck
					END IF
				CASE ".FLV"
					ErrCheck
					objExplorer.Document.Body.InnerHTML = "Your backup is now being processed" & _    			
						"<br><br>File " & intFileCount & " of " & strCountTheFiles & " has been copied.<br><br>" & _
						"This may take several minutes to complete."
						ErrCheck
					intFileCount = intFileCount + 1
					ErrCheck
					IF IsError(err) = TRUE THEN
						ErrCheck					
						LogIt("Backed up file # " & intFileCount & " Had and error.")	
						ErrCheck
					ELSE
						ErrCheck
						strLogFileName = objFile.Name
						ErrCheck
						LogIt("Backed up file # " & intFileCount & " " & RepSource & "\" & strLogFileName)	
						ErrCheck
						strLogFileName = NOTHING
						ErrCheck
					END IF
				CASE ".exe"
					ErrCheck
					objExplorer.Document.Body.InnerHTML = "Your backup is now being processed" & _    			
						"<br><br>File " & intFileCount & " of " & strCountTheFiles & " has been copied.<br><br>" & _
						"This may take several minutes to complete."
						ErrCheck
					intFileCount = intFileCount + 1
					ErrCheck
					IF IsError(err) = TRUE THEN
						ErrCheck					
						LogIt("Backed up file # " & intFileCount & " Had and error.")	
						ErrCheck
					ELSE
						ErrCheck
						strLogFileName = objFile.Name
						ErrCheck
						LogIt("Backed up file # " & intFileCount & " " & RepSource & "\" & strLogFileName)	
						ErrCheck
						strLogFileName = NOTHING
						ErrCheck
					END IF	
				CASE ELSE
					objSource(1)=objFSO.BuildPath(RepSource,objFile.name)
					ErrCheck
					objDest=objFSO.BuildPath(RepDest,objFile.name)
					ErrCheck
					IF objFSO.FileExists(objDest) THEN
						SET objDestCompare=objFSO.GetFile(objDest)
						ErrCheck
						objExplorer.Document.Body.InnerHTML = "Your backup is now being processed" & _    			
							"<br><br>File " & intFileCount & " of " & strCountTheFiles & " has been copied.<br><br>" & _
							"This may take several minutes to complete."
							ErrCheck
						intFileCount = intFileCount + 1
						ErrCheck
						IF IsError(err) = TRUE THEN
							ErrCheck					
							LogIt("Backed up file # " & intFileCount & " Had and error.")	
							ErrCheck
						ELSE
							ErrCheck
							strLogFileName = objFile.Name
							ErrCheck
							LogIt("Backed up file # " & intFileCount & " " & RepSource & "\" & strLogFileName)	
							ErrCheck
							strLogFileName = NOTHING
							ErrCheck
						END IF			
						IF objDestCompare.Size<>objFile.Size Or objDestCompare.DateLastModified<>objFile.DateLastModified THEN
								objFile.Copy objDest,TRUE
									ErrCheck
									objExplorer.Document.Body.InnerHTML = "Your backup is now being processed" & _    			
										"<br><br>File " & intFileCount & " of " & strCountTheFiles & " has been copied.<br><br>" & _
										"This may take several minutes to complete."
										ErrCheck
									intFileCount = intFileCount + 1
									ErrCheck
									IF IsError(err) = TRUE THEN
										ErrCheck					
										LogIt("Backed up file # " & intFileCount & " Had and error.")	
										ErrCheck
									ELSE
										ErrCheck
										strLogFileName = objFile.Name
										ErrCheck
										LogIt("Backed up file # " & intFileCount & " " & RepSource & "\" & strLogFileName)	
										ErrCheck
										strLogFileName = NOTHING
										ErrCheck
									END IF
						END IF								
					ELSE
						objFile.Copy objDest,TRUE
						ErrCheck
						objExplorer.Document.Body.InnerHTML = "Your backup is now being processed" & _    			
							"<br><br>File " & intFileCount & " of " & strCountTheFiles & " has been copied.<br><br>" & _
							"This may take several minutes to complete."
							ErrCheck
						intFileCount = intFileCount + 1
						ErrCheck
						IF IsError(err) = TRUE THEN
							ErrCheck					
							LogIt("Backed up file # " & intFileCount & " Had and error.")	
							ErrCheck
						ELSE
							ErrCheck
							strLogFileName = objFile.Name
							ErrCheck
							LogIt("Backed up file # " & intFileCount & " " & RepSource & "\" & strLogFileName)	
							ErrCheck
							strLogFileName = NOTHING
							ErrCheck
						END IF
					END IF
			END SELECT
		NEXT
			ErrCheck
		FOR EACH objFile IN objSource(0).SubFolders
			IF objFile.Name = "My Music" Or objFile.Name = "My Videos" Or objFile.Name = "My Pictures" THEN
				
			ELSE
				objSource(1)=objFSO.BuildPath(RepSource,objFile.name)
				ErrCheck
				objDest=objFSO.BuildPath(RepDest,objFile.name)
				ErrCheck
				Backup objSource(1),objDest
				ErrCheck
			END IF
		NEXT
			ErrCheck
		SET objSource(0) = NOTHING
		SET objSource(1) = NOTHING
		SET objDest = NOTHING
		SET objDestCompare = NOTHING
	END FUNCTION

V/r,

SPC Key
United States Army
 
I found the error and cleaned up the code a little.

The error was the following.

WRONG: strLogFileName = Nothing
CORRECT: SET strLogFileName = Nothing

Code:
FUNCTION Backup(RepSource,RepDest)
		ON ERROR RESUME NEXT
		DIM objSource(1), objDest, objDestCompare
		SET objSource(0)=objFSO.GetFolder(RepSource)
			ErrCheck
		IF NOT objFSO.FolderExists(RepDest) THEN objFSO.CreateFolder(RepDest)
			ErrCheck
		FOR EACH objFile IN objSource(0).Files
			strExt = Right(objFile.Name,4)
			
			SELECT CASE strExt
				CASE ".mp3", ".MP3"
					PROCESSFILE
				CASE ".wav", ".WAV"
					PROCESSFILE
				CASE ".gif", ".GIF"
					PROCESSFILE
				CASE ".mov", ".MOV"
					PROCESSFILE
				CASE ".wmv", ".WMV"
					PROCESSFILE
				CASE ".wma", ".WMA"
					PROCESSFILE
				CASE ".avi", ".AVI"
					PROCESSFILE
				CASE ".flv", ".FLV"
					PROCESSFILE
				CASE ".exe", ".EXE"
					PROCESSFILE
				CASE ".jpg", ".JPG"
					PROCESSFILE
				CASE ELSE
					objSource(1)=objFSO.BuildPath(RepSource,objFile.name)
					ErrCheck
					objDest=objFSO.BuildPath(RepDest,objFile.name)
					ErrCheck
					IF objFSO.FileExists(objDest) THEN
						SET objDestCompare=objFSO.GetFile(objDest)
						PROCESSFILE			
						IF objDestCompare.Size<>objFile.Size Or objDestCompare.DateLastModified<>objFile.DateLastModified THEN
								objFile.Copy objDest,TRUE
									PROCESSFILE
						END IF								
					ELSE
						objFile.Copy objDest,TRUE
						PROCESSFILE
					END IF
			END SELECT
		NEXT
			ErrCheck
		FOR EACH objFile IN objSource(0).SubFolders
			IF objFile.Name = "My Music" Or objFile.Name = "My Videos" Or objFile.Name = "My Pictures" THEN
				
			ELSE
				objSource(1)=objFSO.BuildPath(RepSource,objFile.name)
				ErrCheck
				objDest=objFSO.BuildPath(RepDest,objFile.name)
				ErrCheck
				Backup objSource(1),objDest
				ErrCheck
			END IF
		NEXT
			ErrCheck
		SET objSource(0) = NOTHING
		SET objSource(1) = NOTHING
		SET objDest = NOTHING
		SET objDestCompare = NOTHING
	END FUNCTION
	
	FUNCTION PROCESSFILE
		ErrCheck
		objExplorer.Document.Body.InnerHTML = "Your backup is now being processed" & _    			
			"<br><br>File " & intFileCount & " of " & strCountTheFiles & " has been copied.<br><br>" & _
			"This may take several minutes to complete."
			ErrCheck
		intFileCount = intFileCount + 1
		ErrCheck
		IF IsError(err) = TRUE THEN
			ErrCheck					
			LogIt("Backed up file # " & intFileCount & " Had and error.")	
			ErrCheck
			SET strLogFileName = NOTHING
			ErrCheck
		ELSE
			strLogFileName = objFile.Name
			ErrCheck
			LogIt("Backed up file # " & intFileCount & " " & RepSource & "\" & strLogFileName)	
			ErrCheck
			SET strLogFileName = NOTHING
			ErrCheck
		END IF
		ErrCheck
	END FUNCTION

V/r,

SPC Key
United States Army
 
I think I noted in your previous thread. If strLogFileName is a string (and in fact it is, as it is obtained by objFile.Name), you don't set it to nothing in the name of cleaning up. You can, only the script engine will take any variable as long as the set keyword is on the left hand side and nothing keyword is on the right hand side. You put that line in and it betrays your professionalism: it's your call.
 
I have a hard head and didn't listen the first time; however, I appreciate the educational comment. I was just thinking since I run this multiple files, that I would have to "reset" the string, but what I hear you saying is that it is not needed and the string will be "reset" on its own. I will try it out - thank you for the input; I really appreciate it. :D

V/r,

SPC Key
United States Army
 
Hi
I am newbee in VB. Would you explain where you define source and destination folder ? I see above has RepSource and RepDest , but they don't point to any directory.
Thank you
 
The above script is just a portion of my main script...

You can define the Source/Destination like so...

Code:
RepSource = "[COLOR=red]C:\Folder_to_be_backed-up[/color]"

RepDestination = "[COLOR=red]E:\Folder_back-up_Destination[/color]"

V/r,

SPC Key
United States Army
 
HI
Keyster86
Forgot one thing ..
will your code does backup all folder and subfolder and undeneath sub folder from source as well as create same subfolders in destination ?

Thank you
 
Yes, it will.

V/r,

SPC Key
United States Army
 
Hi
I create file by backup.vbs with following but when i run this file it erroed out.. backup.vbs contains

Option Explicit
Backup
DIM RepSource
DIM RepDest
RepSource = "C:\Temp\tmp"
RepDest = "C:\Temp\restore"
FUNCTION Backup (RepSource,RepDest)
.
.
.
.
.
END FUNCTION
 
Option Explicit
Backup "C:\Temp\tmp", "C:\Temp\restore"
FUNCTION Backup (RepSource,RepDest)
.
.
.
.
.
END FUNCTION

Hope This Helps, PH.
FAQ219-2884
FAQ181-2886
 
Hi
PHV
I tried following script and it did not work ( no error , it just disappear).Any idea what i am missing ? I have stuff in C:\Temp\tmp\tmp1\ and they did not get copied to C:\Temp\restore\ .


Option Explicit
Backup "C:\Temp\tmp", "C:\Temp\restore"
FUNCTION Backup (RepSource,RepDest)
ON ERROR RESUME NEXT
DIM objSource(1), objDest, objDestCompare
SET objSource(0)=objFSO.GetFolder(RepSource)
ErrCheck
IF NOT objFSO.FolderExists(RepDest) THEN objFSO.CreateFolder(RepDest)
ErrCheck
FOR EACH objFile IN objSource(0).Files
strExt = Right(objFile.Name,4)

SELECT CASE strExt
CASE ".mp3", ".MP3"
PROCESSFILE
CASE ".wav", ".WAV"
PROCESSFILE
CASE ".gif", ".GIF"
PROCESSFILE
CASE ".mov", ".MOV"
PROCESSFILE
CASE ".wmv", ".WMV"
PROCESSFILE
CASE ".wma", ".WMA"
PROCESSFILE
CASE ".avi", ".AVI"
PROCESSFILE
CASE ".flv", ".FLV"
PROCESSFILE
CASE ".exe", ".EXE"
PROCESSFILE
CASE ".jpg", ".JPG"
PROCESSFILE
CASE ELSE
objSource(1)=objFSO.BuildPath(RepSource,objFile.name)
ErrCheck
objDest=objFSO.BuildPath(RepDest,objFile.name)
ErrCheck
IF objFSO.FileExists(objDest) THEN
SET objDestCompare=objFSO.GetFile(objDest)
PROCESSFILE
IF objDestCompare.Size<>objFile.Size Or objDestCompare.DateLastModified<>objFile.DateLastModified THEN
objFile.Copy objDest,TRUE
PROCESSFILE
END IF
ELSE
objFile.Copy objDest,TRUE
PROCESSFILE
END IF
END SELECT
NEXT
ErrCheck
FOR EACH objFile IN objSource(0).SubFolders
IF objFile.Name = "My Music" Or objFile.Name = "My Videos" Or objFile.Name = "My Pictures" THEN

ELSE
objSource(1)=objFSO.BuildPath(RepSource,objFile.name)
ErrCheck
objDest=objFSO.BuildPath(RepDest,objFile.name)
ErrCheck
Backup objSource(1),objDest
ErrCheck
END IF
NEXT
ErrCheck
SET objSource(0) = NOTHING
SET objSource(1) = NOTHING
SET objDest = NOTHING
SET objDestCompare = NOTHING
END FUNCTION

FUNCTION PROCESSFILE
ErrCheck
objExplorer.Document.Body.InnerHTML = "Your backup is now being processed" & _
"<br><br>File " & intFileCount & " of " & strCountTheFiles & " has been copied.<br><br>" & _
"This may take several minutes to complete."
ErrCheck
intFileCount = intFileCount + 1
ErrCheck
IF IsError(err) = TRUE THEN
ErrCheck
LogIt("Backed up file # " & intFileCount & " Had and error.")
ErrCheck
SET strLogFileName = NOTHING
ErrCheck
ELSE
strLogFileName = objFile.Name
ErrCheck
LogIt("Backed up file # " & intFileCount & " " & RepSource & "\" & strLogFileName)
ErrCheck
SET strLogFileName = NOTHING
ErrCheck
END IF
ErrCheck
END FUNCTION
 
Hi
Anybody
I tried above script and it did not work any idea what missing ?
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top