467,870 Members | 1,487 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 467,870 developers. It's quick & easy.

Object variable or With block variable not set error II

100+
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
  • viewed: 2917
Share:
3 Replies
100+
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
Expert 8TB
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

Post your reply

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

Similar topics

28 posts views Thread by Daniel | last post: by
6 posts views Thread by Neo Geshel | last post: by
reply views Thread by jack112 | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.