Author Topic: Your opinions needed...  (Read 3527 times)

0 Members and 1 Guest are viewing this topic.

Offline Pete

  • Forum Resident
  • Posts: 2361
  • Cuz I sez so, varmint!
    • View Profile
Your opinions needed...
« on: July 27, 2019, 04:25:41 pm »
Which s the best way to put a library together that requires the user to make their own prompts? One method uses DATA statements, like: DATA 123,456,EOF, while the other makes the user DIM the prompts variable and type: DIM Prompt$(20): Prompt$(0) = "abc": Prompt$(1) = "def", etc.

This is for a nice little "Notepad" with prompts program I made, which I would like to post as a library. The thing is, I only want to maintain one version.

Anyway, have a look here: https://www.qb64.org/forum/index.php?topic=1530.msg107504#msg107504

https://www.qb64.org/forum/index.php?topic=1530.msg107504#msg107504

Both libraries allow you to make your own prompts, color the text window and text, type, cut, copy, paste, highlight, select all, and use the mouse as well as the keyboard to accomplish these tasks. I may even make another graphics version, using _putstring, in the future.

Pete   

Want to learn how to write code on cave walls? https://www.tapatalk.com/groups/qbasic/qbasic-f1/

Offline SMcNeill

  • QB64 Developer
  • Forum Resident
  • Posts: 3972
    • View Profile
    • Steve’s QB64 Archive Forum
Re: Your opinions needed...
« Reply #1 on: July 27, 2019, 04:51:47 pm »
Generally, the way I do something like this is with 2 library files.

File One: “Library.BI”
Code: QB64: [Select]
  1. REDIM SHARED Prompt(0) AS STRING

File Two: “Library.BM”
Code: [Select]
SUB LibrarySub1
    ....stuff
END SUB

FUNCTION LibraryFunction1
    ....stuff
END FUNCTION



Then when the user calls the library, they do so like:

Code: QB64: [Select]
  1. $INCLUDE:’Library.BI’
  2.  
  3. REDIM Prompt(10) AS STRING ‘User resets the array to needed size
  4. Prompt(0) = “Whatever”: Prompt(1) = “Whatever2”
  5. ...more Prompt(), which the user can fill however they want: manually or by data statements.
  6. ....Main code here
  7.  
  8. $INCLUDE:’Library.BM’
  9.  
https://github.com/SteveMcNeill/Steve64 — A github collection of all things Steve!

Offline Pete

  • Forum Resident
  • Posts: 2361
  • Cuz I sez so, varmint!
    • View Profile
Re: Your opinions needed...
« Reply #2 on: July 27, 2019, 05:17:47 pm »
Do you have a link to one of your posted routines that shows that?

Pete
Want to learn how to write code on cave walls? https://www.tapatalk.com/groups/qbasic/qbasic-f1/

Offline SMcNeill

  • QB64 Developer
  • Forum Resident
  • Posts: 3972
    • View Profile
    • Steve’s QB64 Archive Forum
Re: Your opinions needed...
« Reply #3 on: July 27, 2019, 05:37:02 pm »
Do you have a link to one of your posted routines that shows that?

Pete

Here’s a link to one of Terry Richies:  https://www.qb64.org/forum/index.php?topic=537.msg6476#msg6476

The start of that long set of code is all his TYPES, DECLARE statements, CONST, and global variables.  Around line 272 is where you can see him REDIM SHARED several arrays with a 0 Index, as placeholders for ones the end-user will use in their own code.

Those declarations would be the BI file.  The SUB/FUNCTION statements are the BM file, and you just place them on either side of your own work to use them, just like the simpler demo of my SaveImage Library: https://www.qb64.org/forum/index.php?topic=47.msg245#msg245

Code: QB64: [Select]
  1. '$include:'saveimage.bi'
  2. text$ = "Whatever the heck it is that we might want to compress, be that a long string of input, a binary file (just load the whole file into a single string and then deflate it), or whatever else is wanted)."
  3. de$ = Deflate(text$) ' <-- This is how simple it is to deflate the string
  4. t$ = Inflate(de$) '  <-- This is how simple it is to inflate that deflated string
  5. '$include:'saveimage.bm'[/quote]
  6.  
  7. First line is the include *.BI for the library.  Last line is the include *.BM file for the library.  The users code just pops into the middle.
  8.  
  9.  
  10.  
https://github.com/SteveMcNeill/Steve64 — A github collection of all things Steve!

Offline bplus

  • Global Moderator
  • Forum Resident
  • Posts: 8053
  • b = b + ...
    • View Profile
Re: Your opinions needed...
« Reply #4 on: July 28, 2019, 10:25:24 am »
Here is my one successful test of using a library (for a challenge on another forum):
Code: QB64: [Select]
  1. _TITLE "test range.bi and bm"
  2. '$include: 'range.bi'
  3.  
  4. PRINT Range("1 to 100 step 1 do sin")
  5. PRINT "End of sin(1 to 100 stepping by 1) table."
  6.  
  7. PRINT: PRINT "Sin at 90 degree intervals:"
  8. PRINT Range("0 to 6.2832 step 1.5708 do sin")
  9.  
  10. PRINT: PRINT "Squares of numbers from 3.5 to 5.5 stepping by .5"
  11. PRINT Range("5.5 to 3.5 step .5 do square")
  12.  
  13. '$include: 'range.bm'
  14.  
  15.  

range.bi
Code: QB64: [Select]
  1. DEFSTR R '< not a good idea but it was a challenge!
  2.  

range.bm
Code: QB64: [Select]
  1. FUNCTION Range (p$)
  2.     p$ = LCASE$(p$)
  3.     IF INSTR(p$, " to ") = 0 OR INSTR(p$, " step ") = 0 OR INSTR(p$, " do ") = 0 THEN
  4.         PRINT "Range$ Function is missing to, step, do keywords or keywords aren't spaced. Program aborted."
  5.         END
  6.     END IF
  7.     start = VAL((leftOf$(p$, " to ")))
  8.     finish = VAL(rightOf$(leftOf$(p$, " step "), " to "))
  9.     stepper = VAL(rightOf$(leftOf$(p$, " do "), " step "))
  10.     func$ = rightOf$(p$, " do ")
  11.     IF INSTR(" sin square", func$) = 0 THEN '<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<< function check list
  12.         PRINT "Range$ Function does not recognize do function. Program aborted."
  13.         END
  14.     END IF
  15.     IF stepper >= 0 THEN
  16.         IF stepper = 0 THEN stepper = 1
  17.         IF start > finish THEN SWAP start, finish
  18.     ELSEIF stepper < 0 THEN
  19.         IF start < finish THEN SWAP start, finish
  20.     END IF
  21.     FOR i = start TO finish STEP stepper
  22.         SELECT CASE func$
  23.             CASE "sin": return$ = return$ + STR$(SIN(i)) + CHR$(13)
  24.             CASE "square": return$ = return$ + STR$(i * i) + CHR$(13)
  25.                 'it is trivial to plug in more functions here
  26.                 'but don't forget to add to the function check list as well
  27.         END SELECT
  28.     NEXT
  29.     Range = LEFT$(return$, LEN(return$) - 1)
  30.  
  31. FUNCTION leftOf$ (source$, of$)
  32.     posOf = INSTR(source$, of$)
  33.     IF posOf > 0 THEN leftOf$ = MID$(source$, 1, posOf - 1)
  34.  
  35. FUNCTION rightOf$ (source$, of$)
  36.     posOf = INSTR(source$, of$)
  37.     IF posOf > 0 THEN rightOf$ = MID$(source$, posOf + LEN(of$))
  38.  

Offline Petr

  • Forum Resident
  • Posts: 1720
  • The best code is the DNA of the hops.
    • View Profile
Re: Your opinions needed...
« Reply #5 on: July 28, 2019, 11:17:58 am »
Hi, Pete. I would choose a DIM method, just as I do. This means that no matter how many text windows the user uses, simply counting the required number automatically with _PRESERVE - increases the number of places in the field without deleting the previous positions. As an example library ... I am adding a partially incomplete library for loading ANI files.