|
Post by donjohn24 on Nov 1, 2022 13:15:36 GMT
OK checked out DAT and bas code file looks like a huge effort went into putting this code together! When I see pages and pages of code like this (see attached), I wonder if arrays might be used. We did have a discussion on using Control array variables, kind of tricky when and when not to add the # as I recall. But me thinks you code effort might have been greatly eased by use of array like variables. BTW looking at DAT file had me scratching my head when every Round was same as Team? Maybe just some test code... Despite my earlier reply, your comments re-opened my thinking on this, and I may have found a way to to cut down on a lot of the repetitive code, but I've not got a complete solution. My code for the displaying of the Quiz scores is attached - with the output just for the first three teams at the moment. It does work OK in terms of getting the data to the screen, but the problem I have is with the formatting, as shown in the attached screen capture. Although I am employing b$ = using("###", rdscor(i,j)) the screen space taken up by single and two digit numbers is smaller than that for three digits so the formatting into columns is erratic. It may be to do with the use of strings rather than print instructions, and the screen space taken up by 'space' characters rather than those from the display font but despite trying some solutions involving adjusting the length of b$ according to the value of the score, I can't find a solution. Ay ideas would be welcomed - perhaps xxgeek would like enjoy the torture and frustration of reading code and experimenting with this! I've attached the test data file Attachments:
adispscr.bas (2.44 KB)
QUIZ.DAT (1.15 KB)
|
|
|
Post by tsh73 on Nov 1, 2022 13:39:38 GMT
If you want for digits to align propetly in PRINT/LPRINT, you have to use monospaced font
Consolas, Courier, Courier New, Lucida Console, Cascadia Code/Cascadia Mono Check what you have. (I seem not to have last two)
|
|
|
Post by plus on Nov 1, 2022 14:39:27 GMT
"Ay ideas would be welcomed"
Dr Alignment has prescribed JustRight$ for filling a space wide column = spacePad with a Right Justified item any$
' demo JustRight$ for row = 1 to 20 for col = 1 to 16 rrnd = int(rnd(0)*4)+ 1 b$ = "" if rrnd = 0 then end for i = 1 to rrnd b$ = b$+mid$("0123456789",int(rnd(0)*10)+1, 1) next locate (col-1)*5 + 1, row print JustRight$(b$, 5); next print next
' remember to str$(numbers) for any$, spacepad = space to fill with any$ function JustRight$(any$, spacePad) JustRight$ = right$(space$(spacePad) + any$, spacePad) end function
sample output for demo:
5374 8559 02 2921 222 4401 273 2292 2522 185 2562 62 34 9 6 2 1136 6 89 60 97 39 03 9 2316 72 18 89 257 4489 477 4588 17 7488 8131 1 59 9 674 1 84 02 8 779 3 2559 184 400 832 4 09 04 3 0582 802 26 06 8 68 214 3 6672 11 49 91 48 4 7280 2 8063 53 307 5609 5527 7931 248 4 955 7275 105 440 7 249 9502 3219 84 20 8486 9755 4821 0 4 790 93 104 1 1616 267 3844 9627 2 9 6 031 8492 7 78 4 0 0244 5 164 9474 73 522 7 3 19 5459 21 1973 94 0161 2 40 9 7 536 306 961 75 14 8 6 691 4412 2 733 8 9240 94 77 760 343 6 5978 2184 263 4447 1 241 3 0 80 001 23 311 3 3131 26 4604 9 914 9392 9 163 5145 176 87 33 3 54 4868 9 34 58 39 0 0051 9 1 4060 8 764 810 923 88 1 518 801 40 2782 6408 2938 915 05 78 45 957 1 16 4384 75 7 0 6 844 7 45 7395 19 04 800 3853 560 15 4266 585 3 1 6 92 5 9 59 485 7 8165 9632 680 19 8 2328 39 685 6830 14 3 3 66 6673 539 3833 162 64 0 482 1 381 9729 1 641 987 8 564 613 2 849 431 2 44 86 9148 4423 0383 2 38 2113 9 7403 718 69 454 2 68 76 83 11 573 6 5024 4 2 1849 713 32 77 3 9 69 1510 240 5468 04 6 6230 86 4 7 4983 1211 3 7 5930 5653 156 5904 68 6239 19 4 31 7 7312 437 435 1 4944 2 7410
|
|
|
Post by donjohn24 on Nov 1, 2022 15:01:34 GMT
If you want for digits to align propetly in PRINT/LPRINT, you have to use monospaced font Consolas, Courier, Courier New, Lucida Console, Cascadia Code/Cascadia Mono Check what you have. (I seem not to have last two) Now I knew that! But I think the reason - in my RACENITE program - that I went for the other - cumbersome - way of getting number columns aligned was because I wanted to use Arial Black, which is NOT monospaced, but shows up particularly well when used on an overhead display so people further from the screen can still read it. Thus I followed the same method in QUIZ, despite the repetitive and boring code entry. Certainly, I've swapped to Courier 10 Bold and, after adjustments, I get a beautifully formatted display, but perhaps not so easily read from a distance. I'll now have a look at plus's suggestion regarding Dr Alignment and see how that pans out. Attachments:
|
|
|
Post by plus on Nov 1, 2022 15:36:40 GMT
Yeah font that ignores spaces is not going to work for pretty colomns but even with a well spaced font people like right justified columns of numbers.
|
|
|
Post by xxgeek on Nov 1, 2022 16:17:23 GMT
You have a couple of the best (who showed me the way) helping right now. I see no need to jump in. And I was up all night reading jbsearch code. Problem was cundo's code reads only the files that appear in the list of a 2 pane html file menu.
I've adjusted the code to read ALL files in the help folder instead. Still working on it. Gotta make sure my edits don't mess anything else up before posting it.Tricky code to deal with. Very little documentation, and variable names didn't help, - getting there slowly but surely PrinterFont$ now appears in the search list using pri, print, printer, lprint etc. as keywords. Now on to code the "selection" click to covert a list name to the file it represents so the user can read it.
We better not clutter this thread up any further though, best to keep to the subject being discussed.
|
|
|
Post by donjohn24 on Nov 1, 2022 16:35:46 GMT
Yeah font that ignores spaces is not going to work for pretty colomns but even with a well spaced font people like right justified columns of numbers. I'm not sure if your remark means I have to use a monospaced font, but trying to adapt your sample using JustRight$ - as below. I get a compile error on a$ = a$ + JustRight$(b$, 5); and when that was adjusted I got one on the function itself at function JustRight$(any$, spacePad)I obviously haven't got it anything like correct, and my brain is starting to hurt! and I don't understand ' remember to str$(numbers) for any$, spacepad = space to fill with any$
a$ = "" i = 1 b$ = "" for j = 1 to 16 for b = 1 to 3 b$ = b$+mid$("0123456789", rdscor(i,j), 1) next b a$ = a$ + JustRight$(b$, 5); print #bdscr.tb1, a$ i = 2 b$ = "" for j = 1 to 16 for b = 1 to 3 b$ = b$+mid$("0123456789", rdscor(i,j), 1) next b a$ = a$ + JustRight$(b$, 5); print #bdscr.tb2, a$ i=3 b$ = "" for j = 1 to 16 for b = 1 to 3 b$ = b$+mid$("0123456789", rdscor(i,j), 1) next b a$ = a$ + JustRight$(b$, 5) print #bdscr.tb3, a$ wait [bdscrexit] close #bdscr goto [start] ' remember to str$(numbers) for any$, spacepad = space to fill with any$ function JustRight$(any$, spacePad) JustRight$ = right$(space$(spacePad) + any$, spacePad) end function
|
|
|
Post by plus on Nov 1, 2022 17:07:38 GMT
Might be over thinking a little
str$(number) means convert a number into a string$ so we can use string tools like Mid$, Instr, Right$....
Here is an example using an array called score(r, team), I might have team and round backwards from what you intend
dim score(16, 16), st(16*16,1) ' list score, team for team = 1 to 16 ' teams down the left side for r = 1 to 16 ' rounds across the screen score(r, team) = int(rnd(0)* 10000) ' integers 0 to 9999
'overview of scores columns by team rows print JustRight$( str$(score(r, team)), 5); ' <<<<< this prints out 5 chars every time! so always use same amount of chars across the row
stIndex = stIndex + 1 ' list of scores and teams st(stIndex, 0) = score(r, team) ' leftover code from old sort demo and next line st(stIndex, 1) = team next print ' <<<<<<<<<<<<<<<<< you need this to finish off the Print row and do a carriage return next
' remember to str$(numbers) for any$, spacepad = space to fill with any$ function JustRight$(any$, spacePad) JustRight$ = right$(space$(spacePad) + any$, spacePad) end function
But I think there is a way to do this with a bad or funky font!!!
Man I was going to take my power nap about now, but this is cool way to overcome font problem, maybe... stay tuned!
|
|
|
Post by plus on Nov 1, 2022 17:34:54 GMT
Nope won't do it by locating each individual letter! Apparently JB keeps track of dang pixel just where to locate the next character??? Makes me wonder what it does if start printing different sets of characters over same area, just leave a mess I guess. I know I can do it in a graphics Window. Nap time ;-)) BTW donjohn24 all I wanted to pass to you was the JustRight$() Function. All that code above it was for generating data to have something to print using the JustRight$ function.
|
|
|
Post by donjohn24 on Nov 1, 2022 18:04:59 GMT
Nope won't do it by locating each individual letter! Apparently JB keeps track of dang pixel just where to locate the next character??? Makes me wonder what it does if start printing different sets of characters over same area, just leave a mess I guess. I know I can do it in a graphics Window. Nap time ;-)) BTW donjohn24 all I wanted to pass to you was the JustRight$() Function. All that code above it was for generating data to have something to print using the JustRight$ function. Well, I found a heavy monospaced font - SicretMonoPersonal-Bold 15, which does the job well, so no probably no need for the JustRight$ function but thank you for your help and interest. You enabled me to replace 633 code lines with 166! I initially thought that the top code was as you described but than began to overthink - I guess I need a break! Attachments:
|
|
|
Post by tsh73 on Nov 1, 2022 18:54:35 GMT
With the graphicbox / graphic window, one could position text pixel-perfect And since JB now has STRINGWIDTH - here's the code that draws similar thing with Arial Black (btw it selects font size to fit actual WindowWidth, just try for example WindowWidth = DisplayWidth*3/4 ) nomainwin
UpperLeftX = 1 UpperLeftY = 1 WindowWidth = DisplayWidth WindowHeight = 350
global AlignLeft, AlignCenter, AlignRight AlignLeft=0: AlignCenter=1: AlignRight=2
open "simulated scores in the graphicbox" for graphics_nsb_nf as #gr #gr "trapclose [quit]" #gr "home; posxy cx cy" #gr "down; fill cyan; flush"
print cx
'16 cols +1+2 '=19 'approx 5 chars per column cw=int(2*cx/19/5) 'char width 'cwI=int(cw) 'fit the font to cw pixels width for i = 8 to 40 #gr "font Arial_black ";i if stringWidth("01234567890") > 10*cw then exit for next cwI=i-1 #gr "font Arial_black ";cwI 'actually says 20 for my 1920x1080 'call printAt cx, 50, "Hello", AlignLeft 'call printAt cx, 100, "Hello", AlignCenter 'call printAt cx, 150, "Hello", AlignRight
#gr "place 0 0" #gr "\" #gr "posxy dummy ch" 'char (or line) height
title$=space$(20)+"*** ROUND SCORES ***"+space$(20) #gr "backcolor yellow" call printAt cx, 1*ch, title$, AlignCenter
#gr "backcolor cyan" 'header for i = 0 to 18 if (i = 0) or (i = 18) then s$="Tm" else if i = 17 then s$="TOT" else s$=str$(i) end if end if call printAt cw*(i+1)*5, 2*ch, s$, AlignRight '+1 for having place to step left next
'simulated data
for k = 1 to 3 'lines sum=0 for i = 0 to 18 if (i = 0) or (i = 18) then s$=str$(k) else if i = 17 then s$=str$(sum) else r=int(rnd(0)*300)+1 sum=sum+r s$=str$(r) end if end if call printAt cw*(i+1)*5, (2.5+k)*ch, s$, AlignRight '+1 for having place to step left next next
'#gr "place ";20;" ";7*ch '#gr "\";"0000000000000000" 'this just show that digots has same width '#gr "\";"1111111111111111"
#gr "flush" wait
[quit] close #gr end
function stringWidth(s$) #gr "stringwidth? s$ w" stringWidth = w end function
sub printAt x, y, s$, align w=stringWidth(s$) select case align case AlignLeft #gr "place ";x;" ";y case AlignCenter #gr "place ";x-w/2;" ";y case AlignRight #gr "place ";x-w;" ";y end select #gr "\";s$ end sub
|
|
|
Post by donjohn24 on Nov 1, 2022 19:19:28 GMT
With the graphicbox / graphic window, one could position text pixel-perfect And since JB now has STRINGWIDTH - here's the code that draws similar thing with Arial Black (btw it selects font size to fit actual WindowWidth, just try for example WindowWidth = DisplayWidth*3/4 ) nomainwin
UpperLeftX = 1 UpperLeftY = 1 WindowWidth = DisplayWidth WindowHeight = 350
global AlignLeft, AlignCenter, AlignRight AlignLeft=0: AlignCenter=1: AlignRight=2
open "simulated scores in the graphicbox" for graphics_nsb_nf as #gr #gr "trapclose [quit]" #gr "home; posxy cx cy" #gr "down; fill cyan; flush"
print cx
'16 cols +1+2 '=19 'approx 5 chars per column cw=int(2*cx/19/5) 'char width 'cwI=int(cw) 'fit the font to cw pixels width for i = 8 to 40 #gr "font Arial_black ";i if stringWidth("01234567890") > 10*cw then exit for next cwI=i-1 #gr "font Arial_black ";cwI 'actually says 20 for my 1920x1080 'call printAt cx, 50, "Hello", AlignLeft 'call printAt cx, 100, "Hello", AlignCenter 'call printAt cx, 150, "Hello", AlignRight
#gr "place 0 0" #gr "\" #gr "posxy dummy ch" 'char (or line) height
title$=space$(20)+"*** ROUND SCORES ***"+space$(20) #gr "backcolor yellow" call printAt cx, 1*ch, title$, AlignCenter
#gr "backcolor cyan" 'header for i = 0 to 18 if (i = 0) or (i = 18) then s$="Tm" else if i = 17 then s$="TOT" else s$=str$(i) end if end if call printAt cw*(i+1)*5, 2*ch, s$, AlignRight '+1 for having place to step left next
'simulated data
for k = 1 to 3 'lines sum=0 for i = 0 to 18 if (i = 0) or (i = 18) then s$=str$(k) else if i = 17 then s$=str$(sum) else r=int(rnd(0)*300)+1 sum=sum+r s$=str$(r) end if end if call printAt cw*(i+1)*5, (2.5+k)*ch, s$, AlignRight '+1 for having place to step left next next
'#gr "place ";20;" ";7*ch '#gr "\";"0000000000000000" 'this just show that digots has same width '#gr "\";"1111111111111111"
#gr "flush" wait
[quit] close #gr end
function stringWidth(s$) #gr "stringwidth? s$ w" stringWidth = w end function
sub printAt x, y, s$, align w=stringWidth(s$) select case align case AlignLeft #gr "place ";x;" ";y case AlignCenter #gr "place ";x-w/2;" ";y case AlignRight #gr "place ";x-w;" ";y end select #gr "\";s$ end sub
Neat - I've not played with graphic boxes/windows - which looks pretty good. Having been working on this QUIZ program for quite a few days, and finally got something that does the trick OK I may call a halt now, and come back to try your code a bit later as my wife is beginning to wonder if I will ever leave my PC for a moment and talk to her again. Thanks to everyone here who helped or commented, I wish people like you JB experts had been available in my early days of programming.
|
|
|
Post by plus on Nov 1, 2022 22:11:10 GMT
donjohn24 your screen shot looks great! so is tsh73 of course ;-)) (I knew graphics screen is easier to manipulate.) Your columns are right aligned JustRight! how did you do yours? tsh73 thanks I did not know about StringWidth, good demo!
|
|
|
Post by donjohn24 on Nov 1, 2022 22:55:04 GMT
donjohn24 your screen shot looks great! so is tsh73 of course ;-)) (I knew graphics screen is easier to manipulate.) Your columns are right aligned JustRight! how did you do yours? tsh73 thanks I did not know about StringWidth, good demo! I just used SicretMonoPersonal Bold 15 - a monospaced font after tsh73 reminded me that a monospaced type would be needed for simple formatting. I searched for monospaced fonts, using images, and downloaded this one which is good for reading on a overhead projection screen, like Arial Black. and installed it on my PC. HOWEVER! This font will NOT display on a PC which does not have it installed already.Is there a way to build it into the program .exe/.tkn file so that it is already present ? If not, do I have to find a way of automatically (?) installing the font from a distribution .zip file, or include instructions for a user to do so? . . . . . so many questions . . . .
|
|