By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
445,732 Members | 1,429 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 445,732 IT Pros & Developers. It's quick & easy.

Object variable or With block variable not set error II

100+
P: 123
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
Share this Question
Share on Google+
3 Replies


100+
P: 123
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 5K+
P: 8,434
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

P: n/a
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.