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 TouchToneTommy on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

[Reading TxtFiles] Newbie Help -Only the Patient Should Open- 1

Status
Not open for further replies.

BFreshour

Programmer
Mar 20, 2002
84
Let me first tell you I have just started programming in VB.NET. I'm a very good ColdFusion programmer so I have the 'mindset' of a programmer (somewhat). I'm trying to design a program that does something specific, like parse a text file.

It should have a form with a TextBox where you can enter a string. The string needs to support spaces at the beginning and end of it. For instance, " 3445 " instead of "3445".

Next it needs to have a BROWSE where you can select the file you wish to Parse and a Parse button.

What this program does when you click Parse is run through the file you select and remove ANY lines with your string in it. However, not only does it need to remove that line, it needs to remove the line after that.

Like I said, I'm a newbie VB.NET guy and although I'm working my way through WROX Publishing books I'm not near up to this level. I'm trying to design the form now. If anyone can give me some lines of 'code' or some tips on how exactly I need to do this, I would appreciate it.

Here's a sample of what the file looks like:
Code:
01 04/29/02 08:08 00:02:15 --2---  000028          2561                   3557
                28   0    000000
01 04/29/02 08:08 00:00:22 --2---  000027          3365                   3719
                27   0    000000

We should probably note that those aren't TABS put spaces in between the items.
 
Ack! Just pretend that the second line after each 01 is really attached on to the end and that the lines beginning with 27 and 28 are indented second lines.
 
So you are dealing with fixed-length strings (no delimiters), correct?

Here's an example that opens a textfile, reads it into a string object, then splits it into an array.

Dim sEDI As String
Dim srReader As System.IO.StreamReader = New System.IO.StreamReader("C:\projects\837ansiFile\edversion.001", False)
Dim arData() As String
Dim iint As Integer

sEDI = srReader.ReadToEnd
arData = Split(sEDI, "~")

In my case the textfile data is one big string where each record is separated by the "~" so I don't deal with the strings as a line until it's split into arData. There is an srReader.ReadLine method that can be used if your textfile already has the records separtated by CRLF's.

Now since it seems you don't have delimeters you would then have to parse the string based upon position:

sStrVar = Microsoft.VisualBasic.Mid(arData(0), 1, 3)

Hope this helps; if I missed what you were looking for let me know.

Good luck,

O.

 
I've gotten this project done using StreamWriter and StreamReader. However, I couldn't get it to update the actual file, it had to write a NEW temporary file.

Now what I'd like to do, is after both Streams are Closed(), copy the temporary file over the file opened and delete the temporary file. I've tried finding help on this to no avail. Anyone got some tips?

Brad
 
Dim x As System.IO.File

x.copy("filesource", "filedestination", [overwrite-true or false])
 
One more stupid question... is there anyway to compile this so that the PC running the 'Release' build doesn't have to have the .NET Framework installed?
 
No, not if it is an exe. You could probably do the same thing as an ASP app, thus only having to install the Framework on your server. I haven't played around with this yet but VB in ASP.NET is supposed to have all the functionality of of VB.NET.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top