Welcome, Guest
You have to register before you can post on our site.

Username/Email:
  

Password
  





Search Forums

(Advanced Search)

Forum Statistics
» Members: 714
» Latest member: HenryG
» Forum threads: 3,569
» Forum posts: 31,908

Full Statistics

Latest Threads
4x4 Square Elimination Pu...
Forum: bplus
Last Post: bplus
24 minutes ago
» Replies: 12
» Views: 390
Container Data Structure
Forum: Utilities
Last Post: bplus
37 minutes ago
» Replies: 3
» Views: 86
Accretion Disk
Forum: Programs
Last Post: bplus
48 minutes ago
» Replies: 11
» Views: 239
QB64PE v 4.4.0
Forum: Announcements
Last Post: Unseen Machine
8 hours ago
» Replies: 7
» Views: 650
QBJS v0.10.0 - Release
Forum: QBJS, BAM, and Other BASICs
Last Post: Unseen Machine
8 hours ago
» Replies: 13
» Views: 1,279
Arrays inside Types?
Forum: General Discussion
Last Post: hsiangch_ong
9 hours ago
» Replies: 47
» Views: 1,394
Has anybody experience wi...
Forum: Help Me!
Last Post: Rudy M
Yesterday, 08:47 AM
» Replies: 31
» Views: 1,933
Sorting numbers - FiliSor...
Forum: Utilities
Last Post: PhilOfPerth
03-11-2026, 12:48 AM
» Replies: 11
» Views: 303
Quick Sort for variable l...
Forum: Utilities
Last Post: SMcNeill
03-10-2026, 03:14 PM
» Replies: 3
» Views: 87
Ready for Easter!
Forum: Holiday Code
Last Post: bplus
03-10-2026, 12:15 PM
» Replies: 0
» Views: 51

 
  Danilin without the GoTo's
Posted by: bplus - 02-28-2026, 10:23 PM - Forum: Programs - Replies (13)

https://qb64phoenix.com/forum/showthread...3#pid40263

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

And see it works fine in QBJS without the GoTo's:


And pretty darn fast too!

Print this item

  Recycle File
Posted by: SMcNeill - 02-27-2026, 10:20 PM - Forum: SMcNeill - Replies (43)

Code: (Select All)
Screen _NewImage(800, 600, 32)

Open "MyFile.txt" For Output As #1
Print #1, "Test:" + Date$ + " " + Time$
Close
Print "File created called MyFile.txt"

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

Sub Recycle (file$)
If _FileExists(file$) Then
$If WIN Then
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$
$ElseIf MAC Then
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! 

:D

Print this item

  USSR puzzle digital
Posted by: DANILIN - 02-26-2026, 11:00 PM - Forum: Programs - Replies (8)

USSR puzzle digital
Personally I have naturally solved by 3 algorithms 
Interest your witty decisions

Parallel topic
Danilin without the GoTo's
https://qb64phoenix.com/forum/showthread.php?tid=4515



Attached Files Thumbnail(s)
   
Print this item

  WordList Load and Search
Posted by: SMcNeill - 02-26-2026, 12:51 AM - Forum: SMcNeill - Replies (5)

As we tend to go over this here on the forums repeatedly, I figured I'd share a simple version which works for anything I want to ever toss at it.

Code: (Select All)
Screen _NewImage(1024, 720, 32)
$Color:32

ReDim dict(0) As String 'make a resizeable array to hold our dictionary

t1 = Timer(0.001)
LoadWordList "Collins.txt", dict(), 300000
t2 = Timer(0.001)

Print Using "#.##### seconds to load ###,### words."; t2 - t1, UBound(dict)
For i = 1 To 10
    Print dict(i),
Next
Print
For i = UBound(dict) - 10 To UBound(dict)
    Print dict(i),
Next
Print

'and just to showcase how quick arrays are, let's do a random search of the array from start to bottom
For i = 1 To 1000000 '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)
    If FindWord(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

Function FindWord (WordList() As String, word As String)
    Dim As Long min, max, p 'min, max, and current search position
    min = 1
    max = UBound(WordList)
    p = (min + max) \ 2
    Do Until p < min _OrElse p > max
        Select Case _StriCmp(word, WordList(p))
            Case -1: max = p - 1
            Case 0: FindWord = p: Exit Function 'we found the word!
            Case 1: min = p + 1
        End Select
        p = (min + max) \ 2
    Loop
End Function

Sub LoadWordList (file$, WordList() As String, Limit As Long) 'this sub loads a list of words for use later
    $Checking:Off
    Dim As String temp, t1
    Dim As Long count, p, p1
    ReDim WordList(Limit) As String '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 = 0 Then 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))
                If Right$(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) As String
    $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."



Attached Files
.txt   Collins.txt (Size: 2.96 MB / Downloads: 19)
Print this item

  Function IsWord%(test$)
Posted by: bplus - 02-25-2026, 08:58 PM - Forum: Utilities - Replies (5)

Inspired by mdijkens comment here: https://qb64phoenix.com/forum/showthread...9#pid40209

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!

Here is the file to run your own tests:



Attached Files
.txt   Words.txt (Size: 2.96 MB / Downloads: 13)
Print this item

  Collision Detection
Posted by: NakedApe - 02-25-2026, 06:36 PM - Forum: Help Me! - Replies (12)

This has probably been asked before, but which approach is easier on the old CPU:

If Abs(MX - ship.x) < accuracy _AndAlso Abs(MY - ship.y) < accuracy Then DO STUFF

OR

If _Hypot(Abs(Roid(c).x - ObjX), Abs(Roid(c).y - ObjY)) < accuracy Then DO OTHER STUFF

Is there more or less overhead using _Hypot? 

Thanks from a curious primate.

Print this item

  Word Wrap
Posted by: Pete - 02-24-2026, 06:38 PM - Forum: Help Me! - Replies (3)

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.

https://qb64phoenix.com/forum/showthread.php?tid=4493

Thanks,

Pete

Print this item

  IJ SAI
Posted by: aurel - 02-24-2026, 06:04 PM - Forum: QBJS, BAM, and Other BASICs - No Replies

Subset of ImageJ Macro Interpreter



Attached Files Thumbnail(s)
   
Print this item

  More info about Random Access files
Posted by: PhilOfPerth - 02-24-2026, 12:43 AM - Forum: Help Me! - Replies (28)

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.

Code: (Select All)
SW = 1040: SH = 720
Screen _NewImage(SW, SH, 32)
SetFont: F& = _LoadFont("C:\WINDOWS\fonts\courbd.ttf", 20, "monospace"): _Font F&
_ScreenMove (_DesktopWidth - SW) / 2, 90

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

Print this item

  QBJS in 3D
Posted by: dbox - 02-23-2026, 08:15 PM - Forum: QBJS, BAM, and Other BASICs - Replies (9)

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:

View Source in New Tab

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:

Open in New Tab

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

Open in New Tab

And here's a 3D Chess game that uses the same view controls as above (and the same chess engine API as the text-based UI one I posted recently).
   

Open in New Tab

For additional of examples of what might be possible there is a listing of sample programs on the three.js website:
https://threejs.org/examples/

And a couple of apps built with three.js:
FPS Shooter: https://krunker.io/
Driving Sim: https://slowroads.io/

Anyway, more to come, but I wanted to share what I have so far.

Print this item