Now an Disk IO question. I'm saving the addresses to check in a txt file, so it can load them each time it runs. I'm also trying to add the ability to modify a site, or add a new one (there a 6). When the user modifies a site, I want to go into the txt file to a specific line (the line that contains that site's URL) and replace only that line. ForReading won't help me, ForWriting seems to replace the whole file, and ForAppending only writes to the end of the file... What can I do?
I think I have an idea: On loading, I'll put each existing site URL into a string, called Site1, Site2, etc. Then, when they modify a URL, the changes will be made to the corresponding string. Then I'll just rewrite all of them to the text file. Sound good?
Edit: That works. New problem though. For the first site and only the first, when I write the HTML to its own file (site1cache.txt), the compiler tells me "Invalid procedure call or argument." The line it does this with is
fsoStream.Write (HTML)
The code for the first site (I have six) is EXACTLY the same as the code for the other 5 (In fact I copied and pasted, changing only the filenames when needed). I messed around a bit and found out that it can write non-variable strings just fine (ie, fsoStream.Write ("Quack")). Why might it be having trouble with my HTML string variable, that contains the HTTPReq.ResponseText, only for the first one? Here's some of the code:
Private Sub CmdCheck_Click()
Dim HttpReq As New MSXML2.XMLHTTP
Dim FileSys As FileSystemObject
Dim f As File
Dim fsoStream As TextStream
Dim CACHE As String
Dim HTML As String
Set fsoStream = Nothing
Set FileSys = Nothing
Set f = Nothing
''''''''''''''''''
Set FileSys = New FileSystemObject
Set f = FileSys.GetFile("C:\windows\HTML checker\site1cache.txt")
If txtSite2 <> "" Then
HttpReq.open "GET", txtSite1, False
HttpReq.send
If (HttpReq.Status > 299 Or HttpReq.Status < 200) Then
MsgBox "Site 1 could not be reached!", vbExclamation, "Error"
Else
HTML = HttpReq.responseText
Set fsoStream = f.OpenAsTextStream(ForWriting)
fsoStream.Write (HTML)
End If
Set fsoStream = f.OpenAsTextStream(ForReading)
CACHE = fsoStream.ReadAll
If HTML <> CACHE Then
site1 = 1
Set fsoStream = f.OpenAsTextStream(ForWriting)
fsoStream.Write (HTML)
End If
End If
Set fsoStream = Nothing
Set FileSys = Nothing
Set f = Nothing
''''''''''''''''''''
Set FileSys = New FileSystemObject
Set f = FileSys.GetFile("C:\windows\HTML checker\site2cache.txt")
If txtSite2 <> "" Then
HttpReq.open "GET", txtSite2, False
HttpReq.send
If (HttpReq.Status > 299 Or HttpReq.Status < 200) Then
MsgBox "Site 2 could not be reached!", vbExclamation, "Error"
Else
HTML = HttpReq.responseText
Set fsoStream = f.OpenAsTextStream(ForWriting)
fsoStream.Write (HTML)
End If
Set fsoStream = f.OpenAsTextStream(ForReading)
CACHE = fsoStream.ReadAll
If HTML <> CACHE Then
site2 = 1
Set fsoStream = f.OpenAsTextStream(ForWriting)
fsoStream.Write (HTML)
End If
End If
Set fsoStream = Nothing
Set FileSys = Nothing
Set f = Nothing
''''''''''''''''''''''