Solved

Error when writing a String to txt file

Posted on 2007-11-14
7
181 Views
Last Modified: 2010-04-23
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
0
Comment
Question by:dajoebomb
  • 3
  • 2
  • 2
7 Comments
 
LVL 47

Expert Comment

by:Wayne Taylor (webtubbs)
ID: 20279120
Hi dajoebomb,

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
0
 
LVL 47

Expert Comment

by:Wayne Taylor (webtubbs)
ID: 20279132
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
0
 
LVL 23

Expert Comment

by:Ashish Patel
ID: 20279134
Try our this

Dim strRanTemp As String = "<area shape='rect' coords='522,75,628,93' href='" & TextBox2.Text & "' target='_top' alt='" & TextBox1.Text & "' />"
0
Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

 

Author Comment

by:dajoebomb
ID: 20279150
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
0
 
LVL 47

Accepted Solution

by:
Wayne Taylor (webtubbs) earned 125 total points
ID: 20279172
Joe,

FileOpen is 'old school' VB6 code, but I can't see why it wouldn't work. Perhaps try this native VB.Net function....

    Public Function SaveTextToFile(ByVal strData As String, ByVal FullPath As String)
        Dim bAns As Boolean = False
        Try
            Dim sw As New IO.StreamWriter(FullPath, True)
            sw.Write(strData)
            sw.Close()
            bAns = True
        Catch Ex As Exception
            ErrInfo = Ex.Message
        End Try
        Return bAns
    End Function

Wayne
0
 
LVL 23

Expert Comment

by:Ashish Patel
ID: 20279184
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 & "' />"
0
 

Author Comment

by:dajoebomb
ID: 20279238
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!
0

Featured Post

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

You can of course define an array to hold data that is of a particular type like an array of Strings to hold customer names or an array of Doubles to hold customer sales, but what do you do if you want to coordinate that data? This article describes…
Whether you’re a college noob or a soon-to-be pro, these tips are sure to help you in your journey to becoming a programming ninja and stand out from the crowd.
Get people started with the utilization of class modules. Class modules can be a powerful tool in Microsoft Access. They allow you to create self-contained objects that encapsulate functionality. They can easily hide the complexity of a process from…
Show developers how to use a criteria form to limit the data that appears on an Access report. It is a common requirement that users can specify the criteria for a report at runtime. The easiest way to accomplish this is using a criteria form that a…

920 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

17 Experts available now in Live!

Get 1:1 Help Now