File Moving Problem?
Using VB6
I want to move the files to another folder.
Code.
Dim fso As FileSystem开发者_JAVA百科Object
fso.MoveFile (txtsourcedatabasefile & "\" & "1.txt"), App.Path & "\Uploaded\"
txtsourcedatabasefile = "C:"
Above code is not working, it showing error as object variable or with block variable not set.
How to modify my code.
Need VB6 code Help
fso
is not initialized to anything, try replacing
Dim fso As FileSystemObject
with:
Dim fso As New Scripting.FileSystemObject
Just a couple of questions:
- What is
fso
set to? - What is
txtsourcedatabasefile
set to?
That is, I suspect, where your problem lies. I'd be looking at fso
myself to make sure you've set it.
Update:
In your question updates, your code:
Dim fso As FileSystemObject
creates the object but you don't actually initialize it to anything. You need to do:
Dim fso As FileSystemObject
Set fso = New FileSystemObject
This is actually preferable in the vast majority of the cases since the near-equivalent:
Dim fso As New FileSystemObject
creates an auto-instantiating object, meaning every time you use it, it will check to see if it needs to be created.
That makes a code segment like:
Dim fso As New FileSystemObject
fso.DoThis()
fso.DoThat()
if fso.EverythingDone then
fso.Shutdown()
end if
expensive since it will check fso
four times to see if it exists (and create it only the first time). It's more efficient to create it manually once.
精彩评论