Connecting Tech Pros Worldwide Forums | Help | Site Map

Help - runtime error 91 - object variable not set

Peter
Guest
 
Posts: n/a
#1: Jul 17 '05
I have a program which was working fine.
In it a function works out the number of .jpg files in a specified folder.
I then realised that I needed to make sure the folder exists first & added
the code for this.
After this I get the Runtime Error 91 - Object variable not set.
I've rem'd out my added code to no avail. Tried rebooting to.
The earlier exe version of the program continues to work OK.
The code in question is shown below. I'd appriciate any advice on how I've
messed this up & how to fix it
I'm running VB6 on XP pro SP2
mstrFolder is declared at the module level and Quickwatch shows it's
contents are a valid path.

many thanks


--
Peter
To err is human but it takes a computer to really mess things up!
__________________________________________________ _______
Private Function GetNumberOfFiles()
' Returns the number of files with a "jpg" extension in the folder
mstrFolder

Dim objFSO As Object, objFolder As Object
Dim objFiles As Object, objFile As Object

Set objFolder = objFSO.GetFolder(mstrFolder) ' ---- The error occurs at
this line ---
Set objFiles = objFolder.Files

mintNumFiles = 0
For Each objFile In objFiles
If UCase(Right(objFile.Name, 3)) = "JPG" Then
mintNumFiles = mintNumFiles + 1
End If
Next

End Function ' GetNumberOfFiles



Dikkie Dik
Guest
 
Posts: n/a
#2: Jul 17 '05

re: Help - runtime error 91 - object variable not set


Peter wrote:[color=blue]
> I have a program which was working fine.
> In it a function works out the number of .jpg files in a specified folder.
> I then realised that I needed to make sure the folder exists first & added
> the code for this.
> After this I get the Runtime Error 91 - Object variable not set.
> I've rem'd out my added code to no avail. Tried rebooting to.
> The earlier exe version of the program continues to work OK.
> The code in question is shown below. I'd appriciate any advice on how I've
> messed this up & how to fix it
> I'm running VB6 on XP pro SP2
> mstrFolder is declared at the module level and Quickwatch shows it's
> contents are a valid path.
>
> many thanks
>
>[/color]

Dim objFSO As Object, objFolder As Object
Dim objFiles As Object, objFile As Object

Set objFolder = objFSO.GetFolder(mstrFolder) ' ---- The error occurs at
this line ---

So that's where it occurs. objFSO is not set and is still Nothing.
Therefore, it does not have a GetFolder method and raises an error.
I don't know why you are using late binding, but you can set objFSO to a
filesystem object by using the new keyword or the CreateObject function.

Best regards
Closed Thread


Similar Visual Basic 4 / 5 / 6 bytes