473,509 Members | 11,437 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Object variable or With block variable not set error II

123 New Member
I'm trying to get a list of all subfolders in a folder on a share drive, but I keep on getting this error message:

Object variable or With block variable not set.
Description: An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in the code.

Exception Details: System.NullReferenceException: Object variable or With block variable not set.

Source Error:


Line 25:
Line 26: objFolder = objfso.GetFolder(objstartfolder)
Line 27: wscript.Echo(objFolder.Path)
Line 28: colfiles = objFolder.Files
Line 29:


Here is the code I'm working with:

Expand|Select|Wrap|Line Numbers
  1. Public Class _Default
  2.  
  3.     Inherits System.Web.UI.Page
  4.     Dim wscript As Object
  5.     Dim objfile As Object
  6.     Dim objfso As Object
  7.     Dim objFolder As Object
  8.     Dim objstartfolder As Object
  9.     Dim colfiles As Object
  10.     Protected Sub dataButton_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles dataButton.Click
  11.  
  12.  
  13.  
  14.         objfso = CreateObject("Scripting.FileSystemObject")
  15.         objstartfolder = "P:\freddocs\"
  16.  
  17.         objFolder = objfso.GetFolder(objstartfolder)
  18.         wscript.Echo(objFolder.Path)
  19.         colfiles = objFolder.Files
  20.  
  21.  
  22.         For Each objfile In colfiles
  23.         Next
  24.         wscript.Echo(objfile.Name)
  25.         wscript.Echo()
  26.  
  27.         ShowSubFolders(objfso.GetFolder(objstartfolder))
  28.     End Sub
  29.  
  30.     Sub ShowSubFolders(ByVal Folder)
  31.         Dim subfolder As Object
  32.  
  33.         For Each subfolder In Folder.SubFolders
  34.             wscript.Echo(subfolder.Path)
  35.             objFolder = objfso.GetFolder(subfolder.Path)
  36.             colfiles = objFolder.Files
  37.             For Each objfile In colfiles
  38.                 wscript.Echo(objfile.Name)
  39.             Next
  40.             wscript.Echo()
  41.             ShowSubFolders(subfolder)
  42.         Next
  43.     End Sub
  44.  
  45. End Class
How do I fix this error? I've tried the with statement and get another error. I'm thinking something is wrong with my declarations.

I've read the last person who had this issue, I've done the same thing but if failed.
Thanks,
Jul 31 '07 #1
3 3243
Newbie19
123 New Member
After doing some research in other areas, I've found that WScript.Echo is aVBscript method and should be replaced by Response.write for any VB coding.
Jul 31 '07 #2
Killer42
8,435 Recognized Expert Expert
After doing some research in other areas, I've found that WScript.Echo is aVBscript method and should be replaced by Response.write for any VB coding.
Glad we could help. :D lol
Jul 31 '07 #3
Change line 26:
objFolder = objfso.GetFolder(objstartfolder)

To:
set objFolder = objfso.GetFolder(objstartfolder)
Nov 1 '10 #4

Sign in to post your reply or Sign up for a free account.

Similar topics

28
20274
by: Daniel | last post by:
Hello =) I have an object which contains a method that should execute every x ms. I can use setInterval inside the object construct like this - self.setInterval('ObjectName.methodName()',...
8
8863
by: Lauren Quantrell | last post by:
I get the following error: "Object variable or Width block variable not set error" trying to run this in my Access2000 .ADP database: CurrentDb.Properties.Append...
0
2046
by: RJN | last post by:
Hi Sorry for posting again. I'm calling a shared method in the class. The following error is found in production though I'm not able to reproduce. ...
6
4232
by: Neo Geshel | last post by:
I am trying to deal with an image in code-behind. I consistently get the following error: Server Error in '/' Application. Object variable or With block variable not set. Description: An...
44
3316
by: petermichaux | last post by:
Hi, I have been using the following line of code to create an object called "Serious" if it doesn't already exist. if (Serious == null) {var Serious = {};} This works in the scripts I use...
3
35490
by: Richard Hollenbeck | last post by:
I've marked the line in this subroutine where I've been getting this error. It may be something stupid but I've been staring at this error trying to fix it for over an hour. I'm pretty sure the...
9
3070
by: axs221 | last post by:
I am trying to move some of our large VBA Access front-end file into ActiveX DLL files. I created two DLL files so far, one was a module that contains code to integrate into the QuickBooks...
1
2278
by: abhijmenbumca07 | last post by:
Object variable or With block variable not set. Description: An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information...
4
3466
by: BrianAdev | last post by:
Why It throw an error of <Object variable or With block variable not set> set objAccess = GetObject(strMdbPath) objAccess.DoCmd.SetWarning False objAccess.DoCmd.OpenReport strReportName, 0 'It...
0
7349
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
7417
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
1
7074
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
7506
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
5659
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
0
3219
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The...
0
3210
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
0
1572
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated ...
1
780
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

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.