Blank spaces in Freebasic
-
- Newbie
- Posts: 6
- Joined: Fri Jun 26, 2009 4:40 am
Blank spaces in Freebasic
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
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
- T'lon Nanaki
- Coder
- Posts: 42
- Joined: Mon Aug 04, 2008 12:46 pm
- Location: Denver Colorado
- Contact:
-
- Newbie
- Posts: 6
- Joined: Fri Jun 26, 2009 4:40 am
Blank spaces in Freebasic
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
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
- burger2227
- Veteran
- Posts: 2466
- Joined: Mon Aug 21, 2006 12:40 am
- Location: Pittsburgh, PA
Reading with what? INPUT, LINE INPUT, GET?
How was the file created? With PRINT?
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 : https://www.qb64.org/forum/index.php
Get my Q-Basics demonstrator: https://www.dropbox.com/s/fdmgp91d6h8ps ... s.zip?dl=0
QB64 is a FREE QBasic compiler for WIN, MAC(OSX) and LINUX : https://www.qb64.org/forum/index.php
Get my Q-Basics demonstrator: https://www.dropbox.com/s/fdmgp91d6h8ps ... s.zip?dl=0
-
- Newbie
- Posts: 6
- Joined: Fri Jun 26, 2009 4:40 am
Blank spaces in Freebasic
Hi there
Reading with Input in Freebasic. Created with Print in QBasic.
Midgemaster
Reading with Input in Freebasic. Created with Print in QBasic.
Midgemaster
- burger2227
- Veteran
- Posts: 2466
- Joined: Mon Aug 21, 2006 12:40 am
- Location: Pittsburgh, PA
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.
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 : https://www.qb64.org/forum/index.php
Get my Q-Basics demonstrator: https://www.dropbox.com/s/fdmgp91d6h8ps ... s.zip?dl=0
QB64 is a FREE QBasic compiler for WIN, MAC(OSX) and LINUX : https://www.qb64.org/forum/index.php
Get my Q-Basics demonstrator: https://www.dropbox.com/s/fdmgp91d6h8ps ... s.zip?dl=0
-
- Newbie
- Posts: 6
- Joined: Fri Jun 26, 2009 4:40 am
Blank spaces in Freebasic
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
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
- T'lon Nanaki
- Coder
- Posts: 42
- Joined: Mon Aug 04, 2008 12:46 pm
- Location: Denver Colorado
- Contact:
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!)
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 ![Smile :)](./images/smilies/icon_smile.gif)
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
![Smile :)](./images/smilies/icon_smile.gif)
carpe diem!
-
- Newbie
- Posts: 6
- Joined: Fri Jun 26, 2009 4:40 am
Blank spaces in Freebasic
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
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
- T'lon Nanaki
- Coder
- Posts: 42
- Joined: Mon Aug 04, 2008 12:46 pm
- Location: Denver Colorado
- Contact:
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.
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!
- burger2227
- Veteran
- Posts: 2466
- Joined: Mon Aug 21, 2006 12:40 am
- Location: Pittsburgh, PA
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 : https://www.qb64.org/forum/index.php
Get my Q-Basics demonstrator: https://www.dropbox.com/s/fdmgp91d6h8ps ... s.zip?dl=0
QB64 is a FREE QBasic compiler for WIN, MAC(OSX) and LINUX : https://www.qb64.org/forum/index.php
Get my Q-Basics demonstrator: https://www.dropbox.com/s/fdmgp91d6h8ps ... s.zip?dl=0
A couple of ideas...better late than never?
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.![Smile :)](./images/smilies/icon_smile.gif)
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.
![Smile :)](./images/smilies/icon_smile.gif)