Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Need help in sequential files! 1

Status
Not open for further replies.

annanathan

Programmer
May 1, 2002
24
0
0
CA
Hi all,
I have an INI files with data that I need to read to then manipulate it. I also have comments in this file. A commented line in this INI file would have a semi-colon at the beginning of the line

eg. ;comment here

How can I write a code for this so that if the read line is commented then skip the line and go to the next line, else
read word by word into different variables. ( I know exacly how many words are in each line... 4)

Thank you.
 
Dim oFileSystem As New FileSystemObject
Dim oFile As TextStream
Dim sText As String
Dim sChar As String

Set oFile = oFileSystem.OpenTextFile("MyFile.INI", ForReading)

While Not oFile.AtEndOfStream
sText = oFile.ReadLine
sChar = Left$(sText, 1)
Select Case sChar
Case ";" 'Do nothing - ignore comment lines.
Case "A" 'Handle other line types if you want to.
.
.
.
Case "Z" 'Handle other line types if you want to.
Case else 'Default line handling....
. 'Parse the line,
. 'Execute commands,
. 'Etc....
End Select
Wend

oFile.Close
------------

Hope this helps.

WB
 
helo

have u used FileSystemObjects for file i/o or classic file i/o methods.

if u used FSO then it has a method called "skipLines()", tr using that in a if-block that checks the very first char of line if its ; skip that line else parse the line.

try it. if u feel some difficulty write me, i'll codify it all for u.

ComputerJin.
 
Hi guys,
Well... I don't wanna sound dumn, but I have never used FSO (FileSystemObecjet) What is it? How do u use it. When I press F2 to view the Object Browse, I don't see it there.

Can you please give me some info?
Thank you in advance.
 
The example code I provided (the first response above) makes use of the File System Object -- note that the FSO is invoked by the first Dim statement.

On your VB menu bar, click Project, then click References...this will cause the References form to appear. Select "Microsoft Scripting Runtime" in order to make FSO available to your project.

If you have never used FSO before, you can get detailed information in your VB on-line help.

WB
 
Thank you!
I got it. You guys of realy good help.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top