Wrox Programmer Forums
| Search | Today's Posts | Mark Forums Read
Beginning VB 6 For coders who are new to Visual Basic, working in VB version 6 (not .NET).
Welcome to the p2p.wrox.com Forums.

You are currently viewing the Beginning VB 6 section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
  #1 (permalink)  
Old December 11th, 2003, 01:02 PM
Registered User
Join Date: Dec 2003
Location: , , .
Posts: 1
Thanks: 0
Thanked 0 Times in 0 Posts
Send a message via MSN to tdeng
Default 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!

  #2 (permalink)  
Old December 22nd, 2003, 07:21 AM
Authorized User
Join Date: Jun 2003
Location: Great Dunmow, Essex, United Kingdom.
Posts: 50
Thanks: 0
Thanked 0 Times in 0 Posts

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

  #3 (permalink)  
Old December 22nd, 2003, 02:46 PM
Authorized User
Join Date: Aug 2003
Location: Penn Yan, New York, USA.
Posts: 30
Thanks: 0
Thanked 0 Times in 0 Posts


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
' ************************************************** *********


Similar Threads
Thread Thread Starter Forum Replies Last Post
imports - Chapter 2 sfarber53 BOOK: Beginning Java 2 2 September 19th, 2010 07:43 PM
Change color of text in a listbox? ja8261 VB.NET 2002/2003 Basics 11 April 27th, 2007 10:14 AM
How to apply text color on Listbox h@ckerz Visual Basic 2005 Basics 2 January 29th, 2007 08:14 PM
No Text in listbox khautinh C# 0 May 16th, 2005 06:09 PM
Excel Text Imports Revisited bph Access 5 April 1st, 2004 07:35 AM

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