bungpeng Posted January 22, 2003 Posted January 22, 2003 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 Quote
*Experts* Volte Posted January 22, 2003 *Experts* Posted January 22, 2003 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. Quote
bungpeng Posted January 22, 2003 Author Posted January 22, 2003 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... Quote
*Experts* Volte Posted January 22, 2003 *Experts* Posted January 22, 2003 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 doMyClass.WriteLog("Hey")Are you? Quote
bungpeng Posted January 22, 2003 Author Posted January 22, 2003 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 Quote
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.