| 
 
| 
|  Author | Topic: BB4W can't open file with no extension!  (Read 846 times) |  |  
| 
| 
| Endymion New Member
 
 
 member is offline
 
  
 Write spaghetti-code for food!
 
 
 
  
 Gender:
  Posts: 7
 
 | 
|  | 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 » |  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
 
 | 
|  | 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 » |  Logged |  
 |  |  |  
| 
| 
| admin Administrator
 
 
 member is offline
 
  
 
 
 
 
  
 
 Posts: 1145
 
 | 
|  | 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:
 That won't work because File1% is not a Boolean.  Instead, test for the value being zero:
 
 Code:
 Richard.
 |  
| 
|  |  Logged |  
 |  |  |  
| 
| 
| Endymion New Member
 
 
 member is offline
 
  
 Write spaghetti-code for food!
 
 
 
  
 Gender:
  Posts: 7
 
 | 
|  | 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: That won't work because File1% is not a Boolean.  Instead, test for the value being zero:
 
 Code:
 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 » |  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
 
 
 member is offline
 
  
 
 
 
 
  
 
 Posts: 1145
 
 | 
|  | 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:
 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.
 
 |  
| 
|  |  Logged |  
 |  |  |  
| 
| 
| Endymion New Member
 
 
 member is offline
 
  
 Write spaghetti-code for food!
 
 
 
  
 Gender:
  Posts: 7
 
 | 
|  | 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?
 |  
| 
|  |  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
 
 
 member is offline
 
  
 
 
 
 
  
 
 Posts: 1145
 
 | 
|  | 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:
 
 Richard.
 
 |  
| 
| « Last Edit: May 16th, 2012, 1:03pm by admin » |  Logged |  
 |  |  |  
 |