Author Topic: Scroll Bar  (Read 16106 times)

0 Members and 1 Guest are viewing this topic.

Offline bplus

  • Global Moderator
  • Forum Resident
  • Posts: 8053
  • b = b + ...
    • View Profile
Re: Scroll Bar
« Reply #30 on: September 21, 2019, 10:39:23 am »
Respected bplus,
Could you please tell me the code for just a scroll bar? That would be a big help. I would do a detailed study on that code later.
Regards.

Steve posted code that uses actual scroll bars but I suspect it is way over your head, for some strange reason he does not use normal arrow keys, pg keys... and mouse wheel?

As TempodiBasic said,
Quote
For scrolling
you must load all strings to scroll into an array and pass it to the SUB/Function of scrolling!
Good Luck

Here is menu made from your code you might be able to understand, that sort of does what you want:

Code: QB64: [Select]
  1. SCREEN _NEWIMAGE(800, 700, 32) ' <<<< 32 here means you are using RGB and aplha colors _RGB32(red , green, blue)
  2.  
  3.     'set color then CLS so entire background is same
  4.     COLOR _RGB32(200, 200, 255), _RGB32(0, 0, 120) ' <<< light blueish ink on dark blue paper
  5.     CLS 'so now entire background is dark blue paper
  6.  
  7.     _KEYCLEAR ' need to clear last key press  so first input is not skipped
  8.  
  9.  
  10.     INPUT "ENTER pH OF SOIL"; p
  11.     INPUT "ENTER TEMPERATURE IN FAHRENHEIT"; T
  12.  
  13.     IF p >= 1 AND p < 4.5 AND T > 113 AND T < 134 THEN
  14.         PRINT "pH IS TOO LOW AND TEMPERATURE IS TOO HIGH. CONTROL pH WITH HYDRATED LIMESTONE OR WOOD ASH (0.5 POUNDS OF HYDRATED LIMESTONE EVERY TEN SQUARE FOOT CAN INCREASE pH BY APPROXIMATELY ONE POINT.)"
  15.         PRINT: PRINT "Press any to continue... ": SLEEP
  16.     ELSEIF p >= 1 AND p < 4.5 AND T < 32 THEN
  17.         PRINT "BOTH pH AND TEMPERATURE ARE TOO LOW. CONTROL pH WITH HYDRATED LIMESTONE OR WOOD ASH (0.5 POUNDS OF HYDRATED LIMESTONE EVERY TEN SQUARE FOOT CAN INCREASE pH BY APPROXIMATELY ONE POINT.)"
  18.         PRINT: PRINT "Press any to continue... ": SLEEP
  19.     ELSEIF p > 8.4 AND p <= 14 AND T > 113 AND T <= 134 THEN
  20.         PRINT "BOTH pH AND TEMPERATURE ARE TOO HIGH. CONTROL pH WITH ORGANIC MATTER ( PEAT MOSS), ALUMINIUM SULPHATE, OR SULPHUR (1.2 POUNDS OF ALUMINIUM SULPHATE OR 0.2 POUNDS OF SULPHUR EVERY TEN SQUARE FOOT CAN LOWER pH BY APPROXIMATELY ONE POINT.)"
  21.         PRINT: PRINT "Press any to continue... ": SLEEP
  22.     ELSEIF p > 8.4 AND p < 14 AND T < 32 THEN
  23.         PRINT "pH IS TOO HIGH AND TEMPERATURE IS TOO LOW. CONTROL pH WITH ORAGNIC MATTER LIKE PEAT MOSS, ALUMINIUM SULPHATE, OR SULPHUR (1.2 POUNDS OF ALUMINIUM SULPHATE OR 0.2 POUNDS OF SULPHUR EVRY TEN SQUARE FOOT CAN LOWER pH BY APPROXIMATELY ONE POINT.)"
  24.         PRINT: PRINT "Press any to continue... ": SLEEP
  25.     ELSEIF p >= 4.5 AND p <= 8.4 AND T > 113 AND T < 134 THEN
  26.         PRINT "TEMPERATURE IS TOO HIGH."
  27.         PRINT: PRINT "Press any to continue... ": SLEEP
  28.     ELSEIF p >= 4.5 AND p <= 8.4 AND T < 32 THEN
  29.         PRINT "TEMPERATURE IS TOO LOW."
  30.         PRINT: PRINT "Press any to continue... ": SLEEP
  31.     ELSEIF p <= 14 AND p > 8.4 AND T >= 32 AND T <= 113 THEN
  32.         PRINT "pH IS TOO HIGH. CONTROL IT USING HYDRATED LIMESTONE OR WOOD ASH. (0.5 POUNDS OF HYDRATED LIMESTONE EVERY TEN SQUARE FOOT WILL INCREASE pH BY APPROXIMATELY ONE POINT.)"
  33.         PRINT: PRINT "Press any to continue... ": SLEEP
  34.     ELSEIF p >= 1 AND p < 4.5 AND T >= 32 AND T < 134 THEN
  35.         PRINT "pH IS TOO LOW. CONTROL pH USING HYDRATED LIMETONE OR WOOD ASH (0.5 POUNDS OF HYDRATED LIMESTONE EVERY TEN SQUARE FOOT WILL INCREASE pH BY APPROXIMATELY ONE POINT.)"
  36.         PRINT: PRINT "Press any to continue... ": SLEEP
  37.     ELSEIF p < 1 OR p > 14 AND T > 134 THEN
  38.         PRINT "PLEASE ENTER VALID VALUES."
  39.         PRINT: PRINT "Press any to continue... ": SLEEP
  40.     ELSEIF p >= 1 AND p <= 14 AND T > 134 THEN
  41.         PRINT "ENTER VALID TEMPERATURE VALUE."
  42.         PRINT: PRINT "Press any to continue... ": SLEEP
  43.     ELSEIF p < 1 OR p > 14 AND T <= 134 THEN
  44.         PRINT "ENTER VALID pH VALUE."
  45.         PRINT: PRINT "Press any to continue... ": SLEEP
  46.     ELSEIF T >= 32 AND T <= 50 AND p >= 4.5 AND p <= 5 THEN
  47.         DO
  48.             'set color then CLS so entire background is same
  49.             COLOR _RGB32(200, 200, 255), _RGB32(0, 0, 120)
  50.             CLS
  51.             PRINT "PLANTS THAT WILL GROW BEST IN THESE CONDITIONS:"
  52.             PRINT "Menu:"
  53.             PRINT "1 ENGLISH OAK (TREE):"
  54.             PRINT "2 PAPER BIRCH (TREE):"
  55.             PRINT "3 AZALEAS (FLOWERS):"
  56.             PRINT "4 More Notes"
  57.             PRINT "5 Quit Menu"
  58.             PRINT
  59.             INPUT "Please enter your number choice "; choice
  60.             SELECT CASE choice
  61.                 CASE 1
  62.                     'set color then CLS so entire background is same
  63.                     COLOR _RGB32(128, 64, 32), _RGB32(255, 200, 100)
  64.                     CLS
  65.                     PRINT
  66.                     PRINT "1.ENGLISH OAK (TREE):"
  67.                     PRINT "WATER: SEEDLING:KEEP SOIL WET. YOUNG:1.5 GALLONS A DAY. MATURE:CAN DRAW 50 GALLONS."
  68.                     PRINT "FERTILIZER: DON'T USE TILL 2 YEARS OLD. WHEN MATURE, USE 12-6-6 OR 12-4-8 FERTILIZER ANNUALLY (16.6 POUNDS EVERY 1000 SQUARE FEET.)"
  69.                     PRINT "DISTANCE: PLANT 25 FEET APART. TEMPERATURE: 32-92 F. pH:4.5-5.0."
  70.                     PRINT "SUNLIGHT:HIGH(6-8 HOURS A DAY). MOISTURE PERCENT: MODERATE (21-40%)"
  71.                     PRINT
  72.                     PRINT "press any to continue... "
  73.                     SLEEP
  74.  
  75.                 CASE 2
  76.                     'set color then CLS so entire background is same
  77.                     COLOR _RGB32(0, 64, 0), _RGB32(100, 100, 255)
  78.                     CLS
  79.                     PRINT "2.PAPER BIRCH (TREE):"
  80.                     PRINT "WATER: YOUNG: LET WATER RUN FROM HOSE FOR 30 SEC EVERY 2 WEEKS. MATURE:KEEP SOIL WET 10INCH DEEP."
  81.                     PRINT "FERTILIZER: USE 11-22-22 FERTILIZER ANNUALLY AND COVER SOIL WELL. WHEN MATURE, FERTILIZE ONLY WHEN DEFFIECENCY NOTED."
  82.                     PRINT "DISTANCE:PLANT 25 FT APART. TEMPERATURE:32-113 F pH:4.5-8.4"
  83.                     PRINT "SUNLIGHT: HIGH (6-8 HOURS A DAY). MOISTURE PERCENT: MODERATE (21-40%)"
  84.                     PRINT
  85.                     PRINT "press any to continue... "
  86.                     SLEEP
  87.  
  88.                 CASE 3
  89.                     'set color then CLS so entire background is same
  90.                     COLOR _RGB32(255, 255, 0), _RGB32(0, 0, 100)
  91.                     CLS
  92.                     PRINT "3.AZALEAS (FLOWERS):"
  93.                     PRINT "WATER:4 GALLONS PER SQUARE METRE EVERY 2 WEEKS."
  94.                     PRINT "FERTILIZER:USE 10-10-10 FERTILIZER 2-3 TIMES A YEAR."
  95.                     PRINT "DISTANCE:PLANT 2 FEET APART. TEMPERATURE:32-76 F. pH:4.5-5.0."
  96.                     PRINT "SUNLIGHT: SUNNY TO PARTIAL (HIGH-MED). MOISTURE PERCENT: OPTIMUM 41-60%"
  97.                     PRINT
  98.                     PRINT "press any to continue... "
  99.                     SLEEP
  100.  
  101.                 CASE 4
  102.                     'set color then CLS so entire background is same
  103.                     COLOR _RGB32(200, 200, 255), _RGB32(60, 0, 60)
  104.                     CLS
  105.                     PRINT "NOTE 1. FERTILIZER FORMULAS STATED SHOW THE PROPORTION OF NITROGEN-PHOSPHORUS-POTASSIUM RESPECTIVELY."
  106.                     PRINT "NOTE 2:PLANTS NEED WELL DRAINING AND NOURISHED SOIL AND BEST CO2 AMOUNT FOR THEM IS 1000-1500 PPM (PARTS PER MILLION)"
  107.                     PRINT "NOTE 3:INSTEAD OF NPK FERTILIZER YOU CAN USE THESE IN THE PROPORTION YOU REQUIRE:"
  108.                     PRINT "COFFEE GROUNDS,BLOOD MEAL, AND COTTON SEED MEAL FOR NITROGEN"
  109.                     PRINT "FISH BONE MEAL, STEAMED BONE MEAL, AND ROCK DUST FOR PHOSPHORUS"
  110.                     PRINT "KELP MEAL, HARDWOOD ASH, AND GREEN ORGANIC MATERIAL FOR POTASSIUM"
  111.                     PRINT
  112.                     PRINT "press any to continue... "
  113.                     SLEEP
  114.  
  115.             END SELECT
  116.  
  117.         LOOP UNTIL choice = 5
  118.     END IF
  119.  
« Last Edit: September 21, 2019, 10:50:08 am by bplus »

Offline Erum

  • Newbie
  • Posts: 10
    • View Profile
Re: Scroll Bar
« Reply #31 on: September 21, 2019, 10:41:13 am »
Respected TempodiBasic,
I know I am annoying all the experts like you with my dumbness ;) Thank you for that kind and enlightening reply. I guess that coding for scroll bar is going to take a bit of studying and research. Thanks.
Regards.

Offline Erum

  • Newbie
  • Posts: 10
    • View Profile
Re: Scroll Bar
« Reply #32 on: September 21, 2019, 10:45:36 am »
Respected bplus,
Thank you for that reply. You did a great job helping a dummy like me, as I said Iam a ninth grader and the only BASIC I learnt was from the chapter 'basics of BASIC." ;) I completely understand the select case syntax and I think I might use that. Thanks again.
Regards.

Offline bplus

  • Global Moderator
  • Forum Resident
  • Posts: 8053
  • b = b + ...
    • View Profile
Re: Scroll Bar
« Reply #33 on: September 21, 2019, 10:58:13 am »
Hi Erum,

I have some advice on the inputs of pH and temperature:

If you handle all the issues of pH First! and then only INPUT temperature after the pH is in range, it might be easier to code and follow the code, instead of having to handle all possible cases of pH AND temperature together.

Just advice take it or leave it :)
« Last Edit: September 21, 2019, 10:59:33 am by bplus »

Offline Petr

  • Forum Resident
  • Posts: 1720
  • The best code is the DNA of the hops.
    • View Profile
Re: Scroll Bar
« Reply #34 on: September 21, 2019, 02:00:27 pm »
Hi Erum. I try writing for you something tomorrow. I thing, something easy as is PRINT use, but with output to screen area which allow text shift up/down/left/right. Here is psedocode + image how i think it, if it is, what you need:

PseudoCode:

BoxPrint "This is very long text, which i need shifting in text area on the screen and which not allow edit this text. This is very long text, which i need shifting in text area on the screen and which not allow edit this text. This is very long text, which i need shifting in text area on the screen and which not allow edit this text."

and excepted output is something as on image:

  [ You are not allowed to view this attachment ]  

But as I say. I'll start with it tomorrow, because I'm going to a beer. Is Saturday night...

Is this, what you need? I can do it for you, also color tags can be inserted to this boxes, if you need it. Then it can be something as TextBox "/color 15/ This is white text /color 1/ and this is blue text" I ask you for proposal for this TextBox SUB before i start programming it.




« Last Edit: September 21, 2019, 02:04:49 pm by Petr »

Offline bplus

  • Global Moderator
  • Forum Resident
  • Posts: 8053
  • b = b + ...
    • View Profile
Re: Scroll Bar
« Reply #35 on: September 21, 2019, 02:38:42 pm »
Petr, what you propose would make an excellent tool for all of us. I don't know why Steve hadn't connected his scroll bars to mouse? or normal arrow and pg keys.

I have an array selector too but no scroll bar to it, it uses mouse over and mouse wheel with arrow keys and pg keys, home, end... you can even type the item number and enter to select but it is also pretty complex for Erum.

Even with scroll bar code made for him, Erum would have another problem, getting large amounts of text into an array or arrays, think I will look into that.

Offline Erum

  • Newbie
  • Posts: 10
    • View Profile
Re: Scroll Bar
« Reply #36 on: September 21, 2019, 02:51:22 pm »
Respected Petr and bplus,
Thank you for showing concern and for constantly helping me.
For Petr: Yes I think text boxes can be used instead. I will try them once you provide the guidelines.
For bplus: I do think that these things can be complex, but Iam sure I can figure them out once I study them in detail. P.S. I am a ‘she’, not a ‘he’ ;)
Regards.
« Last Edit: September 21, 2019, 02:56:08 pm by Erum »

Offline bplus

  • Global Moderator
  • Forum Resident
  • Posts: 8053
  • b = b + ...
    • View Profile
Re: Scroll Bar
« Reply #37 on: September 21, 2019, 07:05:34 pm »
Hi Erum,

I like your can do attitude and politeness :)

I took your text blocks and pasted then into a normal .txt file using a \ to mark the titles of smaller text blocks.
Filename: "test file.txt"
Code: QB64: [Select]
  1. \1. ENGLISH OAK (TREE):
  2.      WATER: SEEDLING:KEEP SOIL WET. YOUNG:1.5 GALLONS A DAY. MATURE:CAN DRAW 50 GALLONS.
  3. FERTILIZER: DON'T USE TILL 2 YEARS OLD. WHEN MATURE, USE 12-6-6 OR 12-4-8 FERTILIZER ANNUALLY (16.6 POUNDS EVERY 1000 SQUARE FEET.)
  4.   DISTANCE: PLANT 25 FEET APART. TEMPERATURE: 32-92 F. pH:4.5-5.0.
  5.   SUNLIGHT: HIGH(6-8 HOURS A DAY). MOISTURE PERCENT: MODERATE (21-40%)
  6. \2. PAPER BIRCH (TREE):
  7.      WATER: YOUNG: LET WATER RUN FROM HOSE FOR 30 SEC EVERY 2 WEEKS. MATURE:KEEP SOIL WET 10INCH DEEP.
  8.   DISTANCE: PLANT 25 FT APART. TEMPERATURE:32-113 F pH:4.5-8.4
  9.   SUNLIGHT: HIGH (6-8 HOURS A DAY). MOISTURE PERCENT: MODERATE (21-40%)
  10. \3. AZALEAS (FLOWERS):
  11.      WATER: 4 GALLONS PER SQUARE METRE EVERY 2 WEEKS.
  12. FERTILIZER: USE 10-10-10 FERTILIZER 2-3 TIMES A YEAR.
  13.   DISTANCE: PLANT 2 FEET APART. TEMPERATURE:32-76 F. pH:4.5-5.0.
  14.   SUNLIGHT: SUNNY TO PARTIAL (HIGH-MED). MOISTURE PERCENT: OPTIMUM 41-60%
  15. \4. Notes:
  16.  NOTE 1. FERTILIZER FORMULAS STATED SHOW THE PROPORTION OF NITROGEN-PHOSPHORUS-POTASSIUM RESPECTIVELY.
  17.  NOTE 2: PLANTS NEED WELL DRAINING AND NOURISHED SOIL AND BEST CO2 AMOUNT FOR THEM IS 1000-1500 PPM (PARTS PER MILLION)
  18.  NOTE 3: INSTEAD OF NPK FERTILIZER YOU CAN USE THESE IN THE PROPORTION YOU REQUIRE:
  19.          COFFEE GROUNDS,BLOOD MEAL, AND COTTON SEED MEAL FOR NITROGEN
  20.          FISH BONE MEAL, STEAMED BONE MEAL, AND ROCK DUST FOR PHOSPHORUS
  21. \
  22.  

When you have huge amounts of text it is likely more convenient to edit in a txt editor.

Then I put together or made some tools for loading the text file contents into an array and then more tools for picking out the titled sections for displaying in Petr's text scroller or one of our scrollers.

Here is the test code for our simple little 4 text blocks:

Code: QB64: [Select]
  1. _TITLE "Tool(s) for loading an array from a text file" 'B+ started 2019-09-21
  2.  
  3. DIM txtFile$, nFlines, j, i
  4.  
  5. 'test loading whole file
  6. REDIM test$(1 TO 1)
  7. txtFile$ = "test file.txt"
  8. nFlines = fLineCnt(txtFile$, test$())
  9. 'IF nFLines THEN
  10. '    FOR i = 1 TO nFLines
  11. '        PRINT i; ", "; test$(i)
  12. '        IF (i + 1) MOD 10 = 0 THEN PRINT "press any to continue...": SLEEP: CLS
  13. '    NEXT
  14. 'END IF
  15.  
  16. 'test loading sections of the file into temp$
  17. FOR j = 1 TO 4 'test 4 titles that start with number.
  18.     REDIM temp$(1 TO 1)
  19.     loadTitle test$(), _TRIM$(STR$(j)) + ". ", temp$()
  20.     FOR i = LBOUND(temp$) TO UBOUND(temp$)
  21.         PRINT temp$(i)
  22.     NEXT
  23.     PRINT " end of text... press any to continue..."
  24.     SLEEP
  25. PRINT "Test is done."
  26.  
  27. ' This SUB searches the source array for \+first part of title$ farthest left of source() strings.
  28. ' If a matching string is found, this SUB loads the given dynamic arr() starting at 1 with title string
  29. ' and keeps loading strings until it hits another \ or reaches the end of the file.
  30. SUB loadTitle (source() AS STRING, title$, arr() AS STRING)
  31.     DIM i AS INTEGER
  32.     FOR i = LBOUND(source) TO UBOUND(source)
  33.         IF UCASE$(LEFT$(source$(i), LEN("\" + title$))) = UCASE$("\" + title$) THEN
  34.             REDIM arr(1 TO 1) AS STRING
  35.             arr(1) = MID$(source(i), 2)
  36.             WHILE i + 1 <= UBOUND(source)
  37.                 i = i + 1
  38.                 IF LEFT$(source(i), 1) = "\" THEN 'done
  39.                     EXIT SUB
  40.                 ELSE
  41.                     sAppend arr(), source(i)
  42.                 END IF
  43.             WEND
  44.             EXIT FOR
  45.         END IF
  46.     NEXT
  47.  
  48. 'append to the string array the string item
  49. SUB sAppend (arr() AS STRING, item AS STRING)
  50.     REDIM _PRESERVE arr(LBOUND(arr) TO UBOUND(arr) + 1) AS STRING
  51.     arr(UBOUND(arr)) = item
  52.  
  53. ' This FUNCTION loads a file (using CR + LF between lines) contents into an base 1 array
  54. ' so the upper bound and line count match and returns the number of lines.
  55. ' Hence if 0 was returned the file was empty or not found. new 2019-09-21
  56. FUNCTION fLineCnt (txtFile$, arr() AS STRING)
  57.     DIM filecount%, b$
  58.     filecount% = 0
  59.     IF _FILEEXISTS(txtFile$) THEN
  60.         OPEN txtFile$ FOR BINARY AS #1
  61.         b$ = SPACE$(LOF(1))
  62.         GET #1, , b$
  63.         CLOSE #1
  64.         REDIM _PRESERVE arr(1 TO 1) AS STRING
  65.         Split b$, CHR$(13) + CHR$(10), arr()
  66.         filecount% = UBOUND(arr)
  67.     END IF
  68.     fLineCnt = filecount% 'this file returns the number of lines loaded, 0 means file did not exist
  69.  
  70. 'This SUB will take a given N delimited string, and delimiter$ and create an array of N+1 strings using the LBOUND of the given dynamic array to load.
  71. 'notes: the loadMeArray() needs to be dynamic string array and will not change the LBOUND of the array it is given.  rev 2019-08-27
  72. SUB Split (SplitMeString AS STRING, delim AS STRING, loadMeArray() AS STRING)
  73.     DIM curpos AS LONG, arrpos AS LONG, LD AS LONG, dpos AS LONG 'fix use the Lbound the array already has
  74.     curpos = 1: arrpos = LBOUND(loadMeArray): LD = LEN(delim)
  75.     dpos = INSTR(curpos, SplitMeString, delim)
  76.     DO UNTIL dpos = 0
  77.         loadMeArray(arrpos) = MID$(SplitMeString, curpos, dpos - curpos)
  78.         arrpos = arrpos + 1
  79.         IF arrpos > UBOUND(loadMeArray) THEN REDIM _PRESERVE loadMeArray(LBOUND(loadMeArray) TO UBOUND(loadMeArray) + 1000) AS STRING
  80.         curpos = dpos + LD
  81.         dpos = INSTR(curpos, SplitMeString, delim)
  82.     LOOP
  83.     loadMeArray(arrpos) = MID$(SplitMeString, curpos)
  84.     REDIM _PRESERVE loadMeArray(LBOUND(loadMeArray) TO arrpos) AS STRING 'get the ubound correct
  85.  

Summary:
Put the txt file in the same directory as the bas file. (And make sure under the RUN menu of IDE the Output EXE to Source Folder is bulleted.)

fLineCnt is a function, so it returns something, in this case the number of lines it loaded into the a dynamic string array you specify ie REDIM for Dynamic arrays (instead of DIM, Dynamic Arrays = Arrays you can change the size of, DIM arrays can't be resized so are called Static not Dynamic.)

Code: QB64: [Select]
  1. lineCount = fLineCnt("myLoadTxtFile.txt", myFileArr$())

if lineCnt = 0 you didn't get anything loaded, otherwise myFileArr$() is loaded with the contents of the txt file.



Now to get a titled section from myFileArr$():

Menus work off numbers so I used your numbers to mark the start of a text block, so once a number is chosen from menu that text block can be loaded into an array and if array is huge we can use a scroller to display the entire contents easily for user of your code.

To get an array ready for the scroller just make this call to sub, say 2 text block
REDIM tempTxt$(1 to1) ' setup container to hold the text block
LoadTitle myFileArr$(), "2. ", tempTxt$() 'this loads tempTxt$() array

now ready to display tempTxt$() in scroller!

Too much?




« Last Edit: September 21, 2019, 07:40:43 pm by bplus »

Offline TempodiBasic

  • Forum Resident
  • Posts: 1792
    • View Profile
Re: Scroll Bar
« Reply #38 on: September 21, 2019, 07:13:39 pm »
Hi Erum
glad to be useful
please focus your mind before on this
an attempt to analyze the issue that the program must solve.

structure of the program
what does your program?
as you have said in previous posts
1. it takes 2 parameters (pH and Temperature in FAHRENHEIT)
 2. it outputs informations as text on the screen on the basis of 2 parameters


moreover you should think that you manage
 3. the input from keyboard and/or mouse
 4. and the output to the screen
 5. and the storage of the informations (inner to the program or outer in files)
 6. and an interface for user (only text, an ASCII windowed, a graphic windowed)


going deeper
1. you need 2 variables for the 2 parameters... the type of variable used depens of type of data to get from keyboard.
see here for more infohttp://qb64.org/wiki/Variable_Types
From your code posted before I can think that pH has a range from 1 to 14 with decimal so in QB64 we can use single declared with ! suffix or none suffix, while for temperature there is a range from 32 or less to 134 , but you manage only integer, so you can use an integer variable declared with suffix %

2. in your code you share analysis of value pH and Temperature with Output to screen.
If you want a more flexible code it is useful to separate these two performances. So tomorrow you can modify only the part of program that you must adapt to new needs and not following the line of flow of the program in chained instructions.
  2.1
  you can make a grid of pH values and Temperature to manage the various cases... (if you do this on you code you can see that the
 case temperature T >= 32 AND T <= 113 is not managed in the range pH p > 8.4 AND p <= 14 so in this case your program
 stucks
 2.2 all strings for output must be loaded into an array of strings  (the string is text between 2 ") (array is a set of variables of the same type and with the same name and with an index to distinguish one from another one)  see here for more informations http://qb64.org/wiki/Arrays

3. input from keyboard
 3.1 you can use old INPUT (a semi editor of Qbasic) and you must control the values typed from user (as you do in your code)
 3.2 or the INKEY$ to accept only digit and . for get pH and temperature values
 3.3 or you can use the powerful _KEYHIT of QB64 at the same way of INKEY$ for your goal
 3.4 or you can use mouse (_MOUSEBUTTON(1) or _MOUSEBUTTON(2) or _MOUSEWHEEL) to set input for pH and Temperature
 3.5 or you can use mouse for interaction of user with a structured interface made in text or graphic mode

4. output to the screen
  4.1 choose the screen mode
        if it is good for you an interface  only text or window text based (ASCII screen) you can use SCREEN 0 and use 8 colors for
        paper color (background 0-7) and 31 ink colors (foreground 0-31, after 15 color is blinking)
        but if you prefer the graphic mode you can have so many graphic options to manage and use
  4.2 choose the interface that you must build it for using in your program see point 6 (for now you have used a line text interface)

5. storage of informations
   5.1  informations stored as strings into the program (the way that you have coded)
   5.2  informations stored as DATA into the program (blocks of DATA) see here for more info http://qb64.org/wiki/DATA
   5.3  informations stored as TXT file that you load in the program in a set of variable of type of string called Array (OPEN FOR
          INPUT) see here for more info http://qb64.org/wiki/OPEN. The real advantage to code in this way is that you can
          change or adapt the text editing the file with an editor of text from Notepad to OpenOffice Writer and you program gains
          adjourned informations without so many changes to the code.
6. an user interface
   6.1 a line text of interface (that you have coded)
   6.2 a text interface with prefixed space of screen for different actions
   6.3 a text ASCII interface with inputbox, button, listbox
   6.4 a graphic interface with inputbox, button, listbox

Good work and good luck

PS: all the answers that you have got until now is how to make a listbox in ASCII mode or in Graphic mode.
Wrong :-)  before the last Bplus 's post!


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

Offline Erum

  • Newbie
  • Posts: 10
    • View Profile
Re: Scroll Bar
« Reply #39 on: September 22, 2019, 05:37:48 am »
Respected TempodiBasic and blpus,
Thnak you so much once again. I am gonna focus and try them and see which one works best.
Regards.

Offline Petr

  • Forum Resident
  • Posts: 1720
  • The best code is the DNA of the hops.
    • View Profile
Re: Scroll Bar
« Reply #40 on: September 22, 2019, 01:16:57 pm »
Hello. Does anyone know why my head hurts today? :) To the thread point. Here is the first version of the text shift in a long sentence. I will add two more things - color support, as promised, and the bottom bar for a quick shift. But I'm having trouble with the mousewheel. It doesn't work as swiftly as I want. Anyone want to look at it? Thanks.

Code: QB64: [Select]
  1. 'promise: Textbox with use as PRINT. NEED GRAPHIC SCREEN!
  2.  
  3. 'this is future "TextBox.BI"
  4.  
  5. TYPE TB
  6.     X AS INTEGER '   X position graphic coord
  7.     Y AS INTEGER '   Y position graphic coord
  8.     L AS INTEGER '   TextBox lenght
  9.     T AS STRING '    TextBox text
  10.     B AS INTEGER '   Text begin in textbox  (for shift)
  11.     Arrow AS LONG
  12.     D AS SINGLE 'for time delay between click to arrows
  13. REDIM SHARED TBA(0) AS TB
  14. TBA(0).Arrow = PutArrow&
  15. 'real textboxes starting from 1
  16.  
  17. 'end of future "TextBox.BI"
  18.  
  19. SCREEN _NEWIMAGE(800, 600, 32)
  20. DIM test(20) AS LONG
  21.  
  22. FOR t = 1 TO 20
  23.     test(t) = INITBOX(100 + 250 * RND, 30 * t - 27, "Hi, I'm working on it. This is the test text of the program for longitudinal scrolling in the window. Color capabilities will be added soon. The program uses arrays because program need to remember the shift values for more than one box.", 15 + RND * 40)
  24.  
  25.  
  26.  
  27.     FOR p = 1 TO 20
  28.         PRINTBOX p
  29.     NEXT
  30.  
  31.  
  32. 'this is future "TextBox.BM"
  33.  
  34. FUNCTION INITBOX (X AS INTEGER, Y AS INTEGER, Text AS STRING, BoxLenght AS INTEGER) 'X, Y are GRAPHIC coordinates
  35.     UTB = UBOUND(tba)
  36.     REDIM _PRESERVE TBA(UTB + 1) AS TB
  37.     TBA(UTB + 1).X = X
  38.     TBA(UTB + 1).Y = Y
  39.     TBA(UTB + 1).L = BoxLenght
  40.     TBA(UTB + 1).T = Text
  41.     TBA(UTB + 1).B = 1
  42.     INITBOX = UTB + 1
  43.  
  44.  
  45. SUB PRINTBOX (nr AS LONG)
  46.     IF nr < 1 OR nr > UBOUND(tba) THEN EXIT SUB 'subscript out of range prevention
  47.     TextBoxArrow& = TBA(0).Arrow
  48.     TextLenght = _PRINTWIDTH(TBA(nr).T)
  49.     B = TBA(nr).B
  50.     TextHeight = _FONTHEIGHT
  51.     X = TBA(nr).X
  52.     Y = TBA(nr).Y
  53.     BoxLenght = TBA(nr).L
  54.     T$ = MID$(TBA(nr).T, TBA(nr).B, TBA(nr).L) 'text loader
  55.  
  56.     FOR h = 1 TO 10
  57.         DO WHILE _MOUSEINPUT
  58.             IF _MOUSEX >= X - 30 AND _MOUSEX <= X + 30 + BoxLenght * _FONTWIDTH THEN
  59.                 IF _MOUSEY >= Y - 3 AND _MOUSEY <= Y + 3 + TextHeight THEN
  60.                     B = B + _MOUSEWHEEL
  61.                 END IF
  62.             END IF
  63.         LOOP
  64.     NEXT
  65.     '
  66.     MB1 = _MOUSEBUTTON(1)
  67.     MX = _MOUSEX
  68.     MY = _MOUSEY
  69.  
  70.  
  71.  
  72.     LINE (X - 30, Y - 3)-(X + 30 + BoxLenght * _FONTWIDTH, Y + 3 + TextHeight), , B
  73.     _PUTIMAGE (X + 15 + BoxLenght * _FONTWIDTH, Y + 1), TextBoxArrow&
  74.     _PUTIMAGE (X - 15, Y + 1)-(X - 26, Y + 12), TextBoxArrow&
  75.  
  76.     IF TIMER < 1 THEN TBA(nr).D = 0
  77.  
  78.     IF MX >= X + 15 + BoxLenght * _FONTWIDTH AND MX <= X + 15 + BoxLenght * _FONTWIDTH + 12 THEN
  79.         IF MY >= Y + 1 AND MY <= Y + 13 THEN
  80.             IF TBA(nr).D < TIMER THEN
  81.                 LINE (X + 15 + BoxLenght * _FONTWIDTH, Y + 1)-(X + 15 + BoxLenght * _FONTWIDTH + 11, Y + 12), &H44FFFFFF, BF
  82.                 IF MB1 THEN
  83.                     B = B + 1
  84.                 END IF
  85.                 TBA(nr).D = TIMER + .1
  86.             END IF
  87.         END IF
  88.     END IF
  89.  
  90.     IF MX >= X - 26 AND MX <= X - 15 THEN
  91.         IF MY >= Y + 1 AND MY <= Y + 13 THEN
  92.             IF TBA(nr).D < TIMER THEN
  93.                 LINE (X - 26, Y + 1)-(X - 15, Y + 12), &H44FFFFFF, BF
  94.                 IF MB1 THEN
  95.                     B = B - 1
  96.                 END IF
  97.                 TBA(nr).D = TIMER + .1
  98.             END IF
  99.         END IF
  100.     END IF
  101.     IF B < 1 THEN B = 1
  102.     IF B > LEN(TBA(nr).T) - TBA(nr).L + 1 THEN B = LEN(TBA(nr).T) - TBA(nr).L + 1
  103.     TBA(nr).B = B
  104.     _PRINTSTRING (X, Y), T$
  105.  
  106.  
  107. FUNCTION PutArrow& 'draw one arrow to virtual screen (so is not need external image)
  108.     PutArrow& = _NEWIMAGE(12, 12, 32)
  109.     D = _DEST
  110.     _DEST PutArrow&
  111.     CLS
  112.     LINE (1, 4)-(6, 4) '  ------------     up
  113.     LINE (1, 8)-(6, 8) '  ------------     down
  114.     LINE (1, 4)-(1, 8) '  I                arrow back
  115.     LINE (6, 4)-(6, 1)
  116.     LINE (6, 8)-(6, 11)
  117.     LINE (6, 11)-(11, 6)
  118.     LINE (6, 1)-(11, 6)
  119.     PAINT (6, 6), &HFF777777, &HFFFFFFFF
  120.     _DEST D
  121. 'End of future "TextBox.BM"
  122.  

  [ You are not allowed to view this attachment ]  

Offline Petr

  • Forum Resident
  • Posts: 1720
  • The best code is the DNA of the hops.
    • View Profile
Re: Scroll Bar
« Reply #41 on: September 22, 2019, 04:41:45 pm »
Small upgrade for previous code. Tomorrow i aply colors, replace it to BI and BM for higher clearity and start second box which use shift up/down.

Code: QB64: [Select]
  1. 'promise: Textbox with use as PRINT. NEED GRAPHIC SCREEN!
  2.  
  3. 'this is future "TextBox.BI"
  4.  
  5. TYPE TB
  6.     X AS INTEGER '   X position graphic coord
  7.     Y AS INTEGER '   Y position graphic coord
  8.     L AS INTEGER '   TextBox lenght
  9.     T AS STRING '    TextBox text
  10.     B AS INTEGER '   Text begin in textbox  (for shift)
  11.     Arrow AS LONG
  12.     D AS SINGLE 'for time delay between click to arrows
  13. REDIM SHARED TBA(0) AS TB
  14. TBA(0).Arrow = PutArrow&
  15. 'real textboxes starting from 1
  16.  
  17. 'end of future "TextBox.BI"
  18.  
  19. SCREEN _NEWIMAGE(800, 600, 32)
  20. DIM test(10) AS LONG
  21.  
  22. FOR t = 1 TO 10
  23.     test(t) = INITBOX(100 + 250 * RND, 40 * t - 27, "Hi, I'm working on it. This is the test text of the program for longitudinal scrolling in the window. Color capabilities will be added soon. The program uses arrays because program need to remember the shift values for more than one box.", 15 + RND * 40)
  24. Demo = INITBOX(150, 500, "This is small text", 9)
  25.  
  26.  
  27.  
  28.     FOR p = 1 TO 10
  29.         PRINTBOX p
  30.     NEXT
  31.     PRINTBOX Demo
  32.  
  33.     _DISPLAY
  34.  
  35. 'this is future "TextBox.BM"
  36.  
  37. FUNCTION INITBOX (X AS INTEGER, Y AS INTEGER, Text AS STRING, BoxLenght AS INTEGER) 'X, Y are GRAPHIC coordinates
  38.     UTB = UBOUND(tba)
  39.     REDIM _PRESERVE TBA(UTB + 1) AS TB
  40.     TBA(UTB + 1).X = X
  41.     TBA(UTB + 1).Y = Y
  42.     TBA(UTB + 1).L = BoxLenght
  43.     TBA(UTB + 1).T = Text
  44.     TBA(UTB + 1).B = 1
  45.     INITBOX = UTB + 1
  46.  
  47.  
  48. SUB PRINTBOX (nr AS LONG)
  49.     IF nr < 1 OR nr > UBOUND(tba) THEN EXIT SUB 'subscript out of range prevention
  50.     TextBoxArrow& = TBA(0).Arrow
  51.     TextLenght = _PRINTWIDTH(TBA(nr).T)
  52.     B = TBA(nr).B
  53.     TextHeight = _FONTHEIGHT
  54.     X = TBA(nr).X
  55.     Y = TBA(nr).Y
  56.     BoxLenght = TBA(nr).L
  57.     T$ = MID$(TBA(nr).T, TBA(nr).B, TBA(nr).L) 'text loader
  58.  
  59.     FOR h = 1 TO 10
  60.         DO WHILE _MOUSEINPUT
  61.             IF _MOUSEX >= X - 30 AND _MOUSEX <= X + 30 + BoxLenght * _FONTWIDTH THEN
  62.                 IF _MOUSEY >= Y - 3 AND _MOUSEY <= Y + 3 + TextHeight THEN
  63.                     B = B + _MOUSEWHEEL
  64.                 END IF
  65.             END IF
  66.         LOOP
  67.     NEXT
  68.     '
  69.     MB1 = _MOUSEBUTTON(1)
  70.     MX = _MOUSEX
  71.     MY = _MOUSEY
  72.  
  73.     LINE (X - 30, Y - 3)-(X + 30 + BoxLenght * _FONTWIDTH, Y + 12 + TextHeight), &HFF000000, BF
  74.  
  75.     LINE (X - 30, Y - 3)-(X + 30 + BoxLenght * _FONTWIDTH, Y + 12 + TextHeight), , B
  76.     LINE (X - 28, Y - 1)-(X + 28 + BoxLenght * _FONTWIDTH, Y + 3 + TextHeight), , B
  77.  
  78.  
  79.     LL = ((B + TBA(nr).L) / LEN(TBA(nr).T)) * 100
  80.     Full = BoxLenght * _FONTWIDTH + 15
  81.     OnePercent = Full / 100
  82.     Actual = LL * OnePercent
  83.  
  84.     LINE (X + Actual, Y + TextHeight + 5)-(Actual + 10 + X, Y + 10 + TextHeight), , BF
  85.     IF MX >= X + Actual AND MX <= Actual + 10 + X THEN
  86.         IF MY >= Y + TextHeight + 5 AND MY <= Y + 10 + TextHeight THEN
  87.             IF MB1 THEN
  88.                 omx = MX
  89.                 DO UNTIL _MOUSEX <> MX
  90.                     WHILE _MOUSEINPUT: WEND
  91.                     MB1 = _MOUSEBUTTON(1)
  92.                     B = B + _MOUSEX - omx
  93.                 LOOP
  94.             END IF
  95.         END IF
  96.     END IF
  97.  
  98.  
  99.     _PUTIMAGE (X + 15 + BoxLenght * _FONTWIDTH, Y + 1), TextBoxArrow&
  100.     _PUTIMAGE (X - 15, Y + 1)-(X - 26, Y + 12), TextBoxArrow&
  101.  
  102.     IF TIMER < 1 THEN TBA(nr).D = 0
  103.  
  104.     IF MX >= X + 15 + BoxLenght * _FONTWIDTH AND MX <= X + 15 + BoxLenght * _FONTWIDTH + 12 THEN
  105.         IF MY >= Y + 1 AND MY <= Y + 13 THEN
  106.             IF TBA(nr).D < TIMER THEN
  107.                 LINE (X + 15 + BoxLenght * _FONTWIDTH, Y + 1)-(X + 15 + BoxLenght * _FONTWIDTH + 11, Y + 12), &H44FFFFFF, BF
  108.                 IF MB1 THEN
  109.                     B = B + 1
  110.                 END IF
  111.                 TBA(nr).D = TIMER + .01
  112.             END IF
  113.         END IF
  114.     END IF
  115.  
  116.     IF MX >= X - 26 AND MX <= X - 15 THEN
  117.         IF MY >= Y + 1 AND MY <= Y + 13 THEN
  118.             IF TBA(nr).D < TIMER THEN
  119.                 LINE (X - 26, Y + 1)-(X - 15, Y + 12), &H44FFFFFF, BF
  120.                 IF MB1 THEN
  121.                     B = B - 1
  122.                 END IF
  123.                 TBA(nr).D = TIMER + .01
  124.             END IF
  125.         END IF
  126.     END IF
  127.     IF B < 1 THEN B = 1
  128.     IF B > LEN(TBA(nr).T) - TBA(nr).L + 1 THEN B = LEN(TBA(nr).T) - TBA(nr).L + 1
  129.     TBA(nr).B = B
  130.     'here will be add color block (and next sub, which calculate text lenght without color flags and other one, which return text string without color flags)
  131.     'future use: V = INITBOX (1, 1, "&HFFFFFFWhite text is here,&HFFFF0000and red text is here", 10)    --  or can be done as "/RED/ This is RED text /WHITE/ and this is white text" with Steve's color constants.
  132.  
  133.     _PRINTSTRING (X, Y), T$
  134.  
  135.  
  136. FUNCTION PutArrow& 'draw one arrow to virtual screen (so is not need external image)
  137.     PutArrow& = _NEWIMAGE(12, 12, 32)
  138.     D = _DEST
  139.     _DEST PutArrow&
  140.     CLS
  141.     LINE (1, 4)-(6, 4) '  ------------     up
  142.     LINE (1, 8)-(6, 8) '  ------------     down
  143.     LINE (1, 4)-(1, 8) '  I                arrow back
  144.     LINE (6, 4)-(6, 1)
  145.     LINE (6, 8)-(6, 11)
  146.     LINE (6, 11)-(11, 6)
  147.     LINE (6, 1)-(11, 6)
  148.     PAINT (6, 6), &HFF777777, &HFFFFFFFF
  149.     _DEST D
  150. 'End of future "TextBox.BM"
  151.  

Offline TempodiBasic

  • Forum Resident
  • Posts: 1792
    • View Profile
Re: Scroll Bar
« Reply #42 on: September 22, 2019, 06:23:16 pm »
Hi Petr

I think to have a fix for _mousewheel 
here code
Code: QB64: [Select]
  1. 'promise: Textbox with use as PRINT. NEED GRAPHIC SCREEN!
  2.  
  3. 'this is future "TextBox.BI"
  4.  
  5. TYPE TB
  6.     X AS INTEGER '   X position graphic coord
  7.     Y AS INTEGER '   Y position graphic coord
  8.     L AS INTEGER '   TextBox lenght
  9.     T AS STRING '    TextBox text
  10.     B AS INTEGER '   Text begin in textbox  (for shift)
  11.     Arrow AS LONG
  12.     D AS SINGLE 'for time delay between click to arrows
  13. REDIM SHARED TBA(0) AS TB
  14. TBA(0).Arrow = PutArrow&
  15. 'real textboxes starting from 1
  16.  
  17. 'end of future "TextBox.BI"
  18.  
  19. SCREEN _NEWIMAGE(800, 600, 32)
  20. DIM test(20) AS LONG
  21.  
  22. FOR t = 1 TO 20
  23.     test(t) = INITBOX(100 + 250 * RND, 30 * t - 27, "Hi, I'm working on it. This is the test text of the program for longitudinal scrolling in the window. Color capabilities will be added soon. The program uses arrays because program need to remember the shift values for more than one box.", 15 + RND * 40)
  24.  
  25.  
  26.  
  27.     FOR p = 1 TO 20
  28.         PRINTBOX p
  29.     NEXT
  30.  
  31.  
  32. 'this is future "TextBox.BM"
  33.  
  34. FUNCTION INITBOX (X AS INTEGER, Y AS INTEGER, Text AS STRING, BoxLenght AS INTEGER) 'X, Y are GRAPHIC coordinates
  35.     UTB = UBOUND(tba)
  36.     REDIM _PRESERVE TBA(UTB + 1) AS TB
  37.     TBA(UTB + 1).X = X
  38.     TBA(UTB + 1).Y = Y
  39.     TBA(UTB + 1).L = BoxLenght
  40.     TBA(UTB + 1).T = Text
  41.     TBA(UTB + 1).B = 1
  42.     INITBOX = UTB + 1
  43.  
  44.  
  45. SUB PRINTBOX (nr AS LONG)
  46.     IF nr < 1 OR nr > UBOUND(tba) THEN EXIT SUB 'subscript out of range prevention
  47.     TextBoxArrow& = TBA(0).Arrow
  48.     TextLenght = _PRINTWIDTH(TBA(nr).T)
  49.     B = TBA(nr).B
  50.     TextHeight = _FONTHEIGHT
  51.     X = TBA(nr).X
  52.     Y = TBA(nr).Y
  53.     BoxLenght = TBA(nr).L
  54.     T$ = MID$(TBA(nr).T, TBA(nr).B, TBA(nr).L) 'text loader
  55.  
  56.     '    FOR h = 1 TO 10   ' not need this focusing
  57.     DO
  58.         MW = _MOUSEWHEEL ' a variable to store value -1/+1
  59.         IF MW THEN EXIT DO ' we must exit because _mousewheel resets its value to 0 at each _mouseinput
  60.     '    NEXT
  61.     '
  62.     MB1 = _MOUSEBUTTON(1)
  63.     MX = _MOUSEX
  64.     MY = _MOUSEY
  65.  
  66.  
  67.  
  68.     LINE (X - 30, Y - 3)-(X + 30 + BoxLenght * _FONTWIDTH, Y + 3 + TextHeight), , B
  69.     _PUTIMAGE (X + 15 + BoxLenght * _FONTWIDTH, Y + 1), TextBoxArrow&
  70.     _PUTIMAGE (X - 15, Y + 1)-(X - 26, Y + 12), TextBoxArrow&
  71.  
  72.     IF TIMER < 1 THEN TBA(nr).D = 0
  73.  
  74.     IF MX >= X + 15 + BoxLenght * _FONTWIDTH AND MX <= X + 15 + BoxLenght * _FONTWIDTH + 12 THEN
  75.         IF MY >= Y + 1 AND MY <= Y + 13 THEN
  76.             IF TBA(nr).D < TIMER THEN
  77.                 LINE (X + 15 + BoxLenght * _FONTWIDTH, Y + 1)-(X + 15 + BoxLenght * _FONTWIDTH + 11, Y + 12), &H44FFFFFF, BF
  78.                 IF MB1 THEN
  79.                     B = B + 1
  80.                 END IF
  81.                 TBA(nr).D = TIMER + .1
  82.             END IF
  83.         END IF
  84.     END IF
  85.  
  86.     IF MX >= X - 26 AND MX <= X - 15 THEN
  87.         IF MY >= Y + 1 AND MY <= Y + 13 THEN
  88.             IF TBA(nr).D < TIMER THEN
  89.                 LINE (X - 26, Y + 1)-(X - 15, Y + 12), &H44FFFFFF, BF
  90.                 IF MB1 THEN
  91.                     B = B - 1
  92.                 END IF
  93.                 TBA(nr).D = TIMER + .1
  94.             END IF
  95.         END IF
  96.     END IF
  97.     ' Here the managment of the event _mousewheel
  98.     IF _MOUSEX >= X - 30 AND _MOUSEX <= X + 30 + BoxLenght * _FONTWIDTH THEN
  99.         IF _MOUSEY >= Y - 3 AND _MOUSEY <= Y + 3 + TextHeight THEN
  100.             B = B + MW
  101.             '  DO WHILE _MOUSEINPUT: LOOP  ' <-- this works
  102.             IF _MOUSEINPUT THEN REM   <----  also this works
  103.         END IF
  104.     END IF
  105.  
  106.     IF B < 1 THEN B = 1
  107.     IF B > LEN(TBA(nr).T) - TBA(nr).L + 1 THEN B = LEN(TBA(nr).T) - TBA(nr).L + 1
  108.     TBA(nr).B = B
  109.     _PRINTSTRING (X, Y), T$
  110.  
  111.  
  112. FUNCTION PutArrow& 'draw one arrow to virtual screen (so is not need external image)
  113.     PutArrow& = _NEWIMAGE(12, 12, 32)
  114.     D = _DEST
  115.     _DEST PutArrow&
  116.     CLS
  117.     LINE (1, 4)-(6, 4) '  ------------     up
  118.     LINE (1, 8)-(6, 8) '  ------------     down
  119.     LINE (1, 4)-(1, 8) '  I                arrow back
  120.     LINE (6, 4)-(6, 1)
  121.     LINE (6, 8)-(6, 11)
  122.     LINE (6, 11)-(11, 6)
  123.     LINE (6, 1)-(11, 6)
  124.     PAINT (6, 6), &HFF777777, &HFFFFFFFF
  125.     _DEST D
  126. 'End of future "TextBox.BM"
  127.  
  128.  

I hope it is portable to the final version....
Waiting  feedback
Goog Coding
Programming isn't difficult, only it's  consuming time and coffee

Offline TempodiBasic

  • Forum Resident
  • Posts: 1792
    • View Profile
Re: Scroll Bar
« Reply #43 on: September 22, 2019, 06:47:12 pm »
Fine the presence of the bar under the text!

here mod for _mousewheel but after playing for a while with arrows, scroll bar and mouse wheel the program stucks.


Code: QB64: [Select]
  1. 'promise: Textbox with use as PRINT. NEED GRAPHIC SCREEN!
  2.  
  3. 'this is future "TextBox.BI"
  4.  
  5. TYPE TB
  6.     X AS INTEGER '   X position graphic coord
  7.     Y AS INTEGER '   Y position graphic coord
  8.     L AS INTEGER '   TextBox lenght
  9.     T AS STRING '    TextBox text
  10.     B AS INTEGER '   Text begin in textbox  (for shift)
  11.     Arrow AS LONG
  12.     D AS SINGLE 'for time delay between click to arrows
  13. REDIM SHARED TBA(0) AS TB
  14. TBA(0).Arrow = PutArrow&
  15. 'real textboxes starting from 1
  16.  
  17. 'end of future "TextBox.BI"
  18.  
  19. SCREEN _NEWIMAGE(800, 600, 32)
  20. DIM test(10) AS LONG
  21.  
  22. FOR t = 1 TO 10
  23.     test(t) = INITBOX(100 + 250 * RND, 40 * t - 27, "Hi, I'm working on it. This is the test text of the program for longitudinal scrolling in the window. Color capabilities will be added soon. The program uses arrays because program need to remember the shift values for more than one box.", 15 + RND * 40)
  24. Demo = INITBOX(150, 500, "This is small text", 9)
  25.  
  26.  
  27.  
  28.     FOR p = 1 TO 10
  29.         PRINTBOX p
  30.     NEXT
  31.     PRINTBOX Demo
  32.  
  33.     _DISPLAY
  34.  
  35. 'this is future "TextBox.BM"
  36.  
  37. FUNCTION INITBOX (X AS INTEGER, Y AS INTEGER, Text AS STRING, BoxLenght AS INTEGER) 'X, Y are GRAPHIC coordinates
  38.     UTB = UBOUND(tba)
  39.     REDIM _PRESERVE TBA(UTB + 1) AS TB
  40.     TBA(UTB + 1).X = X
  41.     TBA(UTB + 1).Y = Y
  42.     TBA(UTB + 1).L = BoxLenght
  43.     TBA(UTB + 1).T = Text
  44.     TBA(UTB + 1).B = 1
  45.     INITBOX = UTB + 1
  46.  
  47.  
  48. SUB PRINTBOX (nr AS LONG)
  49.     IF nr < 1 OR nr > UBOUND(tba) THEN EXIT SUB 'subscript out of range prevention
  50.     TextBoxArrow& = TBA(0).Arrow
  51.     TextLenght = _PRINTWIDTH(TBA(nr).T)
  52.     B = TBA(nr).B
  53.     TextHeight = _FONTHEIGHT
  54.     X = TBA(nr).X
  55.     Y = TBA(nr).Y
  56.     BoxLenght = TBA(nr).L
  57.     T$ = MID$(TBA(nr).T, TBA(nr).B, TBA(nr).L) 'text loader
  58.  
  59.     FOR h = 1 TO 10
  60.         DO
  61.             MW = _MOUSEWHEEL
  62.             IF MW THEN EXIT DO
  63.         LOOP WHILE _MOUSEINPUT
  64.     NEXT
  65.     '
  66.     MB1 = _MOUSEBUTTON(1)
  67.     MX = _MOUSEX
  68.     MY = _MOUSEY
  69.  
  70.     LINE (X - 30, Y - 3)-(X + 30 + BoxLenght * _FONTWIDTH, Y + 12 + TextHeight), &HFF000000, BF
  71.  
  72.     LINE (X - 30, Y - 3)-(X + 30 + BoxLenght * _FONTWIDTH, Y + 12 + TextHeight), , B
  73.     LINE (X - 28, Y - 1)-(X + 28 + BoxLenght * _FONTWIDTH, Y + 3 + TextHeight), , B
  74.  
  75.  
  76.     LL = ((B + TBA(nr).L) / LEN(TBA(nr).T)) * 100
  77.     Full = BoxLenght * _FONTWIDTH + 15
  78.     OnePercent = Full / 100
  79.     Actual = LL * OnePercent
  80.  
  81.     LINE (X + Actual, Y + TextHeight + 5)-(Actual + 10 + X, Y + 10 + TextHeight), , BF
  82.     IF MX >= X + Actual AND MX <= Actual + 10 + X THEN
  83.         IF MY >= Y + TextHeight + 5 AND MY <= Y + 10 + TextHeight THEN
  84.             IF MB1 THEN
  85.                 omx = MX
  86.                 DO UNTIL _MOUSEX <> MX
  87.                     WHILE _MOUSEINPUT: WEND
  88.                     MB1 = _MOUSEBUTTON(1)
  89.                     B = B + _MOUSEX - omx
  90.                 LOOP
  91.             END IF
  92.         END IF
  93.     END IF
  94.  
  95.  
  96.     _PUTIMAGE (X + 15 + BoxLenght * _FONTWIDTH, Y + 1), TextBoxArrow&
  97.     _PUTIMAGE (X - 15, Y + 1)-(X - 26, Y + 12), TextBoxArrow&
  98.  
  99.     IF TIMER < 1 THEN TBA(nr).D = 0
  100.  
  101.     IF MX >= X + 15 + BoxLenght * _FONTWIDTH AND MX <= X + 15 + BoxLenght * _FONTWIDTH + 12 THEN
  102.         IF MY >= Y + 1 AND MY <= Y + 13 THEN
  103.             IF TBA(nr).D < TIMER THEN
  104.                 LINE (X + 15 + BoxLenght * _FONTWIDTH, Y + 1)-(X + 15 + BoxLenght * _FONTWIDTH + 11, Y + 12), &H44FFFFFF, BF
  105.                 IF MB1 THEN
  106.                     B = B + 1
  107.                 END IF
  108.                 TBA(nr).D = TIMER + .01
  109.             END IF
  110.         END IF
  111.     END IF
  112.  
  113.     IF MX >= X - 26 AND MX <= X - 15 THEN
  114.         IF MY >= Y + 1 AND MY <= Y + 13 THEN
  115.             IF TBA(nr).D < TIMER THEN
  116.                 LINE (X - 26, Y + 1)-(X - 15, Y + 12), &H44FFFFFF, BF
  117.                 IF MB1 THEN
  118.                     B = B - 1
  119.                 END IF
  120.                 TBA(nr).D = TIMER + .01
  121.             END IF
  122.         END IF
  123.     END IF
  124.  
  125.     IF _MOUSEX >= X - 30 AND _MOUSEX <= X + 30 + BoxLenght * _FONTWIDTH THEN
  126.         IF _MOUSEY >= Y - 3 AND _MOUSEY <= Y + 3 + TextHeight THEN
  127.             B = B + MW
  128.             IF _MOUSEINPUT THEN REM
  129.         END IF
  130.     END IF
  131.  
  132.     IF B < 1 THEN B = 1
  133.     IF B > LEN(TBA(nr).T) - TBA(nr).L + 1 THEN B = LEN(TBA(nr).T) - TBA(nr).L + 1
  134.     TBA(nr).B = B
  135.     'here will be add color block (and next sub, which calculate text lenght without color flags and other one, which return text string without color flags)
  136.     'future use: V = INITBOX (1, 1, "&HFFFFFFWhite text is here,&HFFFF0000and red text is here", 10)    --  or can be done as "/RED/ This is RED text /WHITE/ and this is white text" with Steve's color constants.
  137.  
  138.     _PRINTSTRING (X, Y), T$
  139.  
  140.  
  141. FUNCTION PutArrow& 'draw one arrow to virtual screen (so is not need external image)
  142.     PutArrow& = _NEWIMAGE(12, 12, 32)
  143.     D = _DEST
  144.     _DEST PutArrow&
  145.     CLS
  146.     LINE (1, 4)-(6, 4) '  ------------     up
  147.     LINE (1, 8)-(6, 8) '  ------------     down
  148.     LINE (1, 4)-(1, 8) '  I                arrow back
  149.     LINE (6, 4)-(6, 1)
  150.     LINE (6, 8)-(6, 11)
  151.     LINE (6, 11)-(11, 6)
  152.     LINE (6, 1)-(11, 6)
  153.     PAINT (6, 6), &HFF777777, &HFFFFFFFF
  154.     _DEST D
  155. 'End of future "TextBox.BM"
  156.  
Programming isn't difficult, only it's  consuming time and coffee

Offline bplus

  • Global Moderator
  • Forum Resident
  • Posts: 8053
  • b = b + ...
    • View Profile
Re: Scroll Bar
« Reply #44 on: September 22, 2019, 10:21:16 pm »
OK I throw my hat into the ring, colors, arrow keys, home and end, mouse-wheel, click or drag to string position.
Code: QB64: [Select]
  1. _TITLE "hScroller Array test" 'B+ start2019-09-22
  2. SCREEN _NEWIMAGE(800, 600, 32)
  3. _SCREENMOVE 300, 60
  4. TYPE hScroller
  5.     t AS STRING
  6.     x AS SINGLE
  7.     y AS SINGLE
  8.     w AS SINGLE 'in pixels
  9.     'h is constant 20
  10.     start AS INTEGER 'in textstring char
  11.     fC AS _UNSIGNED LONG
  12.     bC AS _UNSIGNED LONG
  13. nHscrollers = 5
  14. DIM SHARED testScroller(1 TO nHscrollers) AS hScroller
  15. S$ = "Here is an extremely long string to test the hSrcoller SUBs, I hope to add separate mouse and key control code either in main loop or in a sub for several kinds of controls not only a hScroll box."
  16. newScroller testScroller(1), S$, 100, 100, 20, &HFFFFFFFF, &HFF0000FF
  17. S$ = "A second long string for scroller #2, we are now testing an array of hScrollers."
  18. newScroller testScroller(2), S$, 300, 100, 10, &HFF99AAFF, &HFFFF0000
  19. S$ = "These scrollers are great! Use the left and right arrow keys to move the text home or end but be sure that the mouse pointer is over the scroller you want to read."
  20. newScroller testScroller(3), S$, 50, 200, 50, &HFF003300, &HFF00FF00
  21. S$ = "The home and end keys also work with these Hscrollers, home of course will take you to start of string and end to the end of course."
  22. newScroller testScroller(4), S$, 150, 300, 30, &HFF000055, &HFF00BBBB
  23. S$ = "The mouse action is the best part or these Hscrollers, the wheel will scroll from one end to the other and back and you cam either click a position in the text string or you can drag to any place of the string."
  24. newScroller testScroller(5), S$, 50, 400, 70, &HFF00FF55, &HFF330033
  25.  
  26. WHILE _KEYDOWN(27) = 0
  27.     CLS
  28.     FOR i = 1 TO nHscrollers
  29.         drawHScroller testScroller(i)
  30.     NEXT
  31.         mx = _MOUSEX: my = _MOUSEY
  32.         FOR i = 1 TO nHscrollers
  33.             maxStart = (LEN(testScroller(i).t) - (testScroller(i).w - 6) / 8) + 1
  34.             IF mx >= testScroller(i).x AND mx <= testScroller(i).x + testScroller(i).w THEN
  35.                 IF my >= testScroller(i).y - 10 AND my <= testScroller(i).y + 20 + 10 THEN
  36.                     mw = _MOUSEWHEEL: mb = _MOUSEBUTTON(1)
  37.                     IF testScroller(i).start + mw >= 1 AND testScroller(i).start + mw <= maxStart THEN
  38.                         testScroller(i).start = testScroller(i).start + mw
  39.                     END IF
  40.                     WHILE mb AND _MOUSEINPUT
  41.                         mx = _MOUSEX: my = _MOUSEY: mb = _MOUSEBUTTON(1)
  42.                         test = ((mx - testScroller(i).x) / testScroller(i).w)
  43.                         IF test >= 0 AND test <= 1 THEN
  44.                             testScroller(i).start = INT(test * maxStart)
  45.                         END IF
  46.                     WEND
  47.                 END IF
  48.             END IF
  49.         NEXT
  50.     WEND
  51.     kh& = _KEYHIT
  52.     IF kh& THEN
  53.         FOR i = 1 TO nHscrollers
  54.             maxStart = (LEN(testScroller(i).t) - (testScroller(i).w - 6) / 8) + 1
  55.             IF mx >= testScroller(i).x AND mx <= testScroller(i).x + testScroller(i).w THEN
  56.                 IF my >= testScroller(i).y - 10 AND my <= testScroller(i).y + 20 + 10 THEN
  57.                     SELECT CASE kh&
  58.                         CASE 19200: IF testScroller(i).start > 1 THEN testScroller(i).start = testScroller(i).start - 1
  59.                         CASE 19712: IF testScroller(i).start < maxStart THEN testScroller(i).start = testScroller(i).start + 1
  60.                         CASE 18176: testScroller(i).start = 1
  61.                         CASE 20224: testScroller(i).start = maxStart
  62.                     END SELECT
  63.                 END IF
  64.             END IF
  65.         NEXT
  66.     END IF
  67.     _DISPLAY
  68.     _LIMIT 100
  69. LOCATE 1, 1: PRINT "Done"
  70.  
  71. 'get stuff loaded into scoller variable for drawing, then for key and mouse control
  72. SUB newScroller (sharedHScroller AS hScroller, txt$, xPix, yPix, wChars, fore AS _UNSIGNED LONG, back AS _UNSIGNED LONG) 'start will be 1
  73.     sharedHScroller.t = txt$
  74.     sharedHScroller.x = xPix
  75.     sharedHScroller.y = yPix
  76.     sharedHScroller.w = wChars * 8 + 6
  77.     sharedHScroller.start = 1
  78.     sharedHScroller.fC = fore
  79.     sharedHScroller.bC = back
  80.  
  81. SUB drawHScroller (sharedHscroller AS hScroller)
  82.     dx = sharedHscroller.w * sharedHscroller.start / (LEN(sharedHscroller.t) - (sharedHscroller.w - 6) / 8 + 1)
  83.     FOR i = 5 TO 0 STEP -.25
  84.         LINE (sharedHscroller.x + dx - i, sharedHscroller.y - 2 * i)-STEP(2 * i, 20 + 4 * i), _RGB32(255 - i * 50, 255 - i * 50, 255 - i * 50), BF
  85.     NEXT
  86.     LINE (sharedHscroller.x, sharedHscroller.y)-STEP(sharedHscroller.w, 20), sharedHscroller.fC, B
  87.     LINE (sharedHscroller.x + 1, sharedHscroller.y + 1)-STEP(sharedHscroller.w - 2, 18), sharedHscroller.bC, BF
  88.     saveColorF = _DEFAULTCOLOR
  89.     saveColorB = _BACKGROUNDCOLOR
  90.     COLOR sharedHscroller.fC, sharedHscroller.bC
  91.     _PRINTSTRING (sharedHscroller.x + 4, sharedHscroller.y + 3), MID$(sharedHscroller.t, sharedHscroller.start, (sharedHscroller.w - 6) / 8)
  92.     COLOR saveColorF, saveColorB
  93.