473,322 Members | 1,911 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,322 software developers and data experts.

Help - runtime error 91 - object variable not set

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
Jul 17 '05 #1
1 74997
Peter wrote:
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


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
Jul 17 '05 #2

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

1
by: Ike | last post by:
Anyone knows what cuases this under 6.0 ? -Ike
8
by: baustin75 | last post by:
Posted: Mon Oct 03, 2005 1:41 pm Post subject: cannot mail() in ie only when debugging in php designer 2005 -------------------------------------------------------------------------------- ...
2
by: John Regan | last post by:
Hello All I am trying to find the owner of a file or folder on our network (Windows 2000 Server) using VB.Net and/or API. so I can search for Folders that don't follow our company's specified...
5
by: David C. Allen | last post by:
I have a vb.net app that is controling excel 2000 thru the com interop interface. I have referenced the excel 9.0 library and have cut down the code in the problem subroutine to this: Dim...
7
by: Brett | last post by:
I'm not sure why I keep getting this error, "Object reference not set to an instance of an object". Private Function somefunction() as string Dim MyCurrentClass As New Class1 Try For i As...
33
by: larpup | last post by:
I checked all my references prior to compiling. The mdb or mde works perfectly with full version of A2003. When running on a computer with RunTime i receive an error that a reference is broken...
1
by: bobh | last post by:
Hi All, I've been using this function which I got from here for some time now in two of my AccessXP multiusers applications and it has worked without issue until lately it has stopped functioning...
2
by: hcaptech | last post by:
This is my Test.can you help me ? 1.Which of the following statement about C# varialble is incorrect ? A.A variable is a computer memory location identified by a unique name B.A variable's name...
0
by: DolphinDB | last post by:
Tired of spending countless mintues downsampling your data? Look no further! In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
0
by: Vimpel783 | last post by:
Hello! Guys, I found this code on the Internet, but I need to modify it a little. It works well, the problem is this: Data is sent from only one cell, in this case B5, but it is necessary that data...
0
by: jfyes | last post by:
As a hardware engineer, after seeing that CEIWEI recently released a new tool for Modbus RTU Over TCP/UDP filtering and monitoring, I actively went to its official website to take a look. It turned...
0
by: ArrayDB | last post by:
The error message I've encountered is; ERROR:root:Error generating model response: exception: access violation writing 0x0000000000005140, which seems to be indicative of an access violation...
1
by: PapaRatzi | last post by:
Hello, I am teaching myself MS Access forms design and Visual Basic. I've created a table to capture a list of Top 30 singles and forms to capture new entries. The final step is a form (unbound)...
1
by: Defcon1945 | last post by:
I'm trying to learn Python using Pycharm but import shutil doesn't work
1
by: Shællîpôpï 09 | last post by:
If u are using a keypad phone, how do u turn on JavaScript, to access features like WhatsApp, Facebook, Instagram....
0
by: af34tf | last post by:
Hi Guys, I have a domain whose name is BytesLimited.com, and I want to sell it. Does anyone know about platforms that allow me to list my domain in auction for free. Thank you
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.