I could really use some help with this problem its driving me nuts. I have a small vb app, the goal of the app is to read an html doc into a variable then go through that variable and find and replace some tags. I have 3 functions. 1 to open the doc, the 2nd to find and replace the tags the 3rd to save the info. the code is pasted below :
Expand|Select|Wrap|Line Numbers
- Public Function ReadFileContents(FileFullPath As String) As _
- String
- On Error GoTo ErrorHandler
- Dim iFileNumber As Integer
- Dim sAns As String
- If Dir(FileFullPath) = "" Then Exit Function
- iFileNumber = FreeFile
- Open FileFullPath For Input As #iFileNumber
- sAns = Input(LOF(iFileNumber), #iFileNumber)
- sAns = UCase(sAns)
- ReadFileContents = sAns
- 'MsgBox sAns
- ErrorHandler:
- Close #iFileNumber
- End Function
Expand|Select|Wrap|Line Numbers
- Public Function ReplaceText(ByVal txt As String, ByVal _
- from_str As String, ByVal to_str As String) As String
- Dim result As String
- Dim from_len As Integer
- Dim pos As Integer
- from_len = Len(from_str)
- Do While Len(txt) > 0
- ' Find level 1.
- pos = InStr(txt, from_str)
- If pos = 0 Then
- ' No more occurrences.
- result = result & txt
- txt = ""
- Else
- ' Make the replacement.
- result = result & Left$(txt, pos - 1) & to_str
- txt = Mid$(txt, pos + from_len)
- End If
- Loop
- ReplaceText = result
- End Function
Expand|Select|Wrap|Line Numbers
- Public Function SaveTextToFile(FileFullPath As String, _
- sText As String, Optional Overwrite As Boolean = True) As _
- Boolean
- On Error GoTo ErrorHandler
- Dim iFileNumber As Integer
- iFileNumber = FreeFile
- If Overwrite Then
- Open FileFullPath For Output As #iFileNumber
- Else
- Open FileFullPath For Append As #iFileNumber
- End If
- Print #iFileNumber, sText
- SaveTextToFile = True
- ErrorHandler:
- Close #iFileNumber
- End Function
Expand|Select|Wrap|Line Numbers
- Private Sub Form_Load()
- '****************************************************************
- 'Define variables for strings
- Dim sFileText As String
- Dim sFrom1 As String, sTo1 As String
- '****************************************************************
- 'Open the HTML file as text
- sFileText = ReadFileContents("c:\toc\toc.htm")
- '****************************************************************
- 'In this section you should setup the strings you are searching
- 'The document for. You should also setup the replacement string
- 'If the above named strings are found
- '****************************************************************
- sFrom1 = "<img src=" + Chr(34) + "space.gif" + Chr(34)
- MsgBox sFrom1
- sTo1 = "<div class=" + Chr(34) + "toc1" + Chr(34) + "><img src=" + Chr(34) + "space.gif" + Chr(34)
- MsgBox sTo1
- Call ReplaceText(sFileText, sFrom1, sTo1)
- Call SaveTextToFile("c:\toc\toc.htm", sFileText, True)
- End Sub
all help is appreciated im stuck here. I would like someone to help me but also explain why im getting this problem in the solution. I dont just want an answer i would like to learn as well.
thanks in advance,
john