Results 1 to 12 of 12

Thread: Listbox Adding

  1. #1

    Thread Starter
    Lively Member se7en's Avatar
    Join Date
    Dec 2006
    Location
    Manchester, UK
    Posts
    118

    Listbox Adding

    ok i want to show the contents of a txt file located online. iv used inet to grab the content of the text file:

    form Code:
    1. Private Sub Form_Load()
    2. Dim UpData As String
    3.     UpData = Inet2.OpenURL("http://lazyrecords.co.uk/topfloordjs/LRMP/data.txt")
    4.    
    5.         DoEvents
    6.     Inet2.Cancel
    7.     ServerDataParse UpData
    8. Debug.Print UpData
    9. End Sub

    but in this txt file it has carridge return (char(10)) and i want it to show in the listbox as new items. this is wat iv got so far in the module:

    Module Code:
    1. Public Sub ServerDataParse(SiteFile As String)
    2. For i = 0 To Form1.List2.ListIndex
    3. ' this is where im gettin lost...
    4.  
    5. Form1.List2.AddItem SiteFile
    6. ' Form1.Text1 = SiteFile
    7. End Sub

    Can anyone help me out?

    Did a reply help answer your questions? Please RATE good posts!
    When you have received an answer to your question, please mark it as resolved using the Thread Tools menu.
    New Laptop System: Intel Dual-Core T2060 2.0GHz • 533MHz FSB • 2MB Cache • 1024MB RAM • 120GB Hard Drive • Dual Layer DVD ReWriter MultiDrive • 15.4" Widescreen Display • Microsoft Windows Vista Ultimate • 128MB Intel GMA 900 UMA Graphics

  2. #2
    I'm about to be a PowerPoster! Hack's Avatar
    Join Date
    Aug 2001
    Location
    Searching for mendhak
    Posts
    58,333

    Re: Listbox Adding

    Is this what you are looking for?
    Code:
    Public Sub ServerDataParse(SiteFile As String)
    Open SiteFile For Input As #1
    While Not EOF(1)
        Line Input #1, sData
        List1.AddItem sData
    Wend
    Close #1
    End Sub

  3. #3

    Thread Starter
    Lively Member se7en's Avatar
    Join Date
    Dec 2006
    Location
    Manchester, UK
    Posts
    118

    Re: Listbox Adding

    vb Code:
    1. Public Sub ServerDataParse(SiteFile As String)
    2. Open SiteFile For Input As #1
    3. While Not EOF(1)
    4.     Line Input #1, sData
    5.     Form1.List2.AddItem sData
    6. Wend
    7. Close #1
    8. End Sub

    Open SiteFile For Input As #1
    Bad file name or number.

    Did a reply help answer your questions? Please RATE good posts!
    When you have received an answer to your question, please mark it as resolved using the Thread Tools menu.
    New Laptop System: Intel Dual-Core T2060 2.0GHz • 533MHz FSB • 2MB Cache • 1024MB RAM • 120GB Hard Drive • Dual Layer DVD ReWriter MultiDrive • 15.4" Widescreen Display • Microsoft Windows Vista Ultimate • 128MB Intel GMA 900 UMA Graphics

  4. #4
    Super Moderator si_the_geek's Avatar
    Join Date
    Jul 2002
    Location
    Bristol, UK
    Posts
    41,974

    Re: Listbox Adding

    What does SiteFile contain?

  5. #5

    Thread Starter
    Lively Member se7en's Avatar
    Join Date
    Dec 2006
    Location
    Manchester, UK
    Posts
    118

    Re: Listbox Adding

    just updates from a txt file online.

    Did a reply help answer your questions? Please RATE good posts!
    When you have received an answer to your question, please mark it as resolved using the Thread Tools menu.
    New Laptop System: Intel Dual-Core T2060 2.0GHz • 533MHz FSB • 2MB Cache • 1024MB RAM • 120GB Hard Drive • Dual Layer DVD ReWriter MultiDrive • 15.4" Widescreen Display • Microsoft Windows Vista Ultimate • 128MB Intel GMA 900 UMA Graphics

  6. #6
    Super Moderator si_the_geek's Avatar
    Join Date
    Jul 2002
    Location
    Bristol, UK
    Posts
    41,974

    Re: Listbox Adding

    It seems you misunderstood what I was asking... What value does SiteFile contain at the time of the error?

  7. #7

    Thread Starter
    Lively Member se7en's Avatar
    Join Date
    Dec 2006
    Location
    Manchester, UK
    Posts
    118

    Re: Listbox Adding

    LRMP In Development
    TESTERS NEEDED!!

    .. thats all it is. but it has the ascii chr(10) or chr(13) cnt remember which lol.

    Did a reply help answer your questions? Please RATE good posts!
    When you have received an answer to your question, please mark it as resolved using the Thread Tools menu.
    New Laptop System: Intel Dual-Core T2060 2.0GHz • 533MHz FSB • 2MB Cache • 1024MB RAM • 120GB Hard Drive • Dual Layer DVD ReWriter MultiDrive • 15.4" Widescreen Display • Microsoft Windows Vista Ultimate • 128MB Intel GMA 900 UMA Graphics

  8. #8
    New Member
    Join Date
    Jun 2006
    Location
    Nr Norwich
    Posts
    12

    Re: Listbox Adding

    Just my pennies worth, seems you may have 2 problems

    1/
    Is the text file accesible by this method via HTTP ?

    2/
    Public Sub ServerDataParse(SiteFile As String)
    DIM i
    Open SiteFile For Input As #1
    While Not EOF(1)
    Line Input #1, sData
    if len(sdata) > 1 then 'check that sData actually contains something
    for i = 1 to len(sdata)
    if mid(sdata,i,1)=chr(10) or if mid(sdata,i,1)=chr(13) then
    mid(sdata,i,1)=" "
    endif
    next
    Form1.List2.AddItem trim(sData)
    endif
    Wend
    Close #1
    End Sub

  9. #9
    PowerPoster
    Join Date
    Dec 2004
    Posts
    25,618

    Re: Listbox Adding

    sitefile is passed as a string
    try like this
    vb Code:
    1. Public Sub ServerDataParse(SiteFile As String)
    2. dim sitearr() as string
    3. sitearr = split(sitefile,chr(10))
    4. For i = 0 To ubound sitearr
    5.   Form1.List2.AddItem Sitearr(i)
    6. next
    7. End Sub
    i do my best to test code works before i post it, but sometimes am unable to do so for some reason, and usually say so if this is the case.
    Note code snippets posted are just that and do not include error handling that is required in real world applications, but avoid On Error Resume Next

    dim all variables as required as often i have done so elsewhere in my code but only posted the relevant part

    come back and mark your original post as resolved if your problem is fixed
    pete

  10. #10

    Thread Starter
    Lively Member se7en's Avatar
    Join Date
    Dec 2006
    Location
    Manchester, UK
    Posts
    118

    Re: Listbox Adding

    worked like a charm. thanx Westconn!! +1 REP

    Did a reply help answer your questions? Please RATE good posts!
    When you have received an answer to your question, please mark it as resolved using the Thread Tools menu.
    New Laptop System: Intel Dual-Core T2060 2.0GHz • 533MHz FSB • 2MB Cache • 1024MB RAM • 120GB Hard Drive • Dual Layer DVD ReWriter MultiDrive • 15.4" Widescreen Display • Microsoft Windows Vista Ultimate • 128MB Intel GMA 900 UMA Graphics

  11. #11
    I'm about to be a PowerPoster! Hack's Avatar
    Join Date
    Aug 2001
    Location
    Searching for mendhak
    Posts
    58,333

    Re: Listbox Adding

    You asked about a file but you were actually passing a string?

  12. #12
    PowerPoster
    Join Date
    Dec 2004
    Posts
    25,618

    Re: Listbox Adding

    no, the interrnet file was downloaded to string and passed to sub, just his variable name was confusing
    i do my best to test code works before i post it, but sometimes am unable to do so for some reason, and usually say so if this is the case.
    Note code snippets posted are just that and do not include error handling that is required in real world applications, but avoid On Error Resume Next

    dim all variables as required as often i have done so elsewhere in my code but only posted the relevant part

    come back and mark your original post as resolved if your problem is fixed
    pete

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width