Listbox

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • Eric Mitchell

    Listbox

    Hello All,

    I have a listbox that I want to populate with information from a text file.
    For each index in the listbox, I want to load the next line of the text
    file, until there are no more lines. I have the code to open and read each
    line from the text file, but I cannot figure out a way to read a line, put
    it into the listbox, then go to the next line and repeat the process. I know
    it will have to use a For... Next loop, but can't get the configuration
    right. Any help would be greatly appreciated!


  • Rick Rothstein

    #2
    Re: Listbox

    > I have a listbox that I want to populate with information from a text
    file.[color=blue]
    > For each index in the listbox, I want to load the next line of the[/color]
    text[color=blue]
    > file, until there are no more lines. I have the code to open and read[/color]
    each[color=blue]
    > line from the text file, but I cannot figure out a way to read a line,[/color]
    put[color=blue]
    > it into the listbox, then go to the next line and repeat the process.[/color]
    I know[color=blue]
    > it will have to use a For... Next loop, but can't get the[/color]
    configuration[color=blue]
    > right. Any help would be greatly appreciated![/color]

    Usually it is a good idea to post the code that is not working as you
    expect (or that you have so far). That way, we can adapt our answers to
    your style of programming or even make suggestions of ways we might
    approach the problem differently. Without seeing your code, the best we
    can do is give you code and hope it makes sense to you or, if it
    doesn't, that you will try and read up on the parts that are unfamiliar
    to you.

    Dim FF As Long
    Dim LineOfText As String
    FF = FreeFile
    Open "c:\temp\Bi-Weekly Work Schedule (2009).txt" For Input As #FF
    Do While Not EOF(FF)
    Line Input #FF, LineOfText
    ' If test makes sure you don't add a blank line
    If Len(LineOfText) Then List1.AddItem LineOfText
    Loop
    Close #FF

    Rick - MVP

    Comment

    • Eric Mitchell

      #3
      Re: Listbox

      That's exactly what I needed, thanks!

      -Eric

      "Rick Rothstein" <rickNOSPAMnews @NOSPAMcomcast. net> wrote in message
      news:UsSdnccYjJ ldmwjcRVn-ug@comcast.com. ..[color=blue][color=green]
      > > I have a listbox that I want to populate with information from a text[/color]
      > file.[color=green]
      > > For each index in the listbox, I want to load the next line of the[/color]
      > text[color=green]
      > > file, until there are no more lines. I have the code to open and read[/color]
      > each[color=green]
      > > line from the text file, but I cannot figure out a way to read a line,[/color]
      > put[color=green]
      > > it into the listbox, then go to the next line and repeat the process.[/color]
      > I know[color=green]
      > > it will have to use a For... Next loop, but can't get the[/color]
      > configuration[color=green]
      > > right. Any help would be greatly appreciated![/color]
      >
      > Usually it is a good idea to post the code that is not working as you
      > expect (or that you have so far). That way, we can adapt our answers to
      > your style of programming or even make suggestions of ways we might
      > approach the problem differently. Without seeing your code, the best we
      > can do is give you code and hope it makes sense to you or, if it
      > doesn't, that you will try and read up on the parts that are unfamiliar
      > to you.
      >
      > Dim FF As Long
      > Dim LineOfText As String
      > FF = FreeFile
      > Open "c:\temp\Bi-Weekly Work Schedule (2009).txt" For Input As #FF
      > Do While Not EOF(FF)
      > Line Input #FF, LineOfText
      > ' If test makes sure you don't add a blank line
      > If Len(LineOfText) Then List1.AddItem LineOfText
      > Loop
      > Close #FF
      >
      > Rick - MVP
      >[/color]


      Comment

      Working...