BBC BASIC for Windows
« BB4W can't open file with no extension! »

Welcome Guest. Please Login or Register.
Apr 5th, 2018, 11:04pm



ATTENTION MEMBERS: Conforums will be closing it doors and discontinuing its service on April 15, 2018.
Ad-Free has been deactivated. Outstanding Ad-Free credits will be reimbursed to respective payment methods.

If you require a dump of the post on your message board, please come to the support board and request it.


Thank you Conforums members.

BBC BASIC for Windows Resources
Online BBC BASIC for Windows documentation
BBC BASIC for Windows Beginners' Tutorial
BBC BASIC Home Page
BBC BASIC on Rosetta Code
BBC BASIC discussion group
BBC BASIC for Windows Programmers' Reference

« Previous Topic | Next Topic »
Pages: 1  Notify Send Topic Print
 thread  Author  Topic: BB4W can't open file with no extension!  (Read 847 times)
Endymion
New Member
Image


member is offline

Avatar

Write spaghetti-code for food!


PM

Gender: Male
Posts: 7
xx BB4W can't open file with no extension!
« Thread started on: May 15th, 2012, 06:37am »

Code:
      FILE$ = "SCH_LIST"
      File1% = openin(FILE$)
      if not File1% then end
...other parts of the program.... 


This program doesn't work. Renaming file to "SCH_LIST.XXX" solves problem. Dot (FILE$ = "SCH_LIST.") didn't help.
« Last Edit: May 15th, 2012, 06:52am by Endymion » User IP Logged

I wanted to do something. I wanted to do something as badly as a genie who's been let out of his bottle for the first time in a thousand years. Anything at all: Raise up castles, lay waste cities, program in Basic, or embroider in cross-stitch. -- Nochnoy Dozor (The Night Watch) By Sergei Lukyanenko
VBI
Guest
xx Re: BB4W can't open file with no extension!
« Reply #1 on: May 15th, 2012, 07:42am »

Here's an example from one of my programs which works -

Code:
        infile$ = @dir$+"copyright"
        
        
        REM SAVE PROMs
        IF click% = 4 THEN
          REM Check if copyright file exists & add contents to prombuff%
          infile=OPENIN(infile$+".")
          IF infile THEN
            loc% = promsize%-100
            REPEAT
              temp%=BGET#infile
              prombuff%?loc% = temp%
              loc% = loc% + 1
            UNTIL EOF#infile

 


This loads a file named "copyright" which has no extension.
« Last Edit: May 15th, 2012, 08:05am by VBI » User IP Logged

admin
Administrator
ImageImageImageImageImage


member is offline

Avatar




PM


Posts: 1145
xx Re: BB4W can't open file with no extension!
« Reply #2 on: May 15th, 2012, 08:15am »

on May 15th, 2012, 06:37am, Endymion wrote:
This program doesn't work. Renaming file to "SCH_LIST.XXX" solves problem.

If you omit the 'dot' BBC BASIC assumes a default extension (often .BBC, but it depends on the context). If you want to open a file with no extension, simply use a trailing 'dot':

Code:
      FILE$ = "SCH_LIST."
      File1% = openin(FILE$) 

See this Wiki article:
http://bb4w.wikispaces.com/Accessing+files+with+no+extension

Code:
if not File1% then end 

That won't work because File1% is not a Boolean. Instead, test for the value being zero:

Code:
if File1%=0 then end 

Richard.
User IP Logged

Endymion
New Member
Image


member is offline

Avatar

Write spaghetti-code for food!


PM

Gender: Male
Posts: 7
xx Re: BB4W can't open file with no extension!
« Reply #3 on: May 15th, 2012, 12:42pm »

on May 15th, 2012, 08:15am, Richard Russell wrote:
If you omit the 'dot' BBC BASIC assumes a default extension (often .BBC, but it depends on the context).


.XXX and .BBC are equally suited to me.

Quote:
If you want to open a file with no extension, simply use a trailing 'dot':


Very strange. It was the first idea that came into my head. For some reason, did not work.

Quote:
Code:
if not File1% then end 

That won't work because File1% is not a Boolean. Instead, test for the value being zero:

Code:
if File1%=0 then end 

Richard.


I was guided by Rosetta Code - http://rosettacode.org/wiki/Ensure_that_a_file_exists#BBC_BASIC
« Last Edit: May 15th, 2012, 12:43pm by Endymion » User IP Logged

I wanted to do something. I wanted to do something as badly as a genie who's been let out of his bottle for the first time in a thousand years. Anything at all: Raise up castles, lay waste cities, program in Basic, or embroider in cross-stitch. -- Nochnoy Dozor (The Night Watch) By Sergei Lukyanenko
admin
Administrator
ImageImageImageImageImage


member is offline

Avatar




PM


Posts: 1145
xx Re: BB4W can't open file with no extension!
« Reply #4 on: May 15th, 2012, 4:56pm »

on May 15th, 2012, 12:42pm, Endymion wrote:
I was guided by Rosetta Code - http://rosettacode.org/wiki/Ensure_that_a_file_exists#BBC_BASIC

The code there is fine. It uses this:

Code:
      test% = OPENIN("input.txt")
      IF test% THEN 

which is shorthand for:

Code:
      test% = OPENIN("input.txt")
      IF test%<>0 THEN 

so to reverse the logic you need to change the <> into =:

Code:
      test% = OPENIN("input.txt")
      IF test%=0 THEN 

Note that IF NOT test% does not (in general) reverse the result of IF test%. Think what happens if, for example, test% is 1:

Code:
      IF 1 THEN
        PRINT "Test passes"
      ENDIF 

NOT 1 is -2 (try it) so we get:

Code:
      IF -2 THEN
        PRINT "Test passes"
      ENDIF 

This is just the same in most other dialects of BASIC, and indeed other languages that don't have a native Boolean data type.

Richard.
User IP Logged

Endymion
New Member
Image


member is offline

Avatar

Write spaghetti-code for food!


PM

Gender: Male
Posts: 7
xx Re: BB4W can't open file with no extension!
« Reply #5 on: May 16th, 2012, 02:52am »

on May 15th, 2012, 4:56pm, Richard Russell wrote:
This is just the same in most other dialects of BASIC, and indeed other languages that don't have a native Boolean data type.

Richard.


IMHO, it is absolutely illogical. I don't know all dialects of BASIC, but I remember, that Sinclair BASIC had much better bool-type-emulation: 0 = FALSE, 1 = TRUE, NOT 0 = 1, NOT (any number except zero) = 0. Why NOT (1) = -2 in BBC?
User IP Logged

I wanted to do something. I wanted to do something as badly as a genie who's been let out of his bottle for the first time in a thousand years. Anything at all: Raise up castles, lay waste cities, program in Basic, or embroider in cross-stitch. -- Nochnoy Dozor (The Night Watch) By Sergei Lukyanenko
admin
Administrator
ImageImageImageImageImage


member is offline

Avatar




PM


Posts: 1145
xx Re: BB4W can't open file with no extension!
« Reply #6 on: May 16th, 2012, 08:30am »

on May 16th, 2012, 02:52am, Endymion wrote:
IMHO, it is absolutely illogical.

On the contrary, it's absolutely logical! The NOT function inverts all the bits (this is standard binary logic) so if you look at the bit patterns you can see how it works:

1 = %00000000000000000000000000000001
NOT(1) = %11111111111111111111111111111110

Converting that binary value to decimal gives -2.

I think where you are going wrong is that you are confusing numbers with Booleans. If you stick with Booleans then everything works as you expect:

Code:
  PRINT TRUE
  PRINT FALSE
  PRINT NOT TRUE
  PRINT NOT FALSE 

Running this shows that NOT TRUE is the same as FALSE (0), and NOT FALSE is the same as TRUE (-1).

If you are familiar with the C language you can do this (in C ~ is the binary NOT operator):

Code:
  int num = 1 ;
  int notnum = ~ num ;
  printf ("NOT(1) = %i", notnum) ; 

If you run that it will print -2, demonstrating that BBC BASIC is by no means unusual in this respect.

(Later)
Also try this in Microsoft's QBASIC or QuickBASIC; you can guess what you will get:

Code:
PRINT NOT(1) 


Richard.
« Last Edit: May 16th, 2012, 1:03pm by admin » User IP Logged

Pages: 1  Notify Send Topic Print
« Previous Topic | Next Topic »

| |

This forum powered for FREE by Conforums ©
Terms of Service | Privacy Policy | Conforums Support | Parental Controls