Search found 77 matches

by matt7
Thu Apr 08, 2021 6:29 pm
Forum: Other topics
Topic: Reading nth line in a file
Replies: 3
Views: 38

Re: Reading nth line in a file

Follow-up thought: If memory is an issue or you just want a safer way to do this, modify the above function to use FILE N$ READDIM M, N, K in a loop, reading K bytes at a time. Then you can keep overwriting the bytes() variable as you count newline characters, keeping track of the total running file...
by matt7
Thu Apr 08, 2021 6:10 pm
Forum: Other topics
Topic: Reading nth line in a file
Replies: 3
Views: 38

Re: Reading nth line in a file

I recently tried to figure out how to do this but ended up settling for doing a bunch of READLINEs until I reached the line I wanted. However, your post got me thinking about the problem again and I realized that if you know the file size at the line you want, you can use FILE N$ SETPOS X. I briefly...
by matt7
Thu Mar 18, 2021 7:42 pm
Forum: Other topics
Topic: New to SB and File handling
Replies: 2
Views: 218

Re: New to SB and File handling

What is the expected range of values for your numeric variables? For example, if they are limited to the range 0-255 then FILE WRITE and FILE READ can be used, which write and read a single byte. But other numeric values will require some additional code to preserve precision. The below example uses...
by matt7
Wed Mar 03, 2021 3:57 pm
Forum: Libraries
Topic: Recursively Listing Files and Folders
Replies: 2
Views: 182

Re: Recursively Listing Files and Folders

Just updated the library code with some bug fixes.
by matt7
Sat Feb 27, 2021 6:05 am
Forum: Libraries
Topic: Recursively Listing Files and Folders
Replies: 2
Views: 182

Recursively Listing Files and Folders

Below is a standalone library for creating a list of either all files or all folders recursively from a starting directory. The two main functions are: DIRS_LIST_RECURSIVE(dir$) FILES_LIST_RECURSIVE(dir$) Here is a usage example: {{/lib/files/list_recursive}} ' whatever you name it and wherever you ...
by matt7
Sat Jan 16, 2021 3:29 pm
Forum: Other topics
Topic: Format string with PRINT command
Replies: 4
Views: 307

Re: Format string with PRINT command

Here's another option that builds the format string from right to left and then applies it.

Code: Select all

def fmt$(a)
f$="###"
m=1000
while abs(a)>=m
f$="###,"&f$
m*=1000
endwhile
return str$(a,f$)
enddef
Add a trim$() to the return line or whenever you call fmt$ to remove leading spaces.
by matt7
Thu Jan 07, 2021 9:46 pm
Forum: Other topics
Topic: New version has wrong number?
Replies: 7
Views: 817

Re: New version has wrong number?

Here is a thread discussing some different ways to achieve select-case functionality:
https://www.kibernetik.pro/forum/viewto ... =26&t=2387
by matt7
Wed Dec 09, 2020 8:22 pm
Forum: Other topics
Topic: Copy files between BASIC v6 and other apps
Replies: 20
Views: 1477

Re: Copy files between BASIC v6 and other apps

In 'Files' I can only see 'GoodReader' as a target for sharing. This is an app that has been on my iPad for years and is systematically updated. So in principle the sharing facility seems possible in iOS 12.4.9 I just wanted to share a puzzling thing I noticed on my iPhone that was on iOS 13.6 at t...
by matt7
Wed May 15, 2019 11:53 am
Forum: Other topics
Topic: Case Statement
Replies: 10
Views: 589

Re: Case Statement

what happens if dayno is anything but 0 through 6? Good point. I don't use GOTOs and labels very often so it slipped my mind, but if you want to detect the error case you can right under the ON GOTO line. (In my earlier example without error handling, any "invalid" dayno would fall through to d1, c...
by matt7
Mon May 13, 2019 3:50 pm
Forum: Other topics
Topic: Case Statement
Replies: 10
Views: 589

Re: Case Statement

I notice that in some of the previously posted examples, arrays smaller than 10 are being dimensioned. That is not necessary in Smart Basic. True. I didn't even think about that, since I prefer to just DIM every array for clarity so that I know how many array elements I'm intending to use (a lot of...