Page 1 of 1

Blank spaces in Freebasic

Posted: Fri Jun 26, 2009 4:45 am
by midgemaster
Hi there

In Freebasic, if reading a file line by line, blank lines seems to be ignored and the following line is used instead. If I replace a blank line with "", everything works perfectly.

Is this the way it is supposed to work?

Thanks

Midgemaster

Posted: Sun Jun 28, 2009 3:40 pm
by T'lon Nanaki
could you try to explain what your getting at with a bit more detail...
are you trying to read a source file, a file created through FB, my mothers recipe for pea soup? curiosity kills and Im 6ft under so dig away!

Blank spaces in Freebasic

Posted: Mon Jun 29, 2009 1:42 am
by midgemaster
Hi T'lon

I'm trying to read sequential files created by QBasic. Each line in the files has only one piece of data. Part of an example file looks like this :

.
.
PETONG (GB)

1
0
BOLSHOI Ballet
.
.

When the code gets to the blank between 'PETONG (GB) and '1', Freebasic seems to ignore it and picks up the '1' instead. If I replace the clank line with "" it works fine.

I hope that's clearer.

Midgemaster

Posted: Mon Jun 29, 2009 10:56 am
by burger2227
Reading with what? INPUT, LINE INPUT, GET?

How was the file created? With PRINT?

Blank spaces in Freebasic

Posted: Mon Jun 29, 2009 11:45 am
by midgemaster
Hi there

Reading with Input in Freebasic. Created with Print in QBasic.

Midgemaster

Posted: Mon Jun 29, 2009 4:24 pm
by burger2227
Why don't you consider using WRITE # to create the file? It allows you to put string and number values on one line of a file separated by commas.
INPUT # always stops at a comma no matter where it is! Even in a string.
So the best way to read a printed file would be LINE INPUT # anyhow.

You don't need to convert number strings back using the following method:

WRITE #1, person$, score%, DATE$, TIME$

To read it use INPUT #1, player$, last%, Day$, Hour$

The number of values must match each statement and the variable types.

Then format the values any way you want on the screen.

Blank spaces in Freebasic

Posted: Tue Jun 30, 2009 2:16 am
by midgemaster
Hi there

Yes, WRITE would do the trick.

The problem is that I have some 2,500,000 legacy files created using PRINT in QBasic, and peppered with blanks. Naturally I don't wish to have to re-create them.

Midgemaster

Posted: Tue Jun 30, 2009 11:37 am
by T'lon Nanaki
well, I think im stumped on a solution for this sence i really never came across this particulare problem before. I tried to recreate it by making a dummy file for FB to read and the blank lines came up as 0's for me when it was read using input#, I even tryed to place a bunch of commas and got extra 0's. then agian it might be that i wrote the file in notepad and not in QB.
perhaps you should try using line input# an using val() to convert string numbers into integer/single, either that or running a code that opens your files and places a 0 or "" at each blank line.

this small code will do that(tested it myself too!)

Code: Select all

Dim As String retstr
Open (unformmated file name) For Input As #1
Open (formatted file name) For Output As #2


Do Until Eof(1)
	Line input #1,retstr
	If retstr="" Then
		Print #2,"0"
	Else
		Print #2,retstr		
	EndIf		
Loop

if you plug this into a code that gets all files in a directory (assuming that your 2million+ files are all located in one place) you can format all the files in one run. but be a good programmer and back them up first just in case :)

Blank spaces in Freebasic

Posted: Wed Jul 01, 2009 6:25 am
by midgemaster
Hi T'lon

Unfortunately the files are spread over literally hundreds of directories so working through them might not be practical.

I see the forum provides the facility to send e-mails. Do you know whether attachments are permitted? If so, I could e-mail you with an example file attached (the files are small).

Midge

Posted: Wed Jul 01, 2009 2:39 pm
by T'lon Nanaki
I really don't know if the email capablities here allow attachments sense I stick to just trying to help out with problems posted on the forums.
how ever if you like you can send your attachment to my yahoo mail at
talon_nanaki at yahoo dot com, just keep in mind that I don't claim to know all(that would be silly to say) and I might not be able to help.

Posted: Wed Jul 01, 2009 2:54 pm
by burger2227
Clicking on Email button will use your Email service. NOT the person's you are emailing! Mine uses my Outlook Express.

A couple of ideas...better late than never?

Posted: Wed Nov 11, 2009 6:00 pm
by lp0cua0
First, you need to find out what the 'blank' line actually is, acsii wise.

It may be as simple as a CR w/o a LF, in which case you could test for that, then shell out to u2d (unix to dos, takes care of cr to cr/lf), then finish the run you need.

Or, you could:

Open xyz$ for binary as #1

then do some scanning/reencoding to convert whatever the blank line is to a regular cr/lf and continue on.

Me, I'd add a header or a footer to each file as it's processed, then check for it on opening a file, discard the header/footer if present, and continue.
If the header/footer isn't present, then pass the file through the 'recoder' routine, add header/footer, and write file back out.
That should start to save quite a few machine cycles as the files slowly get worked through. That's just me though. :)