tags:

views:

54

answers:

2

Using VB6

I want to move the files to another folder.

Code.

Dim fso As FileSystemObject
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

+2  A: 

Just a couple of questions:

  1. What is fso set to?
  2. 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.

paxdiablo
I modify my question, Check now
Gopal
+4  A: 

fso is not initialized to anything, try replacing

Dim fso As FileSystemObject

with:

Dim fso As New Scripting.FileSystemObject
Anders Lindahl