473,425 Members | 1,673 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes and contribute your articles to a community of 473,425 developers and data experts.

How to read a file in VB - Part 1 - VB6, Line Input

8,435 Expert 8TB
Here is a very simple example routine which reads a text file, one line at a time. This uses the built-in VB statements only. Later we will cover the FileSystemObject, which provides greater functionality at the expense of slightly greater code complexity.

This self-contained routine can be pasted into a code module and called from anywhere, including the immediate window. It will expect you to pass the name of a file (including the path if it isn't in the current directory) and will copy the contents of the file to the immediate window. Note it will also avoid, as far as possible, interfering with any other processing which may be going on at the time.

Expand|Select|Wrap|Line Numbers
  1. Public Sub DumpFile_V01(ByVal FileName As String)
  2.   Dim FileNo As Long
  3.   Dim LineNo As Long
  4.   Dim LineText As String
  5.  
  6.   FileNo = FreeFile ' Get next available file number.
  7.  
  8.   Open FileName For Input Access Read Shared As #FileNo
  9.   Do Until EOF(FileNo) ' Repeat until end of file...
  10.     Line Input #FileNo, LineText ' Read a line from the file.
  11.     LineNo = LineNo + 1
  12.     Debug.Print Format(LineNo, "00000"); ": "; LineText
  13.     DoEvents ' Allow Windows to handle other tasks.
  14.   Loop
  15.   Close #FileNo
  16. End Sub
May 16 '07 #1
0 55976

Sign in to post your reply or Sign up for a free account.

Similar topics

4
by: JrdA | last post by:
Hi NG My programs does following: - ofstream writes fx. "1234#01/26/04#" to a txt-file Now i have a txt-file containing : 1234#01/26/04# 424#01/26/04#
5
by: Rafal 'Raf256' Maj | last post by:
Hi, I need to parse a file. This means reading from it as from std::istream. But - sometimes I also need to put-back some text I read before. What type of string can I use for that? Something...
18
by: jas | last post by:
Hi, I would like to start a new process and be able to read/write from/to it. I have tried things like... import subprocess as sp p = sp.Popen("cmd.exe", stdout=sp.PIPE)...
40
by: Abby | last post by:
My .dat file will contain information like below. /////////// First 0x04 0x05 0x06 Second 0x07
1
by: Magix | last post by:
Hi, I have these string data: str_data1, str_data2, str_data3, which capture some value after a routine process A. Then I would like to write (append) these 3 string values into a text file each...
2
by: Rajen | last post by:
Suppose the field length is 25 characters. After entering the 25th character, it should be available to process. Program should not wait for the user to press enter/return key. Thank you.
2
by: peter.vanna | last post by:
I would like to write a program to read a text file (data.txt) on Windows and Linux machines. data.txt is formated as follows: 1 10 100 1000 2 20 (a new but empty line)
9
by: =?Utf-8?B?QnJpYW4gQ29vaw==?= | last post by:
I want to open a text file and format it into a specific line and then apply color to a specific location of the text and then display it in a RichTextBox after all of this is done. I can do all...
6
by: arnuld | last post by:
This works fine, I welcome any views/advices/coding-practices :) /* C++ Primer - 4/e * * Exercise 8.9 * STATEMENT: * write a program to store each line from a file into a *...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
1
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.