When I try to add the following to :
Public Shared Sub ProcessFile(ByVal path As String)
Dim i As Integer
For i = 0 To 100000
_files(i) = path
Next
End Sub 'ProcessFile
ReadOnly Property speed()
Get
Return _files()
End Get
End Property
I get the following error:
Cannot refer to an instance member of a class from within a shared method or
shared member initializer without an explicit instance of the class.
---------------------------------------------------
Pritesh
-----Original Message-----
From: Pritesh Badiani [mailto:pritesh_b@t...]
Sent: 23 September 2002 16:23
To: pro_VB_dotnet
Subject: [pro_vb_dotnet] Adding a return value to this class i found
Hi
I have found some code which is exactly what I need but I don't know how to
get a return value i.e. add the filenames to a variable.
Can some one please explain to me how this is done?
Thanks
Here is the code I found:
' For Directory.GetFiles and Directory.GetDirectories
' For File.Exists, Directory.Exists
Imports System
Imports System.IO
Imports System.Collections
' Takes an array of file names or directory names on the command line.
' Determines what kind of name it is and processes it appropriately
Public Class RecursiveFileProcessor
Dim _fileLocations As String
'Entry point which delegates to C-style main function
Public Overloads Shared Sub Main()
'Main(System.Environment.GetCommandLineArgs())
'Dim path = "M:\static\core\ssi\V3.3.4"
End Sub
Public Overloads Shared Sub Main(ByVal args() As String)
Dim path As String
For Each path In args
If File.Exists(path) Then
' This path is a file
ProcessFile(path)
Else
If Directory.Exists(path) Then
' This path is a directory
ProcessDirectory(path)
Else
Console.WriteLine("{0} is not a valid file or
directory.", path)
End If
End If
Next path
End Sub 'Main
' Process all files in the directory passed in, and recurse on any
directories
' that are found to process the files they contain
Public Shared Sub ProcessDirectory(ByVal targetDirectory As String)
Dim fileEntries As String() = Directory.GetFiles(targetDirectory)
' Process the list of files found in the directory
Dim fileName As String
For Each fileName In fileEntries
ProcessFile(fileName)
Next fileName
Dim subdirectoryEntries As String()
Directory.GetDirectories(targetDirectory)
' Recurse into subdirectories of this directory
Dim subdirectory As String
For Each subdirectory In subdirectoryEntries
ProcessDirectory(subdirectory)
Next subdirectory
End Sub 'ProcessDirectory
' Real logic for processing found files would go here.
Public Shared Sub ProcessFile(ByVal path As String)
Console.WriteLine("Processed file '{0}'.", path)
End Sub 'ProcessFile
End Class 'RecursiveFileProcessor
---------------------------------------------------
Pritesh
---
Visual Basic .NET Text Manipulation Handbook
The .NET Framework brings a variety of string manipulation features
to the VB language, and some of these, namely regular expressions
and the StringBuilder class, are something VB 6 developers may not
have seen before. This book teaches you how to manipulate text using
these string matching, manipulation, and replacement classes. Issues
such as Localization and data conversion will also be investigated.
http://www.wrox.com/ACON11.asp?ISBN=1861007302