Author Topic: Recomendation of some basic libraries for QB  (Read 4797 times)

0 Members and 1 Guest are viewing this topic.

Offline QB64Curious

  • Newbie
  • Posts: 22
    • View Profile
Recomendation of some basic libraries for QB
« on: February 03, 2022, 02:03:35 pm »
Hi,

There are a lot of legacy libraries around, but it's difficult to search through each one, and find out the kinds of functions I'm looking for.

I'm looking for simple functions like

GetCurrentLocation()  - returns an array with Current Column and Current Row position

PrintAt_RowY_ColumnX_WithColor(  Y, X, Color ) - Self-explanatory, but also saves the current cursor location and LOCATES it back after the call.

GetCurrentBackGroundColor()


, stuff like that, just for Text Mode Screen 0.

I know how to code all these things in principle, but was looking for a basic library that already covers this functionality robustly.


Also, I'd like to write up some Functional modules for QB.  I'm nearly certain it's not available yet, but would like to do

QBArray_Map( fn, SourceArray ) -> TargetArray
QBArray_Reduce( fn, SourceArray ) -> FinalResult

, at the least.  If there's already something like that, can you let me know, so as to avoid reinventing the wheel?

« Last Edit: February 03, 2022, 02:50:47 pm by QB64Curious »

Offline bplus

  • Global Moderator
  • Forum Resident
  • Posts: 8053
  • b = b + ...
    • View Profile
Re: Recomendation of some basic libraries for QB
« Reply #1 on: February 03, 2022, 02:50:53 pm »
https://www.qb64sourcecode.com

Terry Richie's Tutorial will help get you up to date with QB64 terms.

PrintAt_RowY_ColumnX_WithColor(  Y, X, Color )   >>
Code: QB64: [Select]
  1. _PrintString(xpix, ypix), text$
  'set color first

or just
Code: QB64: [Select]
  1. Locate row, col
on screen 0

GetCurrentBackGroundColor()  >> something like
Code: QB64: [Select]
  1.  
Here is very handy link: https://wiki.qb64.org/wiki/Main_Page
Use Keyword Reference by usage if you are looking for name of QB64 Sub or Function

Offline QB64Curious

  • Newbie
  • Posts: 22
    • View Profile
Re: Recomendation of some basic libraries for QB
« Reply #2 on: February 03, 2022, 02:57:48 pm »
Hi bplus,

Coupla quesitons

1)  Does _PrintString(xpix, ypix), text$ return the cursor back to the original location, before calling it?  I didn't mention this in the original post, but edited it afterwards.

2)  Do these routines work in 4.5?  I like to go back & forth between 64 and 4.5, testing in each environment.  At least for now.

This is a really nice comprehensive page, thanks. - https://www.qb64sourcecode.com/Task7.html



Offline bplus

  • Global Moderator
  • Forum Resident
  • Posts: 8053
  • b = b + ...
    • View Profile
Re: Recomendation of some basic libraries for QB
« Reply #3 on: February 03, 2022, 02:59:11 pm »
Quote
Also, I'd like to write up some Functional modules for QB.  I'm nearly certain it's not available yet, but would like to do

QBArray_Map( fn, SourceArray ) -> TargetArray
QBArray_Reduce( fn, SourceArray ) -> FinalResult

, at the least.  If there's already something like that, can you let me know, so as to avoid reinventing the wheel?

What? Explain in English... BTW Functions can not return arrays ie nope() = FunctionName() (x, y, z)
but you can rewrite an array in a Sub (or Function) like

Sort myArray()   ' edited line removed ()'s and As something sorry

sub Sort(MyArr() as say Integer)
' some sort routine
end sub
« Last Edit: February 03, 2022, 03:12:30 pm by bplus »

Offline bplus

  • Global Moderator
  • Forum Resident
  • Posts: 8053
  • b = b + ...
    • View Profile
Re: Recomendation of some basic libraries for QB
« Reply #4 on: February 03, 2022, 03:00:27 pm »
Hi bplus,

Coupla quesitons

1)  Does _PrintString(xpix, ypix), text$ return the cursor back to the original location, before calling it?  I didn't mention this in the original post, but edited it afterwards.

2)  Do these routines work in 4.5?  I like to go back & forth between 64 and 4.5, testing in each environment.  At least for now.

This is a really nice comprehensive page, thanks. - https://www.qb64sourcecode.com/Task7.html

1. No
2. No, every _Sub or _Function is not compatible to old QB stuff

Offline bplus

  • Global Moderator
  • Forum Resident
  • Posts: 8053
  • b = b + ...
    • View Profile
Re: Recomendation of some basic libraries for QB
« Reply #5 on: February 03, 2022, 03:05:42 pm »
_PrintString(col, row), "Works in screen 0 but x, y aren't pixels places but character cell locations ie row (y), col (x).

Locate takes y, row vertical position and then x, col horizontal position, kind of confusing comparing to graphics screens.

Also Locate errors at 0 for row or col, whereas _PrtintString doesn't care.

Offline QB64Curious

  • Newbie
  • Posts: 22
    • View Profile
Re: Recomendation of some basic libraries for QB
« Reply #6 on: February 03, 2022, 03:07:42 pm »
So the arrays are always passed by reference, correct?  So if you pass one to a Sub or Function, and that module modifieds the array, then when you return from that module, the array remains modified.  Is that right?

Thanks,


What? Explain in English... BTW Functions can not return arrays ie nope() = FunctionName() (x, y, z)
but you can rewrite an array in a Sub (or Function) like

Sort (myArray() as something)

sub Sort(MyArr() as say Integer)
' some sort routine
end sub

Offline bplus

  • Global Moderator
  • Forum Resident
  • Posts: 8053
  • b = b + ...
    • View Profile
Re: Recomendation of some basic libraries for QB
« Reply #7 on: February 03, 2022, 03:10:37 pm »
Sorry I put () around arguments when calling a sub, wrong unless you use outdated CALL keyword first.

Sort myArray()

is what the "call" to a Sort sub looks like these days.

Offline LM

  • Newbie
  • Posts: 28
    • View Profile
Re: Recomendation of some basic libraries for QB
« Reply #8 on: February 03, 2022, 03:11:05 pm »
For Screen 0: You can get the current row and column using CSRLIN and POS(0).  Read/store those in variables first and use LOCATE to get back to that position later.

Offline QB64Curious

  • Newbie
  • Posts: 22
    • View Profile
Re: Recomendation of some basic libraries for QB
« Reply #9 on: February 03, 2022, 03:17:33 pm »
I understand, thanks.

Sorry I put () around arguments when calling a sub, wrong unless you use outdated CALL keyword first.

Sort myArray()

is what the "call" to a Sort sub looks like these days.

Offline QB64Curious

  • Newbie
  • Posts: 22
    • View Profile
Re: Recomendation of some basic libraries for QB
« Reply #10 on: February 03, 2022, 03:19:31 pm »
Thanks, LM.  That's the general way I would approach it, but I wanted to see if there were some existing libraries that dealt with these, as well as any side effects and parameter validation.


For Screen 0: You can get the current row and column using CSRLIN and POS(0).  Read/store those in variables first and use LOCATE to get back to that position later.

Offline bplus

  • Global Moderator
  • Forum Resident
  • Posts: 8053
  • b = b + ...
    • View Profile
Re: Recomendation of some basic libraries for QB
« Reply #11 on: February 03, 2022, 03:26:42 pm »
So the arrays are always passed by reference, correct?  So if you pass one to a Sub or Function, and that module modifieds the array, then when you return from that module, the array remains modified.  Is that right?

Thanks,

Everything is passed by reference, QB64 is unusual in that. If you change a variable value inside a procedure (Sub or function) that value will be preserved when return from procedure IFF you use the same Type in variable pass as Type defined in Procedure. You can overcome this by setting varaibles as copies of arguments inside the procedure and then change those all you want inside procedure.

Offline QB64Curious

  • Newbie
  • Posts: 22
    • View Profile
Re: Recomendation of some basic libraries for QB
« Reply #12 on: February 03, 2022, 04:04:02 pm »
Thanks, bplus.


Everything is passed by reference, QB64 is unusual in that. If you change a variable value inside a procedure (Sub or function) that value will be preserved when return from procedure IFF you use the same Type in variable pass as Type defined in Procedure. You can overcome this by setting varaibles as copies of arguments inside the procedure and then change those all you want inside procedure.

Offline QB64Curious

  • Newbie
  • Posts: 22
    • View Profile
Re: Recomendation of some basic libraries for QB
« Reply #13 on: February 03, 2022, 10:33:32 pm »
Although it isn't packaged as a library, this site has some useful general functions:

https://www.pcjs.org/documents/books/mspl13/basic/qblang/

(This may already be mentioned in the QB64 wiki)

, and specifically, a function for printing at a specific Row and Column, while retaining the original position.  It's pretty much what was suggested elsewhere, but is a complete routine.

Code: QB64: [Select]
  1.     ' Print message at the designated row and column.
  2.     SUB PrntMsg(Row%,Col%,Message$) STATIC
  3.         ' Save current cursor position.
  4.         CurRow%=CSRLIN
  5.         CurCol%=POS(0)
  6.         ' Print the message at the location.
  7.         LOCATE Row%,Col% : PRINT Message$;
  8.         ' Restore cursor location.
  9.         LOCATE CurRow%,CurCol%
  10.     END SUB
  11.  

It doesn't include a COLOR attribute parameter, but it's a good start.