Link to home
Start Free TrialLog in
Avatar of andyakira
andyakira

asked on

Problem Ectracting Text From Inet to List

I'm trying to list a items in a textfile into a listbox, it does add the item to the box but its adding it all into one line. ive tried splitting it with vbnewline but it dosnt seem to fix the problem, it loads Squares to replace the new line. how can i fix this
Avatar of Mike Tomlinson
Mike Tomlinson
Flag of United States of America image

Option Explicit

Private Sub Command1_Click()
    populateListBox "c:\someFile.txt"
End Sub

Private Sub populateListBox(ByVal fileName As String)
    If Dir(fileName) <> "" Then
        Dim ff As Integer
        Dim inputLine As String
       
        List1.Clear
        ff = FreeFile
        Open fileName For Input As #ff
        While Not EOF(ff)
            Line Input #ff, inputLine
            List1.AddItem inputLine
        Wend
        Close #ff
        MsgBox "Import Complete", vbInformation, "File Import"
    Else
        MsgBox "File not found: " & fileName, vbCritical, "File Import"
    End If
End Sub
Avatar of andyakira
andyakira

ASKER

I mean listing a text file from a url to a list box
Can you show me how you are downloading the text file right now?

Idle_Mind
THere are two parts of your problem (I have had a bit of difficulty understanding you too).

One is that it comes in one line and the second is it adds squares. You will be glad to know that both problems can be fixed simultaneously.

If you are trying to read the content of a listbox and dump it INTO a text file, the code would be like:

handle = Freefile()
dim filename for output as handle
For i = 0 to list1.count
    Print #handle, list1.list(i)
Next
close #handle


   Dim MyLines As Variant
    Dim i As Long
    MyLines = Split(Inet1.OpenURL("http://www.ietf.org/rfc/rfc2616.txt"), vbNewLine)
    For i = LBound(MyLines) To UBound(MyLines)
   List1.AddItem MyLines(i)
   Next i
that is what i'm using. it adds it all into one line ;{
ASKER CERTIFIED SOLUTION
Avatar of KarcOrigin
KarcOrigin

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial