Blank spaces in Freebasic

The forum for all of your Freebasic needs!

Moderators: Pete, Mods

midgemaster
Newbie
Posts: 6
Joined: Fri Jun 26, 2009 4:40 am

Blank spaces in Freebasic

Postby midgemaster » Fri Jun 26, 2009 4:45 am

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

User avatar
T'lon Nanaki
Coder
Posts: 42
Joined: Mon Aug 04, 2008 12:46 pm
Location: Denver Colorado
Contact:

Postby T'lon Nanaki » Sun Jun 28, 2009 3:40 pm

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!
carpe diem!

midgemaster
Newbie
Posts: 6
Joined: Fri Jun 26, 2009 4:40 am

Blank spaces in Freebasic

Postby midgemaster » Mon Jun 29, 2009 1:42 am

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

User avatar
burger2227
Veteran
Posts: 2142
Joined: Mon Aug 21, 2006 12:40 am
Location: Pittsburgh, PA

Postby burger2227 » Mon Jun 29, 2009 10:56 am

Reading with what? INPUT, LINE INPUT, GET?

How was the file created? With PRINT?
Please acknowledge and thank members who answer your questions!
QB64 is a FREE QBasic compiler for WIN, MAC(OSX) and LINUX : http://www.QB64.NET
Get my Q-Basics demonstrator: https://www.dropbox.com/s/fdmgp91d6h8ps ... s.zip?dl=0

midgemaster
Newbie
Posts: 6
Joined: Fri Jun 26, 2009 4:40 am

Blank spaces in Freebasic

Postby midgemaster » Mon Jun 29, 2009 11:45 am

Hi there

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

Midgemaster

User avatar
burger2227
Veteran
Posts: 2142
Joined: Mon Aug 21, 2006 12:40 am
Location: Pittsburgh, PA

Postby burger2227 » Mon Jun 29, 2009 4:24 pm

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.
Please acknowledge and thank members who answer your questions!
QB64 is a FREE QBasic compiler for WIN, MAC(OSX) and LINUX : http://www.QB64.NET
Get my Q-Basics demonstrator: https://www.dropbox.com/s/fdmgp91d6h8ps ... s.zip?dl=0

midgemaster
Newbie
Posts: 6
Joined: Fri Jun 26, 2009 4:40 am

Blank spaces in Freebasic

Postby midgemaster » Tue Jun 30, 2009 2:16 am

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

User avatar
T'lon Nanaki
Coder
Posts: 42
Joined: Mon Aug 04, 2008 12:46 pm
Location: Denver Colorado
Contact:

Postby T'lon Nanaki » Tue Jun 30, 2009 11:37 am

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 :)
carpe diem!

midgemaster
Newbie
Posts: 6
Joined: Fri Jun 26, 2009 4:40 am

Blank spaces in Freebasic

Postby midgemaster » Wed Jul 01, 2009 6:25 am

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

User avatar
T'lon Nanaki
Coder
Posts: 42
Joined: Mon Aug 04, 2008 12:46 pm
Location: Denver Colorado
Contact:

Postby T'lon Nanaki » Wed Jul 01, 2009 2:39 pm

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.
carpe diem!

User avatar
burger2227
Veteran
Posts: 2142
Joined: Mon Aug 21, 2006 12:40 am
Location: Pittsburgh, PA

Postby burger2227 » Wed Jul 01, 2009 2:54 pm

Clicking on Email button will use your Email service. NOT the person's you are emailing! Mine uses my Outlook Express.
Please acknowledge and thank members who answer your questions!
QB64 is a FREE QBasic compiler for WIN, MAC(OSX) and LINUX : http://www.QB64.NET
Get my Q-Basics demonstrator: https://www.dropbox.com/s/fdmgp91d6h8ps ... s.zip?dl=0

lp0cua0
Newbie
Posts: 1
Joined: Wed Nov 11, 2009 5:41 pm

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

Postby lp0cua0 » Wed Nov 11, 2009 6:00 pm

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. :)


Return to “Freebasic Questions & Answers”

Who is online

Users browsing this forum: No registered users and 2 guests