p2p.wrox.com Forums

p2p.wrox.com Forums (http://p2p.wrox.com/index.php)
-   Beginning VB 6 (http://p2p.wrox.com/forumdisplay.php?f=75)
-   -   Help on ListBox imports text (http://p2p.wrox.com/showthread.php?t=7140)

tdeng December 11th, 2003 01:02 PM

Help on ListBox imports text
Just start reading VB in 2 days...
and try a creat a listbox so it will populate a list of items stored in a plain text file when form loads. Please help!


Bill Crawley December 22nd, 2003 07:21 AM

First of all in your vb project you need to go to tools/refrences and select the microsoft scripting runtime. This will allow you to open the file and read a line at a time.

Something like:

Dim f As Scripting.FileSystemObject
Dim x As TextStream

Set f = New FileSystemObject
x = f.OpenTextFile(myfilename, ForReading, , TristateFalse)
Do While Not x.AtEndOfStream
    myStr = x.ReadLine
    ListBox.AddItem myStr
set f = nothing

CarlR December 22nd, 2003 02:46 PM


You can also read a text file into a listbox using native VB -- without any references. For instance, assume :"C:\Temp.txt" is the
file containing the info and lstData is the listbox you wish to fill:

' ************************************************** *********
intChan = FreeFile
Open "C:\Temp.txt" For Input As intChan
Do While Not EOF(intChan)
  Line Input #intChan, InTxt 'InTxt holds each line of data
  lstData.AddItem InTxt
Close intReadChan
' ************************************************** *********


All times are GMT -4. The time now is 09:17 PM.

Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
© 2013 John Wiley & Sons, Inc.