Want to protect your cyber security and still get fast solutions? Ask a secure question today.Go Premium

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 262
  • Last Modified:

Please help to straighten out this "TEXT" formatting problem

I need this routine to grab the source code from a webpage and save it to a text file.
I then need to import the text file (command1 click code) and be able to import a line at a time for parsing purposes.
If I run this (importpage first then command1_click) an output file gets created.
If I open it in my browser all looks great, but if I open it in Notepad its all over the place and my
"Line Input" statement doesn't input a line at a time because there doesn't seem to be any CR/LF's.
What's wrong here please?

This is the code:
-------------------
Sub importpage()
    Dim sHTML As String
    Dim sURL As String
    sURL = "http://aolsvc.weather.aol.com/main.adp?location=USNY0181"
    sHTML = Inet1.OpenURL(sURL)
  Open "C:\page.html" For Output As #1
    Print #1, sHTML
Close #1
End Sub

Private Sub Command1_Click()
importpage
Open "C:\page.htm" For Input As #1
While Not EOF(1)
Line Input #1, a$
MsgBox a$
Wend




End Sub
0
rbender
Asked:
rbender
  • 4
  • 3
  • 2
  • +1
1 Solution
 
sakuya_suCommented:
have a text box or message box that will display the data in sHTML as it comes in, maybe the Inet object retrieve the HTML without the Line feeds?
0
 
nffvrxqgrcfqvvcCommented:
So you opened in notepad? Try the Word Wrap option and see if it looks like normal formating.
0
 
Cem TürkSenior Software EngineerCommented:

 Dim sHTML As String

Sub importpage()
    Dim sURL As String
    sURL = "http://aolsvc.weather.aol.com/main.adp?location=USNY0181"
    sHTML = Inet1.OpenURL(sURL)
End Sub

Private Sub Command1_Click()
importpage
lines=split(sHTML,vbCrLf)
For i = 0 to Ubound(lines)
msgbox lines(i)
Next
End Sub

0
Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
Cem TürkSenior Software EngineerCommented:
you can get the content into lines on the fly. you dont need to write and read from a file
0
 
rbenderAuthor Commented:
cem_turk:
Here's what happens on my end:
I run the code (as you have it)...
When I debug and watch, when I get to the line:
  For i = 0 to Ubound(lines)
I see Ubound(lines) = 0
Then, when msgbox lines(i) hits, I get the entire source for the whole page.
What the?

 
0
 
Cem TürkSenior Software EngineerCommented:
this means that lines in the code not ends with vbCrLf so

try replacing

lines=split(sHTML,vbCrLf)

with

lines=split(sHTML,chr(13))

0
 
sakuya_suCommented:
also you can try lines=split(sHTML, vbNewLine)
0
 
rbenderAuthor Commented:
Points up to 75.

Listen to this please:
When I run my code.... I am sending the "importer" results to a "TEXT BOX" on my form.
The text runs completely to the right and doesn't observe ANY CR/LF'ds.
Then I'm sending the contents of the TextBox to a FILE on my HD.
If I open the file in Notepad, it looks like the "NoCRLFExample.txt" found on my FTP site:
http://www.cedgeonline.com/voiceover/store/
(just in case, I have captured a screen shot of the text as it appears in Notepad as well)
If I select all text and PASTE it into the COMMENTS box on this thread. (I was going to illustrate) IT ALL FORMATS PERFECTLY !. Then if I copy and paste from here to Notepad, it looks fine.
I'm stumped.


-----------------------------------------------------------------------------------------
0
 
rbenderAuthor Commented:
If there is another way to import an HTML page into a Text file...I'm more that open to the suggestion.
0
 
Cem TürkSenior Software EngineerCommented:
i have tested the following code and it works nice

 Dim sHTML As String

Sub importpage()
    Dim sURL As String
    sURL = "http://aolsvc.weather.aol.com/main.adp?location=USNY0181"
    sHTML = Inet1.OpenURL(sURL)
  End Sub

Private Sub Command1_Click()
importpage
lines = Split(sHTML, Chr(10))
For i = 0 To UBound(lines)
MsgBox lines(i)
Next
End Sub
0

Featured Post

Free Tool: Site Down Detector

Helpful to verify reports of your own downtime, or to double check a downed website you are trying to access.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

  • 4
  • 3
  • 2
  • +1
Tackle projects and never again get stuck behind a technical roadblock.
Join Now