QB64.org Forum

Active Forums => QB64 Discussion => Topic started by: lawsonm1 on February 19, 2020, 12:27:48 pm

Title: Wiki - Template:Parameter?
Post by: lawsonm1 on February 19, 2020, 12:27:48 pm
Ummm, did something change? There are all of these 'Template:Parameter' links that do not seem to go anywhere. And the code examples have 'Template:Cl' all throughout. Bizarre.
Title: Re: Wiki - Template:Parameter?
Post by: FellippeHeitor on February 19, 2020, 12:51:31 pm
In the process of upgrading the wiki software. Issues galore until everything’s sorted.
Title: Re: Wiki - Template:Parameter?
Post by: lawsonm1 on February 19, 2020, 02:06:58 pm
Okay. Sure wish I had that hard copy QB64 book! I guess in the meantime I can use my trusty 'GW-BASIC Reference' book from 1990. On a serious note, I had been thinking of capturing the various webpages, put them in a document, and printing them out. I think I will do that when the issues get sorted out. Thanks, Mike
Title: Re: Wiki - Template:Parameter?
Post by: FellippeHeitor on February 19, 2020, 02:43:38 pm
Your offline copy of the wiki is still available in the IDE, just hit Shift+F1.
Title: Re: Wiki - Template:Parameter?
Post by: lawsonm1 on February 19, 2020, 03:34:51 pm
Yeah, I know. I'm just old and kinda set in my ways I guess. If I come across a programming problem, I find myself grabbing a related book and digging through it for an answer or suggestion, and then go back to see if it works. I will say this, I do LOVE QB64 though. And I'm slowly getting out of my BASIC 'shell' and using some of the '_' commands more. Or even looking at those for suggestions. Some of them seem a bit daunting though. But hey, type in the command and see if it spits an error! It certainly isn't going to destroy the computer!. Thanks again, to you and all of whoever works on this language, and the site, Mike
Title: Re: Wiki - Template:Parameter?
Post by: OldMoses on February 19, 2020, 05:37:48 pm
Okay. Sure wish I had that hard copy QB64 book!

That would be an awesome thing. For all the stuff I do on computer, even reading books, I still like a hardcopy book for things of this nature.
Title: Re: Wiki - Template:Parameter?
Post by: TerryRitchie on February 19, 2020, 07:48:20 pm
That would be an awesome thing. For all the stuff I do on computer, even reading books, I still like a hardcopy book for things of this nature.

The Waite Group put out a book called "The Microsoft QuickBasic Bible" in the early 90's. I still use that book to this day as it is so well written and informative. I would be the first in line to purchase "The QuickBasic64 Bible" if it were offered in the same format.

It's still available used on Amazon:

https://www.amazon.com/Waite-Groups-Microsoft-QuickBASIC-Bible/dp/1556152620/ref=sr_1_1?keywords=1556152620&qid=1582159654&sr=8-1

Title: Re: Wiki - Template:Parameter?
Post by: youreperfect on February 19, 2020, 09:42:09 pm
There are a couple books listed here: https://kit.co/YourePerfect/qbasic-programming
Ordering them via the links on that page also helps donate to the QB64 project.
Title: Re: Wiki - Template:Parameter?
Post by: bplus on February 19, 2020, 10:13:51 pm
  [ This attachment cannot be displayed inline in 'Print Page' view ]  

Hey that's a link to Terry's tutorial.

Hey youreperfect where are you from?
Title: Re: Wiki - Template:Parameter?
Post by: bplus on February 20, 2020, 12:58:32 am
Speaking of templates, I remember QB something had a Format$ statement that I have missed on occasion.

Has someone worked on that? perfect compliment to PRINT USING.
Title: Re: Wiki - Template:Parameter?
Post by: RhoSigma on February 20, 2020, 01:38:11 am
Hi b+,

are you speaking about something like this? https://www.qb64.org/forum/index.php?topic=890.msg100880#msg100880
Title: Re: Wiki - Template:Parameter?
Post by: bplus on February 20, 2020, 01:49:43 am
Hey Rho,

Do you know I was thinking it might be you, I even started to type in your name... couldn't remember why though.

I will check it out after sleeping off all this dang coffee I drank. Thank you!
Title: Re: Wiki - Template:Parameter?
Post by: bplus on February 21, 2020, 02:49:18 pm
OK I am checking out both Steve's and RhoSigma's Format functions and the % is showing up in the output for 2nd demo example:
Code: QB64: [Select]
  1. PRINT Format1$("###,.##", "123456789.987654321", 1)
  2.  

Wiki says when see a % in output then the template isn't adding enough # places for numbers but doesn't this part of template, "###,." kind of write a blank check for amount of numbers places?

ref: Format functions
Code: QB64: [Select]
  1. ' Fellippe's link to wiki for PRINT USING table http://www.qb64.org/wiki/PRINT_USING
  2. ' Steve McNeill formats$   https://www.qb64.org/forum/index.php?topic=890.msg100887#msg100887
  3. PRINT Format1$("###.###", "123.456789", 1)
  4. PRINT Format1$("###,.##", "123456789.987654321", 1)
  5.  
  6.  
  7. FUNCTION format$ (template AS STRING, text AS STRING)
  8.     d = _DEST: s = _SOURCE
  9.     n = _NEWIMAGE(80, 80, 0)
  10.     _DEST n: _SOURCE n
  11.     PRINT USING template; VAL(text)
  12.     FOR i = 1 TO 79
  13.         t$ = t$ + CHR$(SCREEN(1, i))
  14.     NEXT
  15.     format$ = t$
  16.     _DEST d: _SOURCE s
  17.     _FREEIMAGE n
  18.  
  19.  
  20.  
  21. ' RhoSigma's format$  https://www.qb64.org/forum/index.php?topic=890.msg100880#msg100880
  22. '---------------------------------------------------------------------
  23. 'Function:  Can return a PRINT USING formatted string for assignment to
  24. '           any string variable. This is a multiple name function for
  25. '           use of upto three arguments (Format$, Format2$, Format3$).
  26. '
  27. 'Synopsis:  res$ = Format$  (fmt$, arg$, typ%)
  28. '           res$ = Format2$ (fmt$, arg$, typ%, arg2$, typ2%)
  29. '           res$ = Format3$ (fmt$, arg$, typ%, arg2$, typ2% arg3$, typ3%)
  30. '
  31. 'Result:    res$ --> the resulting formatted string
  32. '
  33. 'Inputs:    fmt$ --> the string with format options for PRINT USING
  34. '           arg$ --> the argument(s) to format into the fmt$ string,
  35. '                    use STR$(num) to pass in a number
  36. '           typ% --> the type(s) of the respective argument(s),
  37. '                     0 = argument is a real (alphanumeric) string
  38. '                     1 = argument is a STR$() number string
  39. '
  40. 'Notes:     This function is adapted and slightly altered from an idea
  41. '           posted in the QB64 Forum by Fellippe Heitor,
  42. '           see http://www.[abandoned, outdated and now likely malicious qb64 dot net website - don’t go there]/forum/index.php?topic=14219.0
  43. '---------------------------------------------------------------------
  44. FUNCTION Format1$ (fmt$, arg$, typ%)
  45.     shan& = _SOURCE: dhan& = _DEST: than& = _NEWIMAGE(256, 1, 0) 'if results may get longer, then raise the 256 value
  46.     _SOURCE than&: _DEST than&
  47.     IF typ% THEN
  48.         PRINT USING fmt$; VAL(arg$);
  49.     ELSE
  50.         PRINT USING fmt$; arg$;
  51.     END IF
  52.     FOR i% = 1 TO POS(0) - 1
  53.         res$ = res$ + CHR$(SCREEN(1, i%))
  54.     NEXT i%
  55.     _SOURCE shan&: _DEST dhan&: _FREEIMAGE than&
  56.     Format1$ = res$
  57. '-----
  58. FUNCTION Format2$ (fmt$, arg$, typ%, arg2$, typ2%)
  59.     shan& = _SOURCE: dhan& = _DEST: than& = _NEWIMAGE(256, 1, 0) 'if results may get longer, then raise the 256 value
  60.     _SOURCE than&: _DEST than&
  61.     IF typ% AND typ2% THEN
  62.         PRINT USING fmt$; VAL(arg$); VAL(arg2$);
  63.     ELSEIF typ% THEN
  64.         PRINT USING fmt$; VAL(arg$); arg2$;
  65.     ELSEIF typ2% THEN
  66.         PRINT USING fmt$; arg$; VAL(arg2$);
  67.     ELSE
  68.         PRINT USING fmt$; arg$; arg2$;
  69.     END IF
  70.     FOR i% = 1 TO POS(0) - 1
  71.         res$ = res$ + CHR$(SCREEN(1, i%))
  72.     NEXT i%
  73.     _SOURCE shan&: _DEST dhan&: _FREEIMAGE than&
  74.     Format2$ = res$
  75. '-----
  76. FUNCTION Format3$ (fmt$, arg$, typ%, arg2$, typ2%, arg3$, typ3%)
  77.     shan& = _SOURCE: dhan& = _DEST: than& = _NEWIMAGE(256, 1, 0) 'if results may get longer, then raise the 256 value
  78.     _SOURCE than&: _DEST than&
  79.     IF typ% AND typ2% AND typ3% THEN
  80.         PRINT USING fmt$; VAL(arg$); VAL(arg2$); VAL(arg3$);
  81.     ELSEIF typ% AND typ2% THEN
  82.         PRINT USING fmt$; VAL(arg$); VAL(arg2$); arg3$;
  83.     ELSEIF typ% AND typ3% THEN
  84.         PRINT USING fmt$; VAL(arg$); arg2$; VAL(arg3$);
  85.     ELSEIF typ2% AND typ3% THEN
  86.         PRINT USING fmt$; arg$; VAL(arg2$); VAL(arg3$);
  87.     ELSEIF typ% THEN
  88.         PRINT USING fmt$; VAL(arg$); arg2$; arg3$;
  89.     ELSEIF typ2% THEN
  90.         PRINT USING fmt$; arg$; VAL(arg2$); arg3$;
  91.     ELSEIF typ3% THEN
  92.         PRINT USING fmt$; arg$; arg2$; VAL(arg3$);
  93.     ELSE
  94.         PRINT USING fmt$; arg$; arg2$; arg3$;
  95.     END IF
  96.     FOR i% = 1 TO POS(0) - 1
  97.         res$ = res$ + CHR$(SCREEN(1, i%))
  98.     NEXT i%
  99.     _SOURCE shan&: _DEST dhan&: _FREEIMAGE than&
  100.     Format3$ = res$
  101.  
  102.  
Title: Re: Wiki - Template:Parameter?
Post by: FellippeHeitor on February 21, 2020, 03:06:03 pm
Wiki says when see a % in output then the template isn't adding enough # places for numbers but doesn't this part of template, "###,." kind of write a blank check for amount of numbers places?

Up to three digits. If you make it ####, then it's up to four digits. If I pass 1000 to your format string, with only ### before the ".", then you'll see %1000, to show you you didn't prepare well enough for your program's results.
Title: Re: Wiki - Template:Parameter?
Post by: bplus on February 21, 2020, 03:10:32 pm
Code: QB64: [Select]
  1. PRINT Format1$("############,.##", "123456789.987654321", 1)  

OK and you need places for commas too! :)

But it does count a place for the one comma in template ( 9 numbers + 2 commas = 11, but 10 #'s does it):
Code: QB64: [Select]
  1. PRINT Format1$(STRING$(10, "#") + ",.##", "123456789.987654321", 1)