Author Topic: BASIC  (Read 10470 times)

Offline AlyssonR

  • Advocate
  • Posts: 125
Re: BASIC
« Reply #30 on: September 29, 2018, 01:58:52 AM »
Peter Verhas and his new Java 11 book.


 :o :o :o :o

*Prepares her bleeper, VB6 text and LED lamp to exorcise Peter of the evil spirit possessing him*

 ;D ;D

Offline John

  • Forum Support / SB Dev
  • Posts: 2191
    • ScriptBasic Open Source Project
Re: BASIC
« Reply #31 on: September 29, 2018, 09:40:17 AM »
I keep forgetting you are a she, not that it matters. Excuse any past references to he.

Online AIR

  • RETIRED
  • BASIC Developer
  • Posts: 410
Re: BASIC
« Reply #32 on: September 29, 2018, 10:40:35 PM »
Hey, John!

For the DirWalk thing, you should have just pointed them to Reading a Directory

Anyway, on my Mac I coded and ran this against the Scriptbasic source (old 2.1_RC3_OSX):

Code: Script BASIC
  1. fn = FREEFILE()
  2. Search_Options = SbCollectFullPath AND SbCollectRecursively AND SbSortByName AND SbSortAscending
  3.  
  4. OPEN DIRECTORY "/Users/riveraa/Downloads/src" PATTERN "*.c" OPTION Search_Options AS #fn
  5. RESET DIRECTORY #fn
  6.  
  7. fName = NEXTFILE(fn)
  8. WHILE fName <> undef
  9.     PRINT fName & "\n"
  10.     fName = NEXTFILE(fn)
  11. WEND
  12.  
  13. CLOSE DIRECTORY #fn
  14.  
  15.  
  16.  


Output is attached.  But I do have a question:  Is the generated list accessible, or would I have to copy the output of NEXTFILE into a separate list?  Just curious.

AIR.

Offline John

  • Forum Support / SB Dev
  • Posts: 2191
    • ScriptBasic Open Source Project
Re: BASIC
« Reply #33 on: September 29, 2018, 11:02:07 PM »
Hi AIR,

I forgot all about that post. (10 years ago) Thanks for giving it a refresh for the RetroB challenge.

Quote
Output is attached.  But I do have a question:  Is the generated list accessible, or would I have to copy the output of NEXTFILE into a separate list?  Just curious.

I would create an associative array with the directory names being the key. You could use UBOUND on an array key to get the number of files in that directory for example.
« Last Edit: September 30, 2018, 10:24:47 AM by John »

Online AIR

  • RETIRED
  • BASIC Developer
  • Posts: 410
Re: BASIC
« Reply #34 on: September 30, 2018, 12:03:29 AM »
Thanks, but that's overkill.  I just wanted to save the listing to a file instead of redirecting the output to a file in a terminal using ">".

Code: Script BASIC
  1. fn = FREEFILE()
  2. file_list = ""
  3. Search_Options = SbCollectFullPath AND SbCollectRecursively AND SbSortByName AND SbSortAscending
  4.  
  5. OPEN DIRECTORY "/Users/riveraa/Downloads/src" PATTERN "*.c" OPTION Search_Options AS #fn
  6. RESET DIRECTORY #fn
  7.  
  8. fName = NEXTFILE(fn)
  9. WHILE fName <> undef
  10.     file_list &= fName & "\n"
  11.     fName = NEXTFILE(fn)
  12. WEND
  13.  
  14. CLOSE DIRECTORY #fn
  15.  
  16. OPEN "output.txt" FOR output AS #fn
  17. PRINT #fn,file_list
  18. CLOSE #fn
  19.  

Man, I've been coding in C# and Objective-C for so long that I keep putting semi-colons everywhere as I type in my editor!!!!   ;D

AIR.

Offline AlyssonR

  • Advocate
  • Posts: 125
Re: BASIC
« Reply #35 on: September 30, 2018, 01:38:46 AM »
I keep forgetting about associative arrays.

I might try them out with a JSON datafile or two.

On the other hand, I *could* just carry on as I am.

Offline John

  • Forum Support / SB Dev
  • Posts: 2191
    • ScriptBasic Open Source Project
Re: BASIC
« Reply #36 on: September 30, 2018, 09:08:44 AM »
AIR,

Just open a file handle at the top of your code and PRINT to the file rather than the screen.

Offline John

  • Forum Support / SB Dev
  • Posts: 2191
    • ScriptBasic Open Source Project
Re: BASIC
« Reply #37 on: September 30, 2018, 09:50:56 AM »
Quote
John, please consider rejoining the forum. The BASIC community is too small and life is too short for arguments and fallouts to be sustained.

Heart warming that I'm missed but all my efforts are going towards the VB6 Forms OCX direction and getting Script BASIC as part of the Ubuntu distribution. At 66, (this Nov.) My time left here on earth needs to be used wisely.

It makes me happy every morning I wake up and given another day. Time is the most valuable asset.

Quote from: Tomaaz
I would love to see, for example, ScripBasic distributed in this format. What do you think?

I'm looking at using a Snap to distribute Script BASIC on Linux distributions.

The All BASIC wiki is a great place for all of us to help BASIC stay relevant without our personalities getting in the way.
« Last Edit: September 30, 2018, 10:53:03 AM by John »

Offline John

  • Forum Support / SB Dev
  • Posts: 2191
    • ScriptBasic Open Source Project
Re: BASIC
« Reply #38 on: September 30, 2018, 10:37:51 AM »
Quote from: Tomaaz
The result is a bit surprising. I was expecting it to be 50/50, but it looks like Windows easily "wins". Aurel must be delighted. ;)

I view the Windows desktop migration to Linux like the migration of gas powered cars to electric.

Offline John

  • Forum Support / SB Dev
  • Posts: 2191
    • ScriptBasic Open Source Project
Re: BASIC
« Reply #39 on: September 30, 2018, 12:48:02 PM »
Quote
I keep forgetting about associative arrays.

I might try them out with a JSON datafile or two.

On the other hand, I *could* just carry on as I am.

Script BASIC arrays is one of its stronger features. You can use index based or associative or a combination of both. There isn't a practical limitation to the number or depth of indices or the data type they contain. Copying array structures or portions of them to another array (matrix) is nothing more than an assignment.

« Last Edit: September 30, 2018, 12:53:11 PM by John »

Online AIR

  • RETIRED
  • BASIC Developer
  • Posts: 410
Re: BASIC
« Reply #40 on: September 30, 2018, 12:53:21 PM »
AIR,

Just open a file handle at the top of your code and PRINT to the file rather than the screen.

My second post with code does this (reusing the file handle I used for the OPEN DIRECTORY call which according to the docs should be safe to do since the actual handles are different for each "object"), I guess you missed it....

Offline John

  • Forum Support / SB Dev
  • Posts: 2191
    • ScriptBasic Open Source Project
Re: BASIC
« Reply #41 on: September 30, 2018, 12:58:55 PM »
Quote
I guess you missed it....

No.

My point was no need to build a string before printing it to a file as a whole. Your first example just needed to PRINT # to a file rather than the screen. Small code reduction but both result in the same output.

Offline John

  • Forum Support / SB Dev
  • Posts: 2191
    • ScriptBasic Open Source Project
Re: BASIC
« Reply #42 on: September 30, 2018, 01:11:22 PM »
Quote from: Tomaaz
The whole idea of "this thing" is to work everywhere. Do you mean BaCon together with a compiler, C and GTK libraries etc. in one file? The file would be probably massive, but yes - that would be easy to use.

That is what containers are used for.

Online AIR

  • RETIRED
  • BASIC Developer
  • Posts: 410
Re: BASIC
« Reply #43 on: September 30, 2018, 01:59:36 PM »

My point was no need to build a string before printing it to a file as a whole. Your first example just needed to PRINT # to a file rather than the screen. Small code reduction but both result in the same output.

I originally did it like that, but was concerned that I was modifying the file system while looping over the directory contents.

Also, doing it as you suggest means I'll be making multiple calls to add a single line to the file, instead of a single call at the end to write all of the lines at once.

The data being saved is small in this case, but if it were a large data set I think the performance hit would be noticeable.  File I/O can be expensive, as you know....

If the internal list were exposed, then the need for building the string would be eliminated, I could just PRINT # the list in a loop and call it a day.  :)

AIR.


Offline John

  • Forum Support / SB Dev
  • Posts: 2191
    • ScriptBasic Open Source Project
Re: BASIC
« Reply #44 on: September 30, 2018, 02:59:39 PM »
It would be interesting to see what is more efficient, printing the output to a file or concatenating the output to a string and then printing it.

You can create/open your output file wherever you have permissions for using the path with your OPEN.