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

Username/Email:
  

Password
  





Search Forums

(Advanced Search)

Forum Statistics
» Members: 483
» Latest member: aplus
» Forum threads: 2,799
» Forum posts: 26,380

Full Statistics

Latest Threads
Raspberry OS
Forum: Help Me!
Last Post: Jack
2 hours ago
» Replies: 3
» Views: 51
Merry Christmas Globes!
Forum: Programs
Last Post: SierraKen
5 hours ago
» Replies: 3
» Views: 34
List of file sound extens...
Forum: Help Me!
Last Post: SMcNeill
5 hours ago
» Replies: 13
» Views: 197
Merry Christmas Globes!
Forum: Christmas Code
Last Post: SierraKen
8 hours ago
» Replies: 1
» Views: 27
fast file find with wildc...
Forum: Help Me!
Last Post: madscijr
9 hours ago
» Replies: 2
» Views: 52
Tenary operator in QB64 w...
Forum: Utilities
Last Post: Pete
11 hours ago
» Replies: 6
» Views: 89
Video Renamer
Forum: Works in Progress
Last Post: Pete
11 hours ago
» Replies: 3
» Views: 57
Need help capturng unicod...
Forum: General Discussion
Last Post: SMcNeill
Yesterday, 11:34 PM
» Replies: 24
» Views: 329
QB64PE v4.0 is now live!!
Forum: Announcements
Last Post: RhoSigma
Yesterday, 11:02 PM
» Replies: 35
» Views: 1,055
Remark Remover (WIP)
Forum: Works in Progress
Last Post: Pete
Yesterday, 10:37 PM
» Replies: 0
» Views: 14

 
  Thinking about updating _KEYHIT in the wiki...
Posted by: Pete - 08-17-2024, 02:12 AM - Forum: Works in Progress - No Replies

Code: (Select All)
Dim x, oldx(3) As Long
Dim i, cnt, cy, cx As Integer
Screen _NewImage(800, 600, 8)
Cls
font = _LoadFont("cyberbit.ttf", 24)
unifont = _LoadFont("cyberbit.ttf", 24, "UNICODE")
_Font font
Do
    x = _KeyHit
    If x And x <> oldx(1) And x <> oldx(2) And x <> oldx(3) Then
        Select Case x
            Case Is > 0
                Color 10
                Print "Pressed "; ' Positive value means key was pressed.
                cnt = cnt + 1 ' Tracking on.
                oldx(cnt) = x
            Case Else ' Negative value means key was released.
                Color 2
                Print "Released ";
                x = -x
                i = 0: Do ' Tracking off.
                    i = i + 1
                    If oldx(i) = x Then cnt = cnt - 1: oldx(i) = 0: Exit Do
                Loop Until i = 3
        End Select
        Select Case x
            Case Is < 256
                If x < 256 Then ' ASCII code values.
                    Print "ASCII "; x;
                    If x >= 32 And x <= 255 Then Print "[" + Chr$(x) + "]" Else Print
                End If
            Case 256 To 65536 ' 2 byte key codes.
                Print "2-BYTE-COMBO "; x And 255; x \ 256;
                x2 = x \ 256
                If x2 >= 32 And x2 <= 255 Then Print "[" + Chr$(x2) + "]" Else Print
            Case 100000 To 199999 ' QB64 Virtual Key codes.
                Print "SDL VK"; x - 100000
            Case 200000 To &H3FFFFFFF
                Print "QB64 VK"; x - 200000
            Case Is >= &H40000000 ' Unicode values. (IME Input mode)
                Print "UNICODE "; x - &H40000000; "0x" + Hex$(x - &H40000000) + " ...";
                cx = Pos(1): cy = CsrLin
                _Font unifont
                Locate cy, cx
                Color 15
                z$ = MKL$(x - &H40000000) + MKL$(0)
                Print z$ + z$ + z$;
                _Font font
                Locate cy, 1: Print
        End Select
    End If
Loop

This modification of the existing version adds tracking the keys so it only prints to the screen once, allowing us to hold down key combinations without the screen scrolling all over hell and half of Georgia. (I've always wondered what half of Georgia that is?)

What I don't get is how to test the unicode case. I'm using a standard laptop keyboard. Any ideas???

Interesting that there are some keys that won't allow a 3 key press like A+S+W. The W will not register. That's probably because those keys are sometimes involved in arrow directions.

Since this would be for the wiki, I'm open to any suggestions, modifications, etc. but I get it, wiki examples should be as short and to the point as possible. Prettying things up is the readers responsibility.

Pete

Print this item

  Oh the hex with it...
Posted by: Pete - 08-17-2024, 12:17 AM - Forum: Help Me! - Replies (6)

Hey guys, would one increment less than

&H40000000 be...

&H3FFFFFFF 

Thanks, 

Pete

Print this item

  I also have a question - about DefInt
Posted by: PhilOfPerth - 08-16-2024, 11:33 PM - Forum: Help Me! - Replies (4)

While youse guys are studying cause and effect, I've been experimenting with the DefInt function, and I don't understand the results.
The DefInt function truncates all variables of that name to their integer values, and they then operate with this integer value, right?
But why do I get the Inf result in this snippet? I guess it's to do with their binary expression? 
t1 and t2 are "simple" integers aren't they?

Code: (Select All)
DefInt T
t1 = Timer
Print "T1 is integer. ", , , t1
Sleep 2
ActOnT


Sub ActOnT
    t2 = Timer
    Print "t2 is integer in sub. ", , , t2
    t3 = t1 / t2
    Print "t3 is result of t1 divided by t2, I expect 0. ", t1 / t2
    t4 = t2 / t1
    Print "t4 is result of t2 divided by t1, I expect 1. ", t2 / t1
End Sub

Print this item

  ON ERROR question
Posted by: TerryRitchie - 08-16-2024, 07:16 PM - Forum: Help Me! - Replies (18)

I noticed that ON ERROR line labels can't be placed within subroutines:

SUB MySub()

    ON ERROR GOTO ErrHandler

    ... code

    ErrHandler:

END SUB

Is this normal? I'm using QB64pe v3.13.1

The Wiki states ON ERROR can be used in Subs/Functions but no mention of label being required to be outside of the Sub/Function.

Print this item

  undocumented Len function
Posted by: Jack - 08-16-2024, 03:39 PM - Forum: General Discussion - Replies (3)

in the Wiki the Len function is described for strings only but QBasic uses the Len function also to get the size in bytes of data types including udts
but QB64pe also gives the size in bytes of an array, but this seems to be a feature and it behaves strangely
the following works and prints 50, 100 and 200

Code: (Select All)

Dim As Integer i(4, 4)
Dim As Long l(4, 4)
Dim As _Integer64 ll(4, 4)

Print Len(i())
Print Len(l())
Print Len(ll())
but if you add the following
Code: (Select All)

Print Len(l()) / Len(i())
it prints 100 instead of 2, the division never takes place
I think that getting the SizeOf an array would be nice to have and it almost works, perhaps the developers could fix it so that the last statement would be evaluated correctly

Print this item

  double error
Posted by: Jack - 08-16-2024, 11:19 AM - Forum: General Discussion - Replies (1)

this is only an example of accumulated errors in double floating-point

Code: (Select All)

_Title "MatMul"
$Console:Only
_Dest _Console

Dim As Double a(3, 3), b(3, 3), c(3, 3), d(3, 3)
Dim As Long i

a(0, 0) = 1#: a(0, 1) = 1#: a(0, 2) = 1#: a(0, 3) = 1#
a(1, 0) = 2#: a(1, 1) = 4#: a(1, 2) = 8#: a(1, 3) = 16#
a(2, 0) = 3#: a(2, 1) = 9#: a(2, 2) = 27#: a(2, 3) = 81#
a(3, 0) = 4#: a(3, 1) = 16#: a(3, 2) = 64#: a(3, 3) = 256#

'b() = Inverse of a()
b(0, 0) = 4#: b(0, 1) = -3#: b(0, 2) = 4 / 3#: b(0, 3) = -1 / 4#
b(1, 0) = -13 / 3#: b(1, 1) = 19 / 4#: b(1, 2) = -7 / 3#: b(1, 3) = 11 / 24#
b(2, 0) = 3 / 2#: b(2, 1) = -2#: b(2, 2) = 7 / 6#: b(2, 3) = -1 / 4#
b(3, 0) = -1 / 6#: b(3, 1) = 1 / 4#: b(3, 2) = -1 / 6#: b(3, 3) = 1 / 24#

MatMul d(), a(), a()
MatMul c(), d(), b()
printm c()
Print
For i = 1 To 4
MatMul d(), c(), c()
MatMul c(), d(), b()
printm c()
Print
Next

Sub MatMul (ans() As Double, a() As Double, b() As Double)
Dim As Long i, j, k, n, m, p
If (UBound(a, 2) = UBound(b)) Then 'if valid dims
n = UBound(a, 2)
m = UBound(a)
p = UBound(b, 2)

For i = 0 To m
For j = 0 To p
For k = 0 To n
ans(i, j) = 0
Next k, j, i

For i = 0 To m
For j = 0 To p
For k = 0 To n
ans(i, j) = ans(i, j) + (a(i, k) * b(k, j))
Next k, j, i
Else
Print "invalid dimensions"
End If
End Sub

Sub printm (a() As Double)
Dim As Long i, j, m, p
m = UBound(a)
p = UBound(a, 2)
For i = 0 To m
For j = 0 To p
Print Using "####.##############"; a(i, j);
Next j
Print
Next i
End Sub
output
Code: (Select All)
1.00000000000000   1.00000000000000   1.00000000000000   1.00000000000000
   2.00000000000011   4.00000000000000   8.00000000000011  15.99999999999997
   3.00000000000091   9.00000000000000  26.99999999999955  81.00000000000000
   4.00000000000000  16.00000000000000  64.00000000000182 256.00000000000000

   1.00000000000631   0.99999999999397   1.00000000000310   0.99999999999937
   2.00000000007003   3.99999999992497   8.00000000004081  15.99999999999153
   3.00000000030832   8.99999999965075  27.00000000019281  80.99999999995953
   4.00000000090040  15.99999999894135  64.00000000059481 255.99999999987494

   1.00000001287511   0.99999998735953   1.00000000618997   0.99999999878051
   2.00000017282946   3.99999983016824   8.00000008319284  15.99999998360744
   3.00000082591305   8.99999918818139  27.00000039771248  80.99999992162930
   4.00000253669350  15.99999750625284  64.00000122176243 255.99999975924175

   1.00003194036101   0.99996927234497   1.00001492581766   0.99999707177334
   2.00043128527955   3.99958508810619   8.00020154182073  15.99996046042222
   3.00206469592649   8.99801368628778  27.00096484445567  80.99981071149432
   4.00634687076126  15.99389407272611  64.00296593190251 255.99941812706993

   1.07888506286064   0.92429206751581   1.03674375970633   0.99279446622859
   3.06536455898004   2.97754344879331   8.49623463210287  15.90268727430023
   8.10050050155542   4.10492428973066  29.37575483774754  80.53410914096605
  19.67932001084409   0.95217113012768  71.30324807562465 254.56781665058406

Print this item

  Dancing Tesla Coil To Music
Posted by: SierraKen - 08-16-2024, 05:55 AM - Forum: Programs - Replies (4)

Hi all,

Back in 2022 I made this with the help of Petr and probably others on this forum. It simulates a Tesla Coil that shoots lightning from a rod and the lightning dances with the music you choose. Tonight I added a file dialog box to easily be able to choose a song to play on it. I also added the ability to stop it during play to choose another song. I included an old album I created on my computer around 20 years ago in the zip file. The album has no lyrics, just electronic music.  
Tell me what you think, thanks.

Edit: An improved version is on the next reply post. I removed this one.

Print this item

  Detecting color depth-16 color, 256 color, or 32 bit color
Posted by: dano - 08-16-2024, 12:38 AM - Forum: General Discussion - Replies (20)

I am changing all of my libraries to be agnostic to color depth...or at least trying.  I want them to automatically detect whether we are in 16 color, 256 color, or 32 bit color mode and automatically make adjustments on the fly to compensate for the colors being used, and use the proper colors.

So far so good, EXCEPT that I am having an issue with accurately detecting whether we are in 16 color, 256 color, or 32 bit color.

I cannot find this as a command for QB64.  Is there an easy way to accurately detect this?

Print this item

  Steve's Programming Challenge: Weights and Measures
Posted by: SMcNeill - 08-15-2024, 11:15 PM - Forum: General Discussion - Replies (23)

So here's a challenge which I'd like to propose for all of our coders here to undertake -- particularly @TerryRitchie @bplus @Pete @Dav , but which I'd truly LOVE to see everyone tackle.

The program concept is very simple -- Write a program that simulates you being a merchant in ancient times.  You have a whole bunch of lead weights, which you can use to measure out how much a customer's gold nugget weighs.

Your available weights are all in the power of two -- you have:

1 four-pound weight.
1 two-pound weight.
1 one-pound weight.
1 half-pound weight.
1 quarter-pound weight.
1 1/8-pound weight.
And so on to give you one of each weight from 4 pounds to 1/256 pounds.

Now the task is to figure out what weights are required to properly and perfectly weigh the following:

A 3 pound gold nugget
A 3/8 pound gold nugget
A 11/32 pound gold nugget
A 1/10 pound gold nugget

Now the first solution is obviously 1 2-pound weight + 1 1-pound weight. 
The question is -- can you find the proper combination for the other three nuggets I've mentioned??



Complete this task, and I doubt you guys will ever have any question ever again in the future about how floating point numbers work.  As you're some of our most prolific posters (and teachers) here, I would hope a simple task like this would be enough to help you guys understand the underlying issue with floating point numbers, so when people ask in the future, you'll be able to explain it to them better.  Wink

Print this item

  _KEYHIT Riddle me this???
Posted by: Pete - 08-15-2024, 03:40 PM - Forum: Help Me! - Replies (5)

Here is a modified version of the _KEYHIT Wiki example...

Code: (Select All)
DefLng A-Z
Screen _NewImage(800, 600, 8)
Cls , 1
font = _LoadFont("cyberbit.ttf", 24)
unifont = _LoadFont("cyberbit.ttf", 24, "UNICODE")
_Font font

Do
    x = _KeyHit
    If x And x <> oldx Then
        Select Case x
            Case Is > 0
                Color 10
                Print "Pressed "; 'positive value means key pressed
                oldx = x
            Case Else 'negative value means key released
                Color 2
                Print "Released ";
                x = -x
                oldx = 0
        End Select
        Select Case x
            Case Is < 256
                If x < 256 Then 'ASCII code values
                    Print "ASCII "; x;
                    If x >= 32 And x <= 255 Then Print "[" + Chr$(x) + "]" Else Print
                End If
            Case 256 To 65536 '2 byte key codes
                Print "2-BYTE-COMBO "; x And 255; x \ 256;
                x2 = x \ 256
                If x2 >= 32 And x2 <= 255 Then Print "[" + Chr$(x2) + "]" Else Print
            Case 100000 To 199999 'QB64 Virtual Key codes
                Print "SDL VK"; x - 100000
            Case Else
                If x >= 200000 And x < &H40000000 Then
                    Print "QB64 VK"; x - 200000
                    _Continue
                End If
                If x >= &H40000000 Then 'Unicode values (IME Input mode)
                    Print "UNICODE "; x - &H40000000; "0x" + Hex$(x - &H40000000) + " ...";
                    cx = Pos(1): cy = CsrLin
                    _Font unifont
                    Locate cy, cx
                    Color 15
                    z$ = MKL$(x - &H40000000) + MKL$(0)
                    Print z$ + z$ + z$;
                    _Font font
                    Locate cy, 1: Print
                End If
        End Select
    End If
Loop

Do this...

PRESS ALT.
RELEASE ALT.

So why does it record just the SDK value when alt is pressed, but records both the SDK and ASCII values when released? I'd feel better about the operation if it did not cycle back to deliver the -18 ASCII value after previously delivering the -308 SDK value when the Alt key was released.

Pete

Print this item