Author Topic: QB64 NOT RELIABLE FOR LARRY  (Read 6384 times)

0 Members and 1 Guest are viewing this topic.

Offline RhoSigma

  • QB64 Developer
  • Forum Resident
  • Posts: 565
    • View Profile
Re: QB64 NOT RELIABLE FOR LARRY
« Reply #15 on: October 26, 2020, 07:37:06 pm »
Sometimes it's just funny how people get wrong even the simpliest hints. Of course the ## have to be in quotes just like you did the # in quotes in your first example ;-)

And just to mention, if your numbers get bigger you may need 3,4,5 of the #. Each # represents 1 digit of a number.
« Last Edit: October 26, 2020, 08:02:13 pm by RhoSigma »
My Projects:   https://qb64forum.alephc.xyz/index.php?topic=809
GuiTools - A graphic UI framework (can do multiple UI forms/windows in one program)
Libraries - ImageProcess, StringBuffers (virt. files), MD5/SHA2-Hash, LZW etc.
Bonus - Blankers, QB64/Notepad++ setup pack

Offline SMcNeill

  • QB64 Developer
  • Forum Resident
  • Posts: 3972
    • View Profile
    • Steve’s QB64 Archive Forum
Re: QB64 NOT RELIABLE FOR LARRY
« Reply #16 on: October 26, 2020, 07:50:15 pm »
You forgot your quotes.

PRINT USING “##”; a ^ 2
https://github.com/SteveMcNeill/Steve64 — A github collection of all things Steve!

Offline Kernelpanic

  • Newbie
  • Posts: 94
    • View Profile
Re: QB64 NOT RELIABLE FOR LARRY
« Reply #17 on: October 26, 2020, 08:48:04 pm »
You forgot your quotes.

PRINT USING “##”; a ^ 2
No! That is not the problem. I think not.

Mark Twain
"Als wir das Ziel endgültig aus den Augen verloren hatten, verdoppelten wir unsere Anstrengungen."
„Having lost sight of our goals, we redoubled our efforts.“

Offline doppler

  • Forum Regular
  • Posts: 241
    • View Profile
The troll larry made one post and got a response.


Offline SMcNeill

  • QB64 Developer
  • Forum Resident
  • Posts: 3972
    • View Profile
    • Steve’s QB64 Archive Forum
Re: QB64 NOT RELIABLE FOR LARRY
« Reply #19 on: October 26, 2020, 10:35:39 pm »
No! That is not the problem. I think not.

Two points here:

POINT 1) You have to use enough ###### symbols to represent a placeholder for your result.

USING “#” reserves 1 digit.
USING “##” reserves 2 digits.
USING “###” reserves 3 digits.

POINT 2) The negative sign counts as 1 digit.

1 is 1 digit.
-1 is 2 digits.
12 is 2 digits
-12 is 3 digits.

If the number you are trying to display has more digits that you reserved, the % symbol will print in front, representing, “The programmer who wrote this was an idiot and didn’t reserve proper space for formatting.  Tell them to fix it!”

Reserve enough digits and you’ll never see that error symbol again.
https://github.com/SteveMcNeill/Steve64 — A github collection of all things Steve!

Offline Petr

  • Forum Resident
  • Posts: 1720
  • The best code is the DNA of the hops.
    • View Profile
Re: QB64 NOT RELIABLE FOR LARRY
« Reply #20 on: October 27, 2020, 11:56:50 am »
LARRY wrote:

Quote
First, I had problems with a quote left in an alpha field. Next, it was problems with negative numbers.  Some programs were running quite well but failed upon making changes and recompiling.

This version of QB is NOT worth using.  I have never seen such a buggy language.  I have worked as a programmer on main frames for 40+ years.

How much time did you give it? And how many times have you tried to correct mistakes? And what exactly are you talking about? :)
The problem will definitely be between the chair and the keyboard.

Offline bplus

  • Global Moderator
  • Forum Resident
  • Posts: 8053
  • b = b + ...
    • View Profile
Re: QB64 NOT RELIABLE FOR LARRY
« Reply #21 on: October 27, 2020, 12:01:55 pm »
Where? Here not:

Positive numbers are always 1 space more that what you see, check the LEN:
Code: QB64: [Select]
  1. a = -5
  2. PRINT LEN(STR$((a) ^ 2))
  3.  

Opps wrong page! :P already noted on 2nd page.
« Last Edit: October 27, 2020, 07:17:14 pm by bplus »

Offline Kernelpanic

  • Newbie
  • Posts: 94
    • View Profile
Re: QB64 NOT RELIABLE FOR LARRY
« Reply #22 on: October 27, 2020, 07:06:40 pm »
Quote
If the number you are trying to display has more digits that you reserved, the % symbol will print in front, representing, “The programmer who wrote this was an idiot and didn’t reserve proper space for formatting.  Tell them to fix it!”
Well, do it!

I wrote it: No more "###" and so on. I know this! The problem is, the input decides the output. I do not know the input.

PS: Maybe I have an idea, but not now. In Berlin is it 00:05 - Good Night!

Code: QB64: [Select]
  1.  
  2. a = -5
  3. b = 6
  4.  
  5. PRINT USING "##"; a ^ 3
  6.  
  7. PRINT USING "The Number: ####### is wrong!"; b ^ 3
  8. PRINT USING "The Number: ### is wrong!"; b ^ 3
  9.  
  10. INPUT "Enter a number: ", b
  11. PRINT USING "The Number: ####### is wrong!"; b ^ 3
  12. PRINT USING "The Number: ### is wrong!"; b ^ 3
  13.  
  14.  
  15. PRINT (a) ^ 2
  16. PRINT -3 ^ 2
  17. PRINT (-3) ^ 2
  18.  
  19. 'Unexpected character . . .
  20. 'PRINT LEN ( STR $ ( ( a ) ^ 2 ) )
  21.  
  22.  

Mark Twain
"Als wir das Ziel endgültig aus den Augen verloren hatten, verdoppelten wir unsere Anstrengungen."
„Having lost sight of our goals, we redoubled our efforts.“

Offline bplus

  • Global Moderator
  • Forum Resident
  • Posts: 8053
  • b = b + ...
    • View Profile
Re: QB64 NOT RELIABLE FOR LARRY
« Reply #23 on: October 27, 2020, 07:37:12 pm »
Yeah this is crazy but works:
Code: QB64: [Select]
  1. INPUT "Integer please ", a&
  2. s$ = STRING$(LEN(STR$(a&)), "#")
  3. PRINT "The number input was";
  4. IF a& < 0 THEN PRINT " ";
  5. PRINT USING s$ + "."; a&
  6.  

Offline SMcNeill

  • QB64 Developer
  • Forum Resident
  • Posts: 3972
    • View Profile
    • Steve’s QB64 Archive Forum
Re: QB64 NOT RELIABLE FOR LARRY
« Reply #24 on: October 27, 2020, 07:50:00 pm »
Well, do it!

I wrote it: No more "###" and so on. I know this! The problem is, the input decides the output. I do not know the input.

https://www.qb64.org/wiki/Data_types

As a programmer, you're going to know what the maximum value is that an user can input -- you define it with your variable type.

If you use _BYTE for your variable types, you reserve a maximum of 4 spaces (-128 to 127).
If you use INTEGER for your variable types, you reserve a maximum of 6 spaces (-32768 to 32767).
If you use LONG for your variable types, you reserve a maximum of 11 spaces.
If you use _INTEGER64 for your variable types, you reserve a maximum of 20 spaces.

The point of PRINT USING is to create a form which will line up and keep all your data in a nice neat row.  To do that, you have to allocate space for the largest result, and not dynamically adjust your fields on the fly.

If all you want is to do something like bplus has done above, then don't even use PRINT USING at all.  Just print the answer as it exists.

Code: QB64: [Select]
  1. INPUT "Integer please ", a&
  2. PRINT "The number input was"; a&
  3.  



As per your examples above:

Code: [Select]
DIM a AS INTEGER, b AS INTEGER

a = -5
b = 6

PRINT a ^ 3
PRINT

PRINT "The Number:"; b ^ 3; "is right!"
PRINT
PRINT "The Number:"; b ^ 3; "is right!"
PRINT

INPUT "Enter a number: ", b
PRINT "The Number:"; b ^ 3; "is right!"
PRINT
PRINT "The Number:"; b ^ 3; "is right!"
PRINT


PRINT (a) ^ 2
PRINT
PRINT -3 ^ 2
PRINT
PRINT (-3) ^ 2

PRINT
END


 

What's the obsession with USING?  For what it seems you want to do, it's not needed at all.  Just print the dang value to the screen and be done with it.
« Last Edit: October 27, 2020, 07:55:03 pm by SMcNeill »
https://github.com/SteveMcNeill/Steve64 — A github collection of all things Steve!

Offline Kernelpanic

  • Newbie
  • Posts: 94
    • View Profile
Re: QB64 NOT RELIABLE FOR LARRY
« Reply #25 on: October 28, 2020, 01:07:39 pm »
This is my idea for a correct formatting. But there is a problem: with sums of 100,000.00 or more, "%" is prefixed, regardless of whether "#" x 6,7,9, the character does not go away. I do not find the fault.

The 2nd program is only an example, there the formatting works as it should be.

Kredithoehe/Kredit = Loan amount
Rückzahlungsbetrag = Repayment amount

Code: QB64: [Select]
  1.  
  2. DECLARE FUNCTION Rueckzahlung# (Kredit as Double)
  3.  
  4. DIM Kredithoehe AS DOUBLE
  5.  
  6. INPUT "Gewuenschte Kredithoehe eingeben: ", Kredithoehe
  7. SELECT CASE Kredithoehe
  8.   CASE IS <= 999.99
  9.     PRINT USING "Rueckzahlungsbetrag: ####,.## Euro"; Rueckzahlung#(Kredithoehe)
  10.   CASE IS >= 1000.00
  11.     PRINT USING "Rueckzahlungsbetrag: #####,.## Euro"; Rueckzahlung#(Kredithoehe)
  12.   CASE IS >= 10000.00
  13.     PRINT USING "Rueckzahlungsbetrag: ######,.## Euro"; Rueckzahlung#(Kredithoehe)
  14.   CASE IS >= 100000.00
  15.     PRINT USING "Rueckzahlungsbetrag: #######,.## Euro"; Rueckzahlung#(Kredithoehe)
  16.   CASE IS >= 1000000.00
  17.     PRINT USING "Rueckzahlungsbetrag: ########,.## Euro"; Rueckzahlung#(Kredithoehe)
  18.     PRINT: PRINT "Falsche Eingabe!"
  19.  
  20. END '(Hauptprogramm)
  21.  
  22. FUNCTION Rueckzahlung# (Kredit AS DOUBLE)
  23.   Rueckzahlung# = ((Kredit / 10) + Kredit)
  24.  
---
Code: QB64: [Select]
  1.  
  2.  
  3. DIM Sum AS DOUBLE, Sum2 AS DOUBLE
  4.  
  5. Sum = 150000.00
  6.  
  7. INPUT "Summe -Max 6 Stellen- : ", Sum2
  8. PRINT USING "######,.##"; Sum
  9. PRINT USING "Eingabe ist: ######,.##"; Sum2
  10. 'Examole for wrong format
  11. PRINT USING "Falsche Formatierung: ###,.##"; Sum2
  12. PRINT USING "Summe mit Zinsen: ######,.##"; Rueckzahlung(Sum2)
  13.  
  14.  
  15. FUNCTION Rueckzahlung# (Kredit AS DOUBLE)
  16.   Rueckzahlung# = ((Kredit / 10) + Kredit)
  17.  
Mark Twain
"Als wir das Ziel endgültig aus den Augen verloren hatten, verdoppelten wir unsere Anstrengungen."
„Having lost sight of our goals, we redoubled our efforts.“

Offline Cobalt

  • QB64 Developer
  • Forum Resident
  • Posts: 878
  • At 60 I become highly radioactive!
    • View Profile
Re: QB64 NOT RELIABLE FOR LARRY
« Reply #26 on: October 28, 2020, 01:16:43 pm »
lets start a new topic for pertinent stuff and let this idiot topic fall into the seclusion of darkness it deserves.
Granted after becoming radioactive I only have a half-life!

Offline SMcNeill

  • QB64 Developer
  • Forum Resident
  • Posts: 3972
    • View Profile
    • Steve’s QB64 Archive Forum
Re: QB64 NOT RELIABLE FOR LARRY
« Reply #27 on: October 28, 2020, 02:09:32 pm »
Code: QB64: [Select]
  1.  
  2. DECLARE FUNCTION Rueckzahlung# (Kredit AS DOUBLE)
  3.  
  4. DIM Kredithoehe AS DOUBLE
  5.  
  6. INPUT "Gewuenschte Kredithoehe eingeben: ", Kredithoehe
  7. SELECT CASE Kredithoehe
  8.     CASE 0 TO 999.99
  9.         PRINT USING "Rueckzahlungsbetrag: ####,.## Euro"; Rueckzahlung#(Kredithoehe)
  10.     CASE 1000.00 TO 9999.99
  11.         PRINT USING "Rueckzahlungsbetrag: #####,.## Euro"; Rueckzahlung#(Kredithoehe)
  12.     CASE 10000.00 TO 99999.99
  13.         PRINT USING "Rueckzahlungsbetrag: ######,.## Euro"; Rueckzahlung#(Kredithoehe)
  14.     CASE 100000.00 TO 999999.99
  15.         PRINT USING "Rueckzahlungsbetrag: #######,.## Euro"; Rueckzahlung#(Kredithoehe)
  16.     CASE IS >= 1000000.00
  17.         PRINT USING "Rueckzahlungsbetrag: ########,.## Euro"; Rueckzahlung#(Kredithoehe)
  18.     CASE ELSE
  19.         PRINT: PRINT "Falsche Eingabe!"
  20.  
  21. END '(Hauptprogramm)
  22.  
  23. FUNCTION Rueckzahlung# (Kredit AS DOUBLE)
  24.     Rueckzahlung# = ((Kredit / 10) + Kredit)
  25.  
  26.  

The problem with your code, as you presented it, is that 100,000 is also greater than 10,000.  Since the SELECT CASE > 10,000, it gets processed as a 5 digit value, and not a 6 digit one.  Solution is to simply define the ranges, as I've done above, so that the proper SELECT CASE is triggered.

Even simpler:  Just build the string to whatever size you need it.

Code: QB64: [Select]
  1.  
  2. DECLARE FUNCTION Rueckzahlung# (Kredit AS DOUBLE)
  3.  
  4. DIM Kredithoehe AS DOUBLE, length AS INTEGER, use AS STRING
  5.  
  6. INPUT "Gewuenschte Kredithoehe eingeben: ", Kredithoehe
  7.  
  8. length = LEN(STR$(INT(Rueckzahlung#(Kredithoehe)))) 'get the length
  9. use$ = "Rueckzahlungsbetrag: " + STRING$(length, "#") + ",.## Euro" 'use that length to create the proper number of # symbols
  10. PRINT USING use$; Rueckzahlung#(Kredithoehe) 'print using the created string
  11.  
  12. END '(Hauptprogramm)
  13.  
  14. FUNCTION Rueckzahlung# (Kredit AS DOUBLE)
  15.     Rueckzahlung# = ((Kredit / 10) + Kredit)
« Last Edit: October 28, 2020, 02:20:20 pm by SMcNeill »
https://github.com/SteveMcNeill/Steve64 — A github collection of all things Steve!

Offline Kernelpanic

  • Newbie
  • Posts: 94
    • View Profile
Re: QB64 NOT RELIABLE FOR LARRY
« Reply #28 on: October 28, 2020, 03:50:39 pm »
@SMcNeill - That was it! Thank You!

That with "build a string" I still have to look closely.
Mark Twain
"Als wir das Ziel endgültig aus den Augen verloren hatten, verdoppelten wir unsere Anstrengungen."
„Having lost sight of our goals, we redoubled our efforts.“

Offline Kernelpanic

  • Newbie
  • Posts: 94
    • View Profile
Re: QB64 NOT RELIABLE FOR LARRY
« Reply #29 on: October 28, 2020, 05:08:17 pm »
Ok, the String variant is better. More practicable, really. Thanks!
Mark Twain
"Als wir das Ziel endgültig aus den Augen verloren hatten, verdoppelten wir unsere Anstrengungen."
„Having lost sight of our goals, we redoubled our efforts.“