Jump to content
Xtreme .Net Talk

Recommended Posts

Posted

I was wrote a simple function to write info to text file, but there is a error message: "Referenced object has a value of 'Nothing'." in line 4, this is what I followed exactly the book... anyone can help?

 

Public Function WriteLog(ByVal sVal As String) As Boolean

WriteLog = False

Try

Dim oWriter As StreamWriter = File.AppendText(sFilePath)

oWriter.WriteLine(sVal)

 

WriteLog = True

Catch e As Exception

 

End Try

End Function

  • *Experts*
Posted

Try changing it to this:

        Dim oWriter As New IO.StreamWriter(sFilePath, True)
       oWriter.WriteLine(sVal)

I'm not sure exactly what File.AppendText does, but my way

should work if you just want to append regular text.

Posted

It still the same, cannot work....

 

I wrote this function in a class and call by another class, it should not be the problem right? since everything is a class...

  • *Experts*
Posted

Are you first declaring the class as an object? For example,

Dim cls As New MyClass()

cls.WriteLog("Hey")

Where, 'MyClass' is the class that the function you posted above

is in? You're not just trying to do

MyClass.WriteLog("Hey")

Are you?

Posted

of course, I did declaring the class as an object.

 

I found the same function can be run in Windows project...

 

It cannot run (I use 3 tiers architecture):

1. This function is under a 'class' project (dll file)

2. I use ASP.NET to call this function

 

I still don't understand why it cannot run

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...