Here is how Danilin could have written the above code (2nd one in reply) without the goto's:
Code: (Select All)
Dim t: t = Timer(0.001) ' ussr_puzzle_subzero.bas
For a = 0 To 9: For b = 0 To 9: For c = 0 To 9
If a * b - c = 4 Then
For d = 1 To 9: For e = 0 To 9: For f = 0 To 9
If d + e + f = 8 Then
For g = 0 To 9: For h = 1 To 9: For i = 0 To 9
If g / h + i = 8 Then
If a / d + g = 9 Then
If b + e + h = 8 Then
If c + f - i = 6 Then
Print a, b, c
Print d, e, f
Print g, h, i: Print
End If
End If
End If
End If
Next i
Next h
Next g
End If
Next f
Next e
Next d
End If
Next c
Next b
Next a
Print "time:"; Timer(0.001) - t
Recycle"MyFile.txt" Print"MyFile.txt should now be recycled and in the Recycle Bin, instead of just erased permanently." Print"Check your recycle bin to see if it exists there and contains a simple message of 'Test'." End
SubRecycle (file$) If_FileExists(file$) Then $IfWINThen
ps$ = "powershell -NoLogo -NoProfile -Command "
ps$ = ps$ + Chr$(34) + "Add-Type -AssemblyName Microsoft.VisualBasic; "
ps$ = ps$ + "[Microsoft.VisualBasic.FileIO.FileSystem]:eleteFile('"
ps$ = ps$ + file$
ps$ = ps$ + "','OnlyErrorDialogs','SendToRecycleBin')" + Chr$(34) Shell_Hide ps$ $ElseIfMACThen Shell_Hide"mv " + Chr$(34) + file$ + Chr$(34) + " ~/.Trash/" If_FileExists(file$) Then'a back up second method as per here --> https://www.macterminal.cc/answers/mv-command-examples
message$ = "File failed to move to trash folder. Possible reasons for this are:" + Chr$(10)
message$ = message$ + Chr$(10)
message$ = message$ + "1. Missing Full Disk Access" + Chr$(10)
message$ = message$ + "By default, the Terminal does not have permission to modify 'protected' folders like ~/.Trash/, leading to 'Operation not permitted' errors. "
message$ = message$ + Chr$(10)
message$ = message$ + "Fix: Go to System Settings > Privacy & Security > Full Disk Access and toggle the switch for Terminal to ON." + Chr$(10)
message$ = message$ + Chr$(10)
message$ = message$ + Chr$(10)
message$ = message$ + "2. Incorrect Trash Path for External Drives" + Chr$(10)
message$ = message$ + "Each drive on a Mac has its own hidden trash folder. If the file you are moving is on an external drive, ~/.Trash/ (which is on your internal startup disk) might not be the correct destination for a simple 'move'." + Chr$(10)
message$ = message$ + Chr$(10)
message$ = message$ + "Fix: For files on external volumes, the path is usually /Volumes/[DriveName]/.Trashes/[UserUID]/." + Chr$(10)
message$ = message$ + Chr$(10)
message$ = message$ + Chr$(10)
message$ = message$ + "3. Folder Ownership or Corruption" + Chr$(10)
message$ = message$ + "Sometimes the .Trash directory itself has incorrect permissions or has become corrupted." + Chr$(10)
message$ = message$ + Chr$(10)
message$ = message$ + "Verify: Run ls -ld ~/.Trash to see the permissions. It should be owned by your username with rwx permissions." + Chr$(10)
message$ = message$ + "Fix: If it's missing or broken, you can recreate it by running mkdir ~/.Trash (though you may need to delete a corrupted one first with sudo rm -rf ~/.Trash)." + Chr$(10) _MessageBox"File failed to move to trash", message$, "info" End If $Else 'Assume Linux-like environment with gio available SHELL_HIDE"gio trash " + CHR$(34) + file$ + CHR$(34) $End If End If End Sub
A simple routine which should send a file to the recycle bin, rather than just destroy it utterly like it does with KILL or a shell to DEL or ERASE. Short, simple, and easy enough to toss into any program which needs to make use of it, without a lot of dependencies and such attached to working with it.
Edit: Updated to hopefully work on Mac and Linux. At least according to others who use Mac and Linux, *they* claim this works. I'm a windows guy myself, so I'm just trusting them. I can't actually test it on my own to be certain, so try it out and if it fails, fuss at them!
'and just to showcase how quick arrays are, let's do a random search of the array from start to bottom For i = 1To1000000'let's look for 1000000 random words
word$ = Chr$(65 + Rnd * 26) + Chr$(65 + Rnd * 26) + Chr$(65 + Rnd * 26) + Chr$(65 + Rnd * 26) + Chr$(65 + Rnd * 26) + Chr$(65 + Rnd * 26) IfFindWord(dict(), word$) Then Color Yellow: Print"MATCH:"; word$,: Color White Else 'Print "No match:"; word$, End If Next Print Print Print Using"###.#### seconds to load, parse, search 1,000,000 words, find results, and print them -- TOTAL!!"; Timer(0.001) - t1
SubLoadWordList (file$, WordList() AsString, Limit AsLong) 'this sub loads a list of words for use later $Checking:Off DimAsString temp, t1 DimAsLong count, p, p1 ReDim WordList(Limit) AsString'let's make a nice large array to told the words. Set the limit you want for yourself If_FileExists(file$) Then'then we have a found word list. Let's load and parse it
temp = _ReadFile$(file$)
p = 1 Do
p1 = InStr(p, temp, Chr$(10)) 'look for a chr$(10) end of line marker If p1 = 0Then p1 = InStr(p, temp, Chr$(13)) 'if no chr$(10) then look for a chr$(13) for odd files with it as the CRLF If p1 Then'then we have a delimiter
t1 = _Trim$(Mid$(temp, p, p1 - p)) IfRight$(t1, 1) = Chr$(13) Then t1 = Left$(t1, Len(t1) - 1) 'if CRLF then strip off chr$(13) If t1 <> ""Then'don't add blank lines to the list
count = count + 1
WordList(count) = t1 End If
p = p1 + 1 End If Loop Until p1 = 0 If p < Len(temp) Then'if there's no CRLF for the end of file, we want to last word here
t1 = Mid$(temp$, p) If t1 <> ""Then'again, don't add if it's a blank line
count = count + 1
WordList(count) = Mid$(temp, p) End If End If End If ReDim_Preserve WordList(count) AsString $Checking:On End Sub
This little routine loads the collins dictionary from below, which has over 279k words or so in it. Then it makes a series of words out of random letters -- a *MILLION* words, created on the fly, one by one. Then it searches to determine if the word it hobbled together exists or not. And then it prints out the words that it created that DO match one in the dictionary.
And best of all? It times itself as it does all these different things.
And how long does it take to load a 279,000 word dictionary, parse it, search it a million times, and print the results to screen?
About half a second on my laptop.
This is simple. It's fast and efficient. Why would anyone need anything else?
Whenever someone needs a way to load a wordlist and search it from now on, just remember to point them to this post here and say, "There you go. That's all you need."
This is really easy way to confirm if a word is in a file list of words say from Collins Dictionary:
Code: (Select All)
_Title "Test IsWord function" 'bplus 2026-02-25
Dim Shared FStr$
FStr$ = _ReadFile$("Words.txt") ' once and for all time
While 1
Input "Enter a word to see if in Collins Dictionary"; w$
If IsWord%(w$) Then Print w$; ", is a word." Else Print w$; ", is Not a word"
Wend
Function IsWord% (test$)
testeol$ = Chr$(13) + Chr$(10) + UCase$(test$) + Chr$(13) + Chr$(10)
If InStr(FStr$, testeol$) Then IsWord% = -1 Else IsWord% = 0
End Function
"Words.txt" is a text file using CRLF's to end lines. All I had to do was insert a blank line at beginning of file so that the word "AA" could be verified as a word from the file.
This is way better IMHO than using a Random Access file!
So I put together phase 1 of a WP project. It manipulates a single string and displays it to a resizable width screen. Normally, at this point, I start documenting the routines before moving to the next phase, but I thought I'd ask for a couple of folks to try it out and see anyone can break it, first.
You can REM out the text phrase and run it. If you have anything on your clipboard it will display it, or you can just leave the existing text phrase in place and type to or over the existing text, just like any WP. The mouse is just for cursor positioning at this stage No highlighting, cut, copy, or paste, yet. Ctrl+ arrows right and left are included to skip from word to word. Enter for paragraph(s), home, end ctrl+home, ctrl+end, pgup, pgdn, etc., again, just like any existing WP. Oh, toggle the Insert key to overwrite / insert text.
I've been trying to build a small utility to create a Random Access file from an existing text file, and had a few problems getting it to work.
I have an alpha- sorted, single-element text file, and need to do a binary search to find words within it. I have got this to work , but found, after experimenting, that the Len for the file needed to be at least 2 bytes longer than the max data size. I could find no information about this in the Wiki, and reckon R/A files deserve their own spot there. Here's a (very simple) prog that demonstrates the problem, with the added 2 bytes.
Print "Aim: to convert a serial text file"
Print "(single element, various lengths, alpha-sorted)"
Print "to Direct access (Random access) file."
Print: Print "Problem: Record length"
'prepare a dummy Sequential list
Restore
Data "ARMY","BREAKFAST","CONCORDE","DANGER","ENERGY","FABCDEFGHIJKLMN"
Dim Wrd$(6): For a = 1 To 6: Read Wrd$(a): Next
'name the R/A file
RandFile$ = "RandFile.dat"
'get longest data length 10, length of FLASHPOINT
Input "Max Data length"; MaxLength
RL = MaxLength + 2 ' Len needs to be extended by 2 bytes
RecNum = 0
'prepare R/A file
Open RandFile$ For Random As #1 Len = RL
' Read each word and write to random file
For a = 1 To 6: Put #1, a, Wrd$(a): Next
Close
' Verify the random access file
Print: Print "Reading records from random access file:"
Open RandFile$ For Random As #1 Len = RL
For a = 1 To 6
Get #1, a, wrd$: Print wrd$; " ";
Next
End
Sleep
For some time I've been looking at different ways to leverage the WebGL capabilities of the browser in QBJS. There have been a number of requests to implement _MapTriangle and provide access to GL shaders, etc. Well, while searching for some lower-level JS libraries that might make interacting with WebGL a bit nicer, I ran across three.js, which is a high-level 3D library with a lot of capabilities and a pretty accessible API. I've been pretty impressed with it so far.
So, I've started a new project (three.qbjs) to create a wrapper API that can be used to access this library from QBJS. Here's an obligatory rotating cube example:
At this point, I've only implemented a small percentage of the three.js API, but it's been pretty interesting to see what is possible. It is actually pretty straightforward to incorporate other QBJS content into a 3D scene. Here's an example where we can use one of @bplus' plasma proggies as an animated texture that can be applied to a 3D surface:
You can take that idea even further and play your QBJS game on a virtual NES:
View Controls:
- Orbit: Left mouse / touch: one-finger move.
- Zoom: Middle mouse, or mousewheel / touch: two-finger spread or squish.
- Pan: Right mouse, or left mouse + ctrl/meta/shiftKey / touch: two-finger move.
Game Controls:
- As shown on screen