Author Topic: and another one for your toolbox...  (Read 21279 times)

0 Members and 1 Guest are viewing this topic.

Offline SMcNeill

  • QB64 Developer
  • Forum Resident
  • Posts: 3972
    • Steve’s QB64 Archive Forum
« Last Edit: December 03, 2020, 11:11:19 am by odin »
https://github.com/SteveMcNeill/Steve64 — A github collection of all things Steve!

Offline bplus

  • Global Moderator
  • Forum Resident
  • Posts: 8053
  • b = b + ...
Re: and another one for your toolbox...
« Reply #91 on: December 03, 2020, 01:53:11 pm »
Usually it’s in the bottom row.

CTRL - WIN - ALT - SPACEBAR - ALT - WIN - MENU - CTRL

https://www.howtogeek.com/425623/what-is-the-menu-key-for-and-how-to-remap-it/#:~:text=On%20full-size%20keyboards%2C%20the%20menu%20key%20is%20located,laptop%20keyboards—omit%20the%20menu%20key%20to%20save%20space.

Bottom row for me is:
Ctrl, Fn, Win, Alt, Space, Alt, Ctrl, 4 arrow keys   then  Number keypad block

And nothing is returned when I press Fn Key. Win key of course Interrupts probably a good thing.
Fn key works like a shift key for letters because those keys are doing double duty too.
« Last Edit: December 03, 2020, 01:55:58 pm by bplus »

Offline SMcNeill

  • QB64 Developer
  • Forum Resident
  • Posts: 3972
    • Steve’s QB64 Archive Forum
Re: and another one for your toolbox...
« Reply #92 on: December 03, 2020, 02:53:53 pm »
You just don’t have a menu key then.  Not all keyboards do.  They basically work similar to a right mouse click for the keyboard. 
https://github.com/SteveMcNeill/Steve64 — A github collection of all things Steve!

Offline TempodiBasic

  • Forum Resident
  • Posts: 1792
Re: and another one for your toolbox...
« Reply #93 on: December 03, 2020, 05:32:17 pm »
on my TOSHIBA the bottom row is Ctrl Fn Windows Alt Space AltGr Menu Ctrl  4 cursors  numeric pad
https://www.ebay.it/itm/TOSHIBA-SATELLITE-PRO-C850-15-6-INTEL-CORE-i3-3rd-GEN-4GB-RAM-250GB-HDD-WIN-10/283549905207?hash=item4204e43137:g:OloAAOSwMXxfft3O
Alt Gr is both  to get the 3rd character on the keyboard or together numerica pad to input ASCII code of the character choosen  both as Alt.
How many variation of the hardware!

Programming isn't difficult, only it's  consuming time and coffee

Offline bplus

  • Global Moderator
  • Forum Resident
  • Posts: 8053
  • b = b + ...
Re: and another one for your toolbox...
« Reply #94 on: January 31, 2021, 11:50:39 am »
Here is a set of handy subs and functions for storing an array of Integers, Floats and Strings (length limit 32) into a string. Thanks to Luke for idea.

One particularly useful application is for storing arrays into a string for a UDT since UDTs cant hold arrays.

For your tool box:
Code: QB64: [Select]
  1. ' words have a length limit of 32, needed some sort of cutoff number not too big, not too small
  2. SUB SetWord (array$, index AS LONG, word32$) ' Luke's Method except option explicit requires mod, no variables needed for one type
  3.     IF LEN(array$) < 32 * (index + 1) THEN array$ = array$ + STRING$(32 * (index + 1) - LEN(array$), SPC(32))
  4.     MID$(array$, index * 32 + 1) = LEFT$(word32$ + SPC(32), 32)
  5.  
  6. ' words have a length limit of 32, needed some sort of cutoff number not too big, not too small
  7. FUNCTION GetWord$ (array$, index AS LONG)
  8.     GetWord$ = _TRIM$(MID$(array$, index * 32 + 1, 32))
  9.  
  10. SUB SetLong (array$, index AS LONG, value&) ' Luke's Method except option explicit requires mod, no variables needed for one type
  11.     IF LEN(array$) < 4 * (index + 1) THEN array$ = array$ + STRING$(4 * (index + 1) - LEN(array$), CHR$(0))
  12.     MID$(array$, index * 4 + 1) = _MK$(LONG, value&)
  13.  
  14. FUNCTION GetLong& (array$, index AS LONG)
  15.     GetLong& = _CV(LONG, MID$(array$, index * 4 + 1, 4))
  16.  
  17. SUB SetDbl (array$, index AS LONG, value#) ' Luke's Method except option explicit requires mod, no variables needed for one type
  18.     IF LEN(array$) < 8 * (index + 1) THEN array$ = array$ + STRING$(8 * (index + 1) - LEN(array$), CHR$(0))
  19.     MID$(array$, index * 8 + 1) = _MK$(DOUBLE, value#)
  20.  
  21. FUNCTION GetDbl# (array$, index AS LONG)
  22.     GetDbl# = _CV(DOUBLE, MID$(array$, index * 8 + 1, 8))
  23.  

And some simple little demo tests of each pair:
Code: QB64: [Select]
  1. ' I modified this for LONG type only do one one for floats DOUBLE 2021-01-31  stored in handy toolbox
  2. DEFLNG A-Z
  3.     s AS STRING
  4. DIM v AS t
  5.  
  6. FOR i = 10 TO 0 STEP -1
  7.     SetLong v.s, i, i ^ 2
  8.  
  9. FOR i = 0 TO 10
  10.     PRINT GetLong&(v.s, i)
  11.  
  12. SUB SetLong (array$, index AS LONG, value&) ' Luke's Method except option explicit requires mod, no variables needed for one type
  13.     IF LEN(array$) < 4 * (index + 1) THEN array$ = array$ + STRING$(4 * (index + 1) - LEN(array$), CHR$(0))
  14.     MID$(array$, index * 4 + 1) = _MK$(LONG, value&)
  15.  
  16. FUNCTION GetLong& (array$, index AS LONG)
  17.     GetLong& = _CV(LONG, MID$(array$, index * 4 + 1, 4))
  18.  

Code: QB64: [Select]
  1. _TITLE "SetDbl GetDbl Test" '2021-01-31 for Handy Toolbox
  2. PRINT LEN(dbl) ' = 8
  3. FOR i = 0 TO 20
  4.     SetDbl rndArr$, i, RND + i
  5. FOR i = 20 TO 0 STEP -1
  6.     PRINT GetDbl#(rndArr$, i)
  7.  
  8. SUB SetDbl (array$, index AS LONG, value#) ' Luke's Method except option explicit requires mod, no variables needed for one type
  9.     IF LEN(array$) < 8 * (index + 1) THEN array$ = array$ + STRING$(8 * (index + 1) - LEN(array$), CHR$(0))
  10.     MID$(array$, index * 8 + 1) = _MK$(DOUBLE, value#)
  11.  
  12. FUNCTION GetDbl# (array$, index AS LONG)
  13.     GetDbl# = _CV(DOUBLE, MID$(array$, index * 8 + 1, 8))
  14.  

Code: QB64: [Select]
  1. _TITLE "SetWord GetWord test" '2021-01-31 for Handy Toolbox
  2.  
  3. FOR i = 0 TO 20
  4.     SetWord wordArr$, i, "Here is word number" + STR$(i)
  5. FOR i = 20 TO 0 STEP -1
  6.     PRINT "'"; GetWord$(wordArr$, i); "'"
  7.  
  8. ' words have a length limit of 32, needed some sort of cutoff number not too big, not too small
  9. SUB SetWord (array$, index AS LONG, word32$) ' Luke's Method except option explicit requires mod, no variables needed for one type
  10.     IF LEN(array$) < 32 * (index + 1) THEN array$ = array$ + STRING$(32 * (index + 1) - LEN(array$), SPC(32))
  11.     MID$(array$, index * 32 + 1) = LEFT$(word32$ + SPC(32), 32)
  12.  
  13. ' words have a length limit of 32, needed some sort of cutoff number not too big, not too small
  14. FUNCTION GetWord$ (array$, index AS LONG)
  15.     GetWord$ = _TRIM$(MID$(array$, index * 32 + 1, 32))
  16.  

« Last Edit: January 31, 2021, 12:02:27 pm by bplus »

Offline bplus

  • Global Moderator
  • Forum Resident
  • Posts: 8053
  • b = b + ...
Re: and another one for your toolbox...
« Reply #95 on: February 20, 2021, 01:47:57 am »
Along the lines in the above post, here is a set of tools for Variable Length Array-Like Strings.

https://www.qb64.org/forum/index.php?topic=3681.0
« Last Edit: March 29, 2021, 01:13:59 pm by bplus »

Offline bplus

  • Global Moderator
  • Forum Resident
  • Posts: 8053
  • b = b + ...
Re: and another one for your toolbox...
« Reply #96 on: February 21, 2021, 05:11:12 pm »
Evaluate$ - might take a little study to use but look at LOC!

https://www.qb64.org/forum/index.php?topic=3660.msg130074#msg130074





« Last Edit: March 29, 2021, 01:13:44 pm by bplus »

FellippeHeitor

  • Guest
Re: and another one for your toolbox...
« Reply #97 on: February 21, 2021, 05:28:58 pm »
Why are we screaming here?

Offline bplus

  • Global Moderator
  • Forum Resident
  • Posts: 8053
  • b = b + ...
Re: and another one for your toolbox...
« Reply #98 on: February 21, 2021, 06:48:01 pm »
We?

Dang it,  lost the link! Now I am ready to scream. ;-))
« Last Edit: February 22, 2021, 01:41:05 pm by bplus »

Offline bplus

  • Global Moderator
  • Forum Resident
  • Posts: 8053
  • b = b + ...
Re: and another one for your toolbox...
« Reply #99 on: March 29, 2021, 12:56:43 pm »
The Fval$ Evaluator is, in my humble opinion, light years ahead of Eval evaluator in flexibility ie it does strings and everything can be considered a string, my own private String Theory ;-))

Here I use it as core idea to my oh Interpreter:
https://www.qb64.org/forum/index.php?topic=3723.0

I also use string math, and files tools and others you can find in this thread "and another one for your toolbox"
Don't forget to bookmark this thread for reference to many tools and more importantly ideas bplus uses.

The only thing Eval has going for it is it offers more Basic-like number handling and math like formulas.

Of course if you want to get a little philosophical, physicists are leaning more towards information as the basis or foundation or Theory of Everything, just another String Theory in my book.
« Last Edit: March 29, 2021, 01:26:48 pm by bplus »

Offline SMcNeill

  • QB64 Developer
  • Forum Resident
  • Posts: 3972
    • Steve’s QB64 Archive Forum
Re: and another one for your toolbox...
« Reply #100 on: April 03, 2022, 03:47:55 am »
Here's a very short little tool for your toolbox:

Code: QB64: [Select]
  1. i = 2
  2.     Print i, Digits(i)
  3.     i = i * 2
  4. Loop Until Digits(i) > 7
  5.  
  6. Function Digits&& (value As Double)
  7.     Digits&& = Int(Log(Abs(value)) / Log(10.#)) + 1
  8.  

Function Digits tells you how many digits a number has, not counting any decimal places.  Can be much faster and simpler than something like Len(_Trim$(Str$(INT(number)))) + (Sgn(number) = -1) , which does the same thing (for integer values) by converting the number to a string first.
https://github.com/SteveMcNeill/Steve64 — A github collection of all things Steve!

Offline STxAxTIC

  • Library Staff
  • Forum Resident
  • Posts: 1091
  • he lives
Re: and another one for your toolbox...
« Reply #101 on: April 03, 2022, 04:11:17 am »
Not bad for fat integers, I think the more complete function captures this behavior and does these examples:

 
sssss.PNG
You're not done when it works, you're done when it's right.

Offline bplus

  • Global Moderator
  • Forum Resident
  • Posts: 8053
  • b = b + ...
Re: and another one for your toolbox...
« Reply #102 on: April 03, 2022, 10:48:58 pm »
Hey while we have this thread pulled down from a year ago, let's get this one posted too!

MessageBox function:

Code: QB64: [Select]
  1. ' Thank you FellippeHeitor!
  2. $If WIN Then
  3.         Function MessageBox (ByVal ignore&, message$, title$, Byval type&)
  4.     End Declare
  5.     DECLARE LIBRARY ""
  6.     FUNCTION MessageBox (BYVAL ignore&, message$, title$, BYVAL type&)
  7.     END DECLARE
  8. ' answer = MessageBox(0, "Hi, bplus. You can do this.", "This is platform-agnostic", 0)
  9. Dim m$, answer, temp
  10. m$ = "Message: press OK to return 1, press Cancel to return 2."
  11. answer = MessageBox(0, m$, "Test MessageBox", 4097) ' 4097 for OK = 1 Cancel = 2 Modal on top messagebox
  12. If answer = 1 Then
  13.     temp = MessageBox(0, "OK was pressed.", "Test MessageBox", 4096)
  14.     temp = MessageBox(0, "Cancel was pressed.", "Test MessageBox", 4096)
  15.  

Thank you Fellippe! Very lightweight in terms of LOC.

Offline NOVARSEG

  • Forum Resident
  • Posts: 509
Re: and another one for your toolbox...
« Reply #103 on: April 04, 2022, 12:48:37 am »
Ok im all rusty now but heh I remember the good ol days - labyrinth tiles, one line word editors, BMP viewers,  all the stuff we know and love

Offline bplus

  • Global Moderator
  • Forum Resident
  • Posts: 8053
  • b = b + ...
Re: and another one for your toolbox...
« Reply #104 on: April 04, 2022, 02:19:29 pm »
Ok im all rusty now but heh I remember the good ol days - labyrinth tiles, one line word editors, BMP viewers,  all the stuff we know and love

I'd ask where have you been, if you don't mind but that's for Discord. That's right they converted me.