dajoebomb
asked on
Error when writing a String to txt file
HI guys, got a bit of a problem, (probably quite easy to sort out)
I'm writing html generated by my program to a text file, but im having a problem with Quotes, i either get too many or none at all,
THIS CODE:
Dim strRanTemp As String = "<area shape=" & ControlChars.Quote & "rect" & ControlChars.Quote & " coords=" & ControlChars.Quote & "522,75,628,93" & ControlChars.Quote & " href=" & ControlChars.Quote & TextBox2.Text & ControlChars.Quote & " target=" & ControlChars.Quote & "_top" & ControlChars.Quote & " alt=" & ControlChars.Quote & TextBox1.Text & ControlChars.Quote & " />"
SaveTextToFile(strRanTemp, "htmlCode.txt")
GIVES THIS RESPONSE:
"<area shape=""rect"" coords=""522,75,628,93"" href=""5.c"" target=""_top"" alt=""5"" />"
"<area shape=""rect"" coords=""522,75,628,93"" href=""6.c"" target=""_top"" alt=""6"" />"
It seems to give double quotes and a quote at the beggining and the end
And if i leave the & ControlChars.Quote out then i get this:
"<area shape=rect coords=522,75,628,93 href=60.com target=_top alt=60 />"
Could anyone sort this out please? thanks
I'm writing html generated by my program to a text file, but im having a problem with Quotes, i either get too many or none at all,
THIS CODE:
Dim strRanTemp As String = "<area shape=" & ControlChars.Quote & "rect" & ControlChars.Quote & " coords=" & ControlChars.Quote & "522,75,628,93" & ControlChars.Quote & " href=" & ControlChars.Quote & TextBox2.Text & ControlChars.Quote & " target=" & ControlChars.Quote & "_top" & ControlChars.Quote & " alt=" & ControlChars.Quote & TextBox1.Text & ControlChars.Quote & " />"
SaveTextToFile(strRanTemp,
GIVES THIS RESPONSE:
"<area shape=""rect"" coords=""522,75,628,93"" href=""5.c"" target=""_top"" alt=""5"" />"
"<area shape=""rect"" coords=""522,75,628,93"" href=""6.c"" target=""_top"" alt=""6"" />"
It seems to give double quotes and a quote at the beggining and the end
And if i leave the & ControlChars.Quote out then i get this:
"<area shape=rect coords=522,75,628,93 href=60.com target=_top alt=60 />"
Could anyone sort this out please? thanks
An alternate to using ControlChars.Quote is to use them literally....
Dim strRanTemp As String = "<area shape=""rect"" coords=""522,75,628,93"" href=""" & _
TextBox2.Text & """ target=""_top"" alt=""" & TextBox1.Text & """ />"
Wayne
Dim strRanTemp As String = "<area shape=""rect"" coords=""522,75,628,93"" href=""" & _
TextBox2.Text & """ target=""_top"" alt=""" & TextBox1.Text & """ />"
Wayne
Try our this
Dim strRanTemp As String = "<area shape='rect' coords='522,75,628,93' href='" & TextBox2.Text & "' target='_top' alt='" & TextBox1.Text & "' />"
Dim strRanTemp As String = "<area shape='rect' coords='522,75,628,93' href='" & TextBox2.Text & "' target='_top' alt='" & TextBox1.Text & "' />"
ASKER
Hi webtubbs, thanks for your speedy reply
Here is the function as you requested:
Public Function SaveTextToFile(ByVal strData As String, ByVal FullPath As String)
Dim bAns As Boolean = False
Try
FileOpen(1, FullPath, OpenMode.Append)
WriteLine(1, strData)
bAns = True
Catch Ex As Exception
ErrInfo = Ex.Message
End Try
FileClose(1)
Return bAns
End Function
Regards Joe
Here is the function as you requested:
Public Function SaveTextToFile(ByVal strData As String, ByVal FullPath As String)
Dim bAns As Boolean = False
Try
FileOpen(1, FullPath, OpenMode.Append)
WriteLine(1, strData)
bAns = True
Catch Ex As Exception
ErrInfo = Ex.Message
End Try
FileClose(1)
Return bAns
End Function
Regards Joe
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Function looks good just try using this
Try our this
Dim strRanTemp As String = "<area shape='rect' coords='522,75,628,93' href='" & TextBox2.Text & "' target='_top' alt='" & TextBox1.Text & "' />"
Try our this
Dim strRanTemp As String = "<area shape='rect' coords='522,75,628,93' href='" & TextBox2.Text & "' target='_top' alt='" & TextBox1.Text & "' />"
ASKER
Thanks Webtubbs,
That function and the
Dim strRanTemp As String = "<area shape=""rect"" coords=""522,75,628,93"" href=""" & _
TextBox2.Text & """ target=""_top"" alt=""" & TextBox1.Text & """ />"
Worked great.
THanks Again!
That function and the
Dim strRanTemp As String = "<area shape=""rect"" coords=""522,75,628,93"" href=""" & _
TextBox2.Text & """ target=""_top"" alt=""" & TextBox1.Text & """ />"
Worked great.
THanks Again!
I tried your code with the ControlChars.Quote and it worked fine, but I only tested with a MsgBox....
Dim strRanTemp As String = "<area shape=" & ControlChars.Quote & "rect" & ControlChars.Quote & _
" coords=" & ControlChars.Quote & "522,75,628,93" & ControlChars.Quote & _
" href=" & ControlChars.Quote & TextBox2.Text & ControlChars.Quote & _
" target=" & ControlChars.Quote & "_top" & ControlChars.Quote & _
" alt=" & ControlChars.Quote & TextBox1.Text & ControlChars.Quote & " />"
MsgBox(strRanTemp)
Whet does the SaveTextToFile() routine do? Can you post it here?
Regards,
Wayne