开发者

File Moving Problem?

开发者 https://www.devze.com 2022-12-11 18:34 出处:网络
Using VB6 I want to move the files to another folder. Code. Dim fso As FileSystem开发者_JAVA百科Object

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:

  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.

0

精彩评论

暂无评论...
验证码 换一张
取 消