Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Object reference not set to an instance of an object.

Status
Not open for further replies.

MikeParc

Technical User
Jan 13, 2003
15
DE
HI,

I got this error above in the this code:

hFile = FindFirstFile(StartPath & "\" & File & vbNullChar, FileData)

Please help me, I'm new to .NET

Mike

 
Just a quick answer, in VB.net there is no VBnullChar call
ControlChars.NullChar is listed as the Equivalent. I have never used either call sorry I cannot help any more but maybe it will point you in the right direction

bassguy
 
Well it still sais that the object reference is not set to an instance of an object.

What can I do about it...
code looks now like this:

hFile = FindFirstFile(StartPath & "\" & File & ControlChars.NullChar, FileData)color]

And it also didn't work without the ControlChars.NullChar...

Mike
 
Make sure the api declaration is right.

Declare Function FindFirstFile Lib "kernel32" Alias "FindFirstFileA" (ByVal lpFileName As String, ByRef lpFindFileData As WIN32_FIND_DATA) As Integer

Make sure the WIN32_FIND_DATA is set to an instance by creating a sub new() for it and calling it.

Dim wfd As New WIN32_FIND_DATA

if you need more help. seanrdittmar at hotmail.com
 
By the way, you should really use:

dim files() As String = IO.Directory.GetFiles(path)

if you need additional info on a file, you can use:

Dim fi As New IO.FileInfo(path)

hope this helps
 
Hey thanx, that's pretty good...but would be good to know, HOW MANY Files are in that folder (path) because I need to display them in a ListView...and I think that only works with this:


for i = 0 To NumberOfFiles
ListView1.Items.Add(files(i))
next


MIke
 
you could use:
Dim dirRoot As New DirectoryInfo("YourPath")
Dim myFile As FileInfo

For Each myFile In dirRoot.GetFiles("*.*")
yourListView.Items.Add(myFile.Name)
Next
 
thats wrong, bro.

Use this instead:

dim fle As String

For Each fle In Directory.GetFiles("yourpath")
yourListView.Items.Add(Path.GetFileName(fle))

Next fle
 
hi,

works perfectly...but, how can I display the fileinfo in another column ??? the filenames are all displayed in the first column and I need to display the fileinfo in another one...

Mike
 
As far as the file attributes, you can use something like myFile.LastWriteTime.Date Almost all attributes are direct properties of the FileInfo variable.
 
well that's not exactly what I meant, I need to know how to display the FileInfo in another Column of the ListView

Mike
 
Dim lvi As New ListViewItem
With lvi
.Text = filename
.SubItems.Add("otherinfo")
End With

YourListView.Items.Add(lvi)


Does that answer your quandry?
 
hi,

works almost as I need it....it places the "otherinfo" in the second column, BUT it places it in the next line...

this is the whole function I'm using...

Dim fle As String
Dim filename As String
Dim lvi As New ListViewItem()

For Each fle In Directory.GetFiles(strPathMedia)
lvMedia.Items.Add(Path.GetFileName(fle))

With lvi
.Text = filename
.SubItems.Add(Path.GetExtension(fle))
End With

lvMedia.Items.Add(lvi)

Next fle


Mike
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top