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

Username/Email:
  

Password
  





Search Forums

(Advanced Search)

Forum Statistics
» Members: 485
» Latest member: zenevan
» Forum threads: 2,799
» Forum posts: 26,431

Full Statistics

Latest Threads
micro(A)v11
Forum: QBJS, BAM, and Other BASICs
Last Post: JRace
1 hour ago
» Replies: 109
» Views: 4,787
GNU C++ Compiler error
Forum: Help Me!
Last Post: JRace
1 hour ago
» Replies: 53
» Views: 1,090
Let's Make a Wheel!
Forum: Help Me!
Last Post: Pete
1 hour ago
» Replies: 4
» Views: 61
What do you guys like to ...
Forum: General Discussion
Last Post: bplus
4 hours ago
» Replies: 18
» Views: 319
Raspberry OS
Forum: Help Me!
Last Post: Jack
Today, 01:15 AM
» Replies: 10
» Views: 241
Mean user base makes Stev...
Forum: General Discussion
Last Post: Pete
Yesterday, 10:31 PM
» Replies: 25
» Views: 434
A question on using Infor...
Forum: Help Me!
Last Post: justsomeguy
Yesterday, 10:14 PM
» Replies: 7
» Views: 142
New Message Box Library U...
Forum: Works in Progress
Last Post: Pete
Yesterday, 10:11 PM
» Replies: 1
» Views: 47
SaucerZap
Forum: QBJS, BAM, and Other BASICs
Last Post: Pete
Yesterday, 10:06 PM
» Replies: 6
» Views: 69
_IIF limits two question...
Forum: General Discussion
Last Post: madscijr
Yesterday, 03:53 AM
» Replies: 9
» Views: 197

 
  Sample program using the new _Files$ function
Posted by: eoredson - 01-20-2024, 04:29 AM - Forum: Utilities - Replies (29)

Well about time! I have been waiting for a function similar to the one in BC7 called Dir$() for years! Big Grin 

This sample program searches for files with *,?,^ matching. Also recurses directories and subdirectories and their files.

Can also write output to a file and stores directory and filename arrays.

Also compatible with Win/Linux/OSX platforms.

Erik.

@a740g: Thanks for the time and effort writing a _Files$ function.

  v2.0a:
    Adds dirspec match and restart.
    Adds shellsort for dirs and files.
  v2.1a:
    Adds statusline and ctrl-break trap.
    Adds filename search to titlebar.
  v2.2a:
    Adds Case-Sensitive selection.
  v3.0a:
    Fixes print position output.
    Fixes exit loop in prompt output file.

Now 656 lines.

Things I like about _files$ is the improvement over dir$ when matching directories appended with slash and lan capability when specified as \\server\share\

[Image: filedir.jpg]

A simple breakdown of the Files$ function:

Code: (Select All)
DefLng A-Z
Rem $Dynamic

Dim Shared Directories(1) As String
Dim Shared Filenames(1) As String
Dim Shared MaxDirs As Long
Dim Shared MaxFiles As Long

Dim Directory As String
_ScreenMove _Middle
Color 15
Print "Enter dirspec";: Input Directory
If Directory = "" Then Directory = _CWD$
If _DirExists(Directory) Then
   If Right$(Directory, 1) <> "\" Then Directory = Directory + "\"
   PrintDirectory Directory
End If
Print "Dirs"; MaxDirs; "Files"; MaxFiles
Print "Dirlist:"
Count = 0
For L = 1 To MaxDirs
   Color 15
   Print Directories(L)
   Count = Count + 1
   If Count >= 24 Then
      Color 14
      Print "-more-";
      Do
         _Limit 50
         X$ = InKey$
         If LCase$(X$) = "y" Then Print: Count = 0: Exit Do
         If LCase$(X$) = "n" Then Print: Count = 0: Exit For
      Loop
   End If
Next
If Count Then
   Color 14
   Print "-more-";
   Do
      _Limit 50
      If Len(InKey$) Then Print: Exit Do
   Loop
End If
Color 15
Count = 0
Print "Filelist:"
For L = 1 To MaxFiles
   Color 15
   Print Filenames(L)
   Count = Count + 1
   If Count >= 24 Then
      Color 14
      Print "-more-";
      Do
         _Limit 50
         X$ = InKey$
         If LCase$(X$) = "y" Then Print: Count = 0: Exit Do
         If LCase$(X$) = "n" Then Print: Count = 0: Exit For
      Loop
   End If
Next
If Count Then
   Color 14
   Print "-more-";
   Do
      _Limit 50
      If Len(InKey$) Then Print: Exit Do
   Loop
End If
Color 7
End

Sub PrintDirectory (Directory As String)
   Dim I As _Unsigned Long
   Dim N As _Unsigned Long
   Dim VarX As String
   Dim Entry(0 To 0) As String
   Dim E As String
   ' start search
   E = _Files$(Directory)
   Do
      Entry(N) = E
      N = N + 1
      If N > UBound(Entry) Then
         ReDim _Preserve Entry(0 To N) As String
      End If
      ' continue search
      E = _Files$
   Loop While Len(E) > 0
   VarX$ = Directory
   GoSub StoreFile
   While I < N
      If Entry(I) <> ".\" And Entry(I) <> "..\" Then
         If Right$(Entry(I), 1) = "\" Then
            PrintDirectory Directory + Entry(I)
         Else
            VarX$ = Directory + Entry(I)
            GoSub StoreFile
         End If
      End If
      I = I + 1
   Wend
   Exit Sub
   StoreFile:
   If Right$(VarX$, 1) = "\" Then
      MaxDirs = MaxDirs + 1
      ReDim _Preserve Directories(MaxDirs) As String
      Directories(MaxDirs) = VarX$
   Else
      MaxFiles = MaxFiles + 1
      ReDim _Preserve Filenames(MaxFiles) As String
      Filenames(MaxFiles) = VarX$
   End If
   Return
End Sub



Attached Files
.zip   FILEDIR3.ZIP (Size: 4.85 KB / Downloads: 24)
Print this item

  Arrays In User Data Types
Posted by: Consolemu - 01-18-2024, 08:30 PM - Forum: Help Me! - Replies (2)

Hello everyone,

I'm not sure if this question has been asked before and if so my apologies.  I tried searching online for the topic but those solutions weren't necessarily applicable to what I'm looking for.  I'm working on a program for practice where I take a text file, read and parse the data into an array, then save the array to my own custom binary file.  This task is tricky in most languages but a breeze in C as far as creating a struct that contains an array that can be written to or read from a binary file.  But with QB when I try this code for example I get an error:

Type MyPalette
HeaderTag as String
    Colors(20) As integer

End Type

For as long as I've been coding off and on in Basic and QB especially I didn't know you couldn't simply create a fixed array in a custom data.  With binary files I'll typically create a data type with a header and variables where each variable in succession including large chunks of data can be organized into a contained array so I can write the entire custom data type to a binary file with one line of code.  Is this even possible with QB or is there any type of workaround?  I did glance at the new _MEM command but not too familiar with that either.

Thanks for reading and your input.

Print this item

  A = A(0)
Posted by: Dimster - 01-18-2024, 04:56 PM - Forum: Help Me! - Replies (7)

Is there a difference between Dim A as integer and Dim A(0) as integer??

Print this item

  Possible to control Windows 11 volume?
Posted by: loopy750 - 01-15-2024, 02:39 PM - Forum: Help Me! - Replies (4)

As the title suggests, trying to find a way with Dynamic Library to control the Windows sound settings, such as muting, etc. if possible.

Print this item

  Extended Trig Methods
Posted by: dbox - 01-15-2024, 02:34 PM - Forum: General Discussion - Replies (19)

In the process of trying to expand QBJS' support for QB64 keywords I noticed a curiosity with the extended trigonometric functions.  It looks like this has been the case for some time and predates "the incident".

There is a bit of inconsistency with the documentation in the wiki(s) for the support of these keywords.  Some are well documented and have their own page like: _acos, _asin, _hypot, etc..  Many of them, however, are only referenced in the "Derived Mathematical Functions" section of the Mathematical Operations page.  This section, though, is really just a reference of how to implement your own trig functions and doesn't really indicate that many (but not all) of those methods are actually available in the language.

The following functions from this section have first-class keyword support:
_sec, _csc, _cot, _arcsec, _arccsc, _arccot, _sinh, _cosh, _tanh, _sech, _csch, _coth

...while these do not have a dedicated keyword:
_arcsin, arccos, _arcsinh, _arccosh, _arccsch, _arccoth

So the curiosity that I found is related to the _arccsc method.  If you run the following example you will see that you get two different answers for built-in function vs the provided logic in the wiki:

Code: (Select All)
Print _Arccsc(x)
Print Atn(1 / Sqr(1 - x * x)) + (Sgn(x) - 1) * (2 * Atn(1))

Which one is right?

Print this item

  Here's Print Using Mismatch error
Posted by: Dimster - 01-13-2024, 06:47 PM - Forum: Help Me! - Replies (15)

So I was pretty sure Print Using could work with numeric variables but my code came up with a mismatch error. Upon re-reading the wiki it seems I was wrong, that Print Using works with string values. So I changed the code but have hit the same mismatch error. Here is the routine

Code: (Select All)
Dim formatString As String
formatString = "##.##"
For i = 0 To 9
    'Print Using "##.##"; i / 10; "-"; (i + 1) / 10; " |";
    Print Using formatString; i / 10; "-"; (i + 1) / 10; " |";
    For j = 1 To freq(i) / 10
        Print "*";
    Next j
    Print
Next i
I have commented out the original code of  'Print Using "##.##"; i / 10; "-"; (i + 1) / 10; " |"; which produced the error and tried to convert it all to string with that dim statement of formatString sting variable. I'm not sure what I'm missing here?

Print this item

  Elementary Cellular Automaton
Posted by: FellippeHeitor - 01-13-2024, 04:21 AM - Forum: Programs - Replies (7)

Adapted from Coding Challenge 179: Elementary Cellular Automata (youtube.com)
Original javascript code: Wolfram CA / The Coding Train
More on it at Elementary Cellular Automaton -- from Wolfram MathWorld

Code: (Select All)
Option _Explicit
_ControlChr Off

Const true = -1, false = 0

Dim ruleValue As _Unsigned _Byte
Dim Shared ruleSet$
Dim nav$, newValue$
Dim As Long w, total, i, x, y, k
Dim As _Byte l, r, state, newState, firstTime, done
Dim As _Unsigned Long c
Dim As _MEM m1, m2

firstTime = true
ruleValue = 99
w = 2

'setup
Screen _NewImage(1000, 800, 32)
_Display
Color _RGB32(0), _RGB32(255)
total = _Width / w

'main loop
Do
    ruleSet$ = Right$(String$(8, "0") + _Bin$(ruleValue), 8)
    ReDim As _Byte cells(total - 1), nextCells(total - 1)
    cells(Int(total / 2)) = 1
    y = _FontHeight
    Cls

    'draw loop
    Do
        For i = 0 To total - 1
            x = i * w
            If cells(i) Then
                If x < _Width / 2 Then
                    c = _RGB32(map(x, 0, _Width / 2, 200, 0))
                Else
                    c = _RGB32(map(x, _Width / 2, _Width, 0, 200))
                End If
            Else
                _Continue
            End If
            Line (x, y)-Step(w, w), c, BF
        Next

        y = y + w
        If y > _Height Then Exit Do

        'calculate next generation
        For i = 0 To total - 1
            l = cells((i - 1 + total) Mod total)
            r = cells((i + 1) Mod total)
            state = cells(i)
            newState = calculateState(l, state, r)
            nextCells(i) = newState
        Next

        m1 = _Mem(cells())
        m2 = _Mem(nextCells())
        _MemCopy m2, m2.OFFSET, m2.SIZE To m1, m1.OFFSET
    Loop

    If ruleValue > 0 Then nav$ = Chr$(27) + " " Else nav$ = Space$(2)
    nav$ = nav$ + "Rule " + Right$(String$(3, "0") + _Trim$(Str$(ruleValue)), 3)
    If ruleValue < 255 Then nav$ = nav$ + " " + Chr$(26)
    nav$ = nav$ + "; w =" + Str$(w)
    _PrintString (_Width / 2 - _PrintWidth(nav$) / 2, 0), nav$
    If firstTime Then
        Locate 3, 1
        Print "use left/right arrows to change rule set or"
        Print "enter a rule number directly (0-255);"
        Print "up/down arrows to change box width."
        firstTime = false
    End If

    _Display
    _KeyClear
    done = false
    Do
        k = _KeyHit
        Select Case k
            Case 27: System
            Case 19200: If ruleValue > 0 Then ruleValue = ruleValue - 1: Exit Do
            Case 19712: If ruleValue < 255 Then ruleValue = ruleValue + 1: Exit Do
            Case 18432: w = w + 2: total = _Width / w: Exit Do
            Case 20480: If w > 2 Then w = w - 2: total = _Width / w: Exit Do
            Case 13, 48 To 57
                'insert mode
                If k > 13 Then newValue$ = Chr$(k) Else newValue$ = ""
                _KeyClear
                Do
                    Locate 2, 1
                    Print "Enter new rule (0-255): "; newValue$; "_ ";
                    _Display
                    k = _KeyHit
                    Select Case k
                        Case 48 To 57
                            newValue$ = newValue$ + Chr$(k)
                        Case 8
                            If Len(newValue$) Then newValue$ = Left$(newValue$, Len(newValue$) - 1)
                        Case 13
                            If Val(newValue$) >= 0 And Val(newValue$) <= 255 Then
                                ruleValue = Val(newValue$)
                                done = true
                                Exit Do
                            Else
                                Beep
                            End If
                        Case 27
                            done = true
                            Exit Do
                    End Select
                    _Limit 30
                Loop
        End Select
        _Limit 30
    Loop Until done
Loop

Function calculateState%% (a As _Byte, b As _Byte, c As _Byte)
    Dim neighborhood$
    Dim value As _Byte

    neighborhood$ = _Trim$(Str$(a)) + _Trim$(Str$(b)) + _Trim$(Str$(c))
    value = 8 - Val("&B" + neighborhood$)
    calculateState%% = Val(Mid$(ruleSet$, value, 1))
End Function

Function map! (value!, minRange!, maxRange!, newMinRange!, newMaxRange!)
    map! = ((value! - minRange!) / (maxRange! - minRange!)) * (newMaxRange! - newMinRange!) + newMinRange!
End Function

Print this item

  ThrowBack Friday: "TARGET"
Posted by: Cobalt - 01-13-2024, 01:11 AM - Forum: Programs - No Replies

Another Blast from the past! A three dimensional "shooter" text based. Attempt to hit a target in 3d space. (circa. 1975)

Code: (Select All)
0 REM ********************************** TARGET **************************************
1 REM In this program, you are firing a weapon from a spaceship in 3-dimensional space.
2 REM Your ship, the Starship Enterprise, is located at the origin (0,0,0) of a set of
4 REM x,y,z coordinates. You will be told the approximate location of the target in
6 REM 3-dimensional rectangular coordinates, the approximate angular deviation from
8 REM the x and z axes in both radius and degrees, and the approximate distance to the
10 REM target. Given this information, you then proceed to shoot at the target.
12 REM A shot within 20 kilometers of the target destroys it. After each shot, you are
14 REM given information as to the position of the explosion of your shot and a somewhat
16 REM improved estimate of the location of the target. Fortunately, this is just
18 REM practice and the target doesn't shoot back. After you have attained proficiency,
20 REM you ought to be able to destroy a target in 3 or 4 shots. However, attaining
22 REM proficiency might take awhile!
23 REM *******************************************************************************

25 REM Original Program Author
27 REM H. David Crockett
29 REM Fort Worth, TX 76133

90 PI = _PI 'added to define PI to maintain program originality

100 R = 1: R1 = 57.296: RANDOMIZE TIMER
110 PRINT "You are the weapons officer on the star ship Enterprise"
120 PRINT "and this is a test to see how accurate a shot you"
130 PRINT "are in a Three-Dimensional range. You will be told"
140 PRINT "the radian offset for the X and Z axes, the location"
150 PRINT "of the target in three-dimensional rectangular coordinates,"
160 PRINT "the approximate number of degrees from the X and Z"
170 PRINT "axes, and the approximate distance to the target."
180 PRINT "You will then proceed to shoot at the target until it is "
190 PRINT "destroyed!": PRINT: PRINT "Good Luck!!": PRINT: PRINT
220 A = RND * 2 * PI: B = RND * 2 * PI: Q = INT(A * R1): W = INT(B * R1)
260 PRINT "Radians from X axis ="; A; "  From Z axis ="; B
270 PRINT "Approx degrees from X axis ="; Q; "    From Z axis ="; W
280 P = 100000 * RND + RND: X = SIN(B) * COS(A) * P: Y = SIN(B) * SIN(aa) * P: z = COS(B) + R '??? scan is damaged at end of line looks like R though
340 PRINT "Target sighted: Approx Coordinates X="; X; "  Y="; Y; "  Z="; z
345 R = R + 1: IF R > 5 THEN GOTO 390
350 ON R GOTO 355, 360, 365, 370, 375
355 P3 = INT(P * .05) * 20: GOTO 390
360 P3 = INT(P * .1) * 10: GOTO 390
365 P3 = INT(P * .5) * 2: GOTO 390
370 P3 = INT(P) * 20: GOTO 390
375 P3 = P
390 PRINT "    Estimated Distance="; P3
400 INPUT "Input angle deviation from X, Deviation from Z, Distance"; A1, B1, P2
410 prinit: IF P2 < 20 THEN PRINT "YOU BLEW YOURSELF UP!!!": GOTO 580
420 A1 = A1 / R1: B1 = B1 / R1: PRINT "Radians from X axis="; A1; "  From Z axis ="; B1
480 X1 = P2 * SIN(B1) * COS(A1): Y1 = P2 * SIN(B1) * sn(A1): Z1 = P2 * COS(B1)
510 D = ((X1 - X) ^ 2 + (Y1 - Y) ^ 2 + (Z1 - z) ^ 2) ^ (1 / 2)
520 IF D > 20 THEN GOTO 670
530 PRINT: PRINT " * * * HIT * * *    Target is NON-FUNCTIONAL": PRINT
550 PRINT "Distance of explosion from target was"; D; "Kilometers"
570 PRINT: PRINT "Mission Accomplished in"; R; " shots."
580 R = 0: FOR I = 1 TO 5: PRINT: NEXT I: PRINT "Next Target....": PRINT: GOTO 220
670 x2 = X1 - X: y2 = Y1 - Y: z2 = Z1 - z: IF x2 < 0 THEN 730
710 PRINT "Shot in front of target"; x2; " Kilometers.": GOTO 780
730 PRINT "Shot Behind target"; -x2; " Kilometers."
740 IF y2 < 0 THEN 770
750 PRINT "Shot to LEFT of target"; y2; " Kilometers.": GOTO 780
770 PRINT "Shot to RIGHT of target"; -y2; " Kilometers."
780 IF z2 > 0 THEN 810
790 PRINT "Shot Above target"; z2; " Kilometers.": GOTO 820
810 PRINT "Shot Below target"; -z2; " Kilometers."
820 PRINT "Approx position of Explosion:  X="; X1; "  Y="; Y1; "  Z="; Z1
830 PRINT "  Distance from target ="; D: PRINT: PRINT: PRINT: GOTO 345
999 END

Print this item

  Dual Monitors using QB64
Posted by: Donald Foster - 01-11-2024, 01:47 AM - Forum: General Discussion - Replies (4)

Hello All,

Does QB64 offer statements that utilize dual monitors?

Donald

Print this item

  Pls help with CPU usage!!!
Posted by: liubartas - 01-08-2024, 02:54 PM - Forum: Help Me! - Replies (13)

Hi, I want to use qb64pe but for some reason ide uses 50% cpu, and my laptop starts overheating.
This happens when I load the full source code of ide itself. It's a large file, but maybe it's possible
to somehow disable such high cpu usage?

Print this item