croag
asked on
Misc Compile errors. That I can't figure out!!
What is this about! is this mutiple errors? Just one big one with many dependecies? Please please help.
__________________________ _
Service cannot be started. System.InvalidCastExceptio n: Cast from type 'StreamWriter' to type 'String' is not valid.
at Microsoft.VisualBasic.Comp ilerServic es.StringT ype.FromOb ject(Objec t Value)
at PxpParser.PxpParser.WriteT oFile(Stri ng pr_String) in C:\Thomas Huff\Visual Studio Projects\PxpParser\PxpPars er.vb:line 209
at PxpParser.PxpParser.StartW atch() in C:\Thomas Huff\Visual Studio Projects\PxpParser\PxpPars er.vb:line 140
at PxpParser.PxpParser.OnStar t(String[] args) in C:\Thomas Huff\Visual Studio Projects\PxpParser\PxpPars er.vb:line 363
at System.ServiceProcess.Serv iceBase.Se rviceQueue dMainCallb ack(Object state)
------------------
1 - Line 209 =
logsw = CObj(logobject.OpenText(CO bj(logobje ct.AppendT ext(logfil e))))
2 - Line 140 =
WriteToFile("Setting Folder to watch:" & watcher.Path() & "Done" & " @ " & Date.UtcNow & vbNewLine)
3 - Line 363 =
StartWatch()
Please Assist. I can't solve! Thanks!
__________________________
Service cannot be started. System.InvalidCastExceptio
at Microsoft.VisualBasic.Comp
at PxpParser.PxpParser.WriteT
at PxpParser.PxpParser.StartW
at PxpParser.PxpParser.OnStar
at System.ServiceProcess.Serv
------------------
1 - Line 209 =
logsw = CObj(logobject.OpenText(CO
2 - Line 140 =
WriteToFile("Setting Folder to watch:" & watcher.Path() & "Done" & " @ " & Date.UtcNow & vbNewLine)
3 - Line 363 =
StartWatch()
Please Assist. I can't solve! Thanks!
ASKER
THANK YOU for your quick response. So here is the WriteToFile Fuction that I"m using and the arguments aren't throwing a syntax error. What should I do different withing the code.....Where it writes to the actual file below, Right now, It says logsw.WriteLine(pr_String) cause thats what the argument that the fuction calls from, do you think If I can change the argument type to streamwriter passed to the function and then change another couple of things in this funciton..it will work? Please let me know. Thank you.
-------------------------- ---------- ---------- ---------- ---------- ---------- ---------- ---
Public Function WriteToFile(ByVal pr_String As String)
Dim logsw As StreamWriter
Dim logfile As String = logs & "\PxpParser.log"
Dim logobject As File
If logobject.Exists(logfile) Then
logsw = CObj(logobject.OpenText(CO bj(logobje ct.AppendT ext(logfil e))))
ElseIf Not logobject.Exists(logfile) Then
logsw = (CObj(logobject.CreateText (CObj(logo bject.Open Text(CObj( logobject. AppendText (logfile)) )))))
End If
'Write to the file
logsw.WriteLine(pr_String)
'Set the Value of pr_String back to NULL - Just to be safe
pr_String = ""
'Close the Stream Writer
logsw.Close()
End Function
-------------------------- ---------- ---------- ---------- ---------- ---------- ---------- ---------- -
--------------------------
Public Function WriteToFile(ByVal pr_String As String)
Dim logsw As StreamWriter
Dim logfile As String = logs & "\PxpParser.log"
Dim logobject As File
If logobject.Exists(logfile) Then
logsw = CObj(logobject.OpenText(CO
ElseIf Not logobject.Exists(logfile) Then
logsw = (CObj(logobject.CreateText
End If
'Write to the file
logsw.WriteLine(pr_String)
'Set the Value of pr_String back to NULL - Just to be safe
pr_String = ""
'Close the Stream Writer
logsw.Close()
End Function
--------------------------
Ohhhhh..... that could be the problem... there is a .NET function named WriteToFile, and it's very likely that your compile error is checking your function call against the .NET WriteToFile function and not yours... a quick test would be to rename your MyWriteToFile and change all the calls to call that instead and see if you still get the compile error.
Second of all, it's not clear to me why you have all the cast to CObj statements in your code... I think you could get rid of those completely... secondly, on the Else condition for this if statement:
If logobject.Exists(logfile)
You don't have to say Elseif.... because if the object.Exists is false, then by definition, it doesn't exist.
Hope that helps!
Second of all, it's not clear to me why you have all the cast to CObj statements in your code... I think you could get rid of those completely... secondly, on the Else condition for this if statement:
If logobject.Exists(logfile)
You don't have to say Elseif.... because if the object.Exists is false, then by definition, it doesn't exist.
Hope that helps!
ASKER
Oh man...Thank you..I'm going to try that one right now!
hmmmmmmmokay darn...same errors. Time to try taking out the Obj casting
NOpe...it loooks like i HAVE to use object casting..is it bad to cast so much like that?
Please hlep me more!!!
hmmmmmmmokay darn...same errors. Time to try taking out the Obj casting
NOpe...it loooks like i HAVE to use object casting..is it bad to cast so much like that?
Please hlep me more!!!
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
Dude....mdougan, You are the man!!!!!!!!! Thank you sooo much man. Thank you!!!!! that was it!
You are THE man!!!!!!!!!!!!!!!!! Thank you ..I may have a more questions for yoU!..Thank you!!!!. YES!..Thank you!..I am sooooo happy
You are THE man!!!!!!!!!!!!!!!!! Thank you ..I may have a more questions for yoU!..Thank you!!!!. YES!..Thank you!..I am sooooo happy
sure, my pleasure :) I've been away from EE for a while, nice to be back
> WriteToFile
The writeToFile function does not take a string as a parameter, rather, it takes a StreamWriter object.
If you just want to write a string to a file, you'd do something like this:
Dim fWriter As StreamWriter
fWriter = System.IO.File.CreateText(
fWriter.Write("Hello World")
fWriter.Close()
Cheers!