Author Topic: instruction boolean QB64 true o false  (Read 5610 times)

0 Members and 1 Guest are viewing this topic.

Offline Kiara87

  • Forum Regular
  • Posts: 164
    • View Profile
instruction boolean QB64 true o false
« on: October 08, 2020, 09:23:18 am »
Hello everyone
in the basic you can create a boolean statement where if the answer is true it returns the value 1 instead if the answer is false it returns the value 0
in my program even if the answers are true it returns 0 where is that wrong?

Code: QB64: [Select]
  1. DEFLNG A-Z
  2.  
  3. ' Main
  4. DIM Eta
  5. DIM Citta$
  6. DIM EsitoControllo
  7.  
  8. PRINT " = chiedi inserisci eta della persona"
  9. INPUT Eta
  10. PRINT "inserisci la città "
  11. INPUT Citta$
  12. EsitoControllo = Citta$ = "milano" AND (Eta >= 18) = 1
  13. PRINT "la persona e maggiorenne è anche di milano " + STR$(EsitoControllo)
  14.  
se avessi solo un'ora per salvare il mondo, passerei 55 minuti per definire bene il problema e 5 a trovare la soluzione

FellippeHeitor

  • Guest
Re: instruction boolean QB64 true o false
« Reply #1 on: October 08, 2020, 10:22:56 am »
True is -1:

Code: QB64: [Select]
  1. DEFLNG A-Z
  2.  
  3. ' Main
  4. DIM Eta
  5. DIM Citta$
  6. DIM EsitoControllo
  7.  
  8. PRINT " = chiedi inserisci eta della persona"
  9. INPUT Eta
  10. PRINT "inserisci la città "
  11. INPUT Citta$
  12. EsitoControllo = (Citta$ = "milano") AND (Eta >= 18)
  13. PRINT "la persona e maggiorenne è anche di milano " + STR$(EsitoControllo)
  14.  

Offline bplus

  • Global Moderator
  • Forum Resident
  • Posts: 8053
  • b = b + ...
    • View Profile
Re: instruction boolean QB64 true o false
« Reply #2 on: October 08, 2020, 11:09:26 am »
Further proof: True = NOT 0

Code: QB64: [Select]
  1. PRINT NOT 0  
  2.  

Offline Kiara87

  • Forum Regular
  • Posts: 164
    • View Profile
Re: instruction boolean QB64 true o false
« Reply #3 on: October 08, 2020, 04:21:55 pm »
True is -1:

Code: QB64: [Select]
  1. DEFLNG A-Z
  2.  
  3. ' Main
  4. DIM Eta
  5. DIM Citta$
  6. DIM EsitoControllo
  7.  
  8. PRINT " = chiedi inserisci eta della persona"
  9. INPUT Eta
  10. PRINT "inserisci la città "
  11. INPUT Citta$
  12. EsitoControllo = (Citta$ = "milano") AND (Eta >= 18)
  13. PRINT "la persona e maggiorenne è anche di milano " + STR$(EsitoControllo)
  14.  

thank you   FellippeHeitor

I didn't know what true it was
and false = 0
and what instruction can I use to make me print true or false instead of 0 or -1

I have to print if it gives me -1 I have to print true
if instead it is 0 I have to print false

do i think it is possible?
se avessi solo un'ora per salvare il mondo, passerei 55 minuti per definire bene il problema e 5 a trovare la soluzione

Offline Kiara87

  • Forum Regular
  • Posts: 164
    • View Profile
Re: instruction boolean QB64 true o false
« Reply #4 on: October 08, 2020, 04:23:05 pm »
Further proof: True = NOT 0

Code: QB64: [Select]
  1. PRINT NOT 0  
  2.  

thanks bplus

but I wanted to print true
and print false
se avessi solo un'ora per salvare il mondo, passerei 55 minuti per definire bene il problema e 5 a trovare la soluzione

Offline Dimster

  • Forum Resident
  • Posts: 500
    • View Profile
Re: instruction boolean QB64 true o false
« Reply #5 on: October 08, 2020, 04:27:49 pm »
a = 10
b = 5
if a > b then print "True" else print "False"

Offline bplus

  • Global Moderator
  • Forum Resident
  • Posts: 8053
  • b = b + ...
    • View Profile
Re: instruction boolean QB64 true o false
« Reply #6 on: October 08, 2020, 05:20:56 pm »
Code: QB64: [Select]
  1. ' you must set True and False variables to integer values
  2. False = 0
  3. True = NOT False
  4.  
  5. IF 5 < 15 THEN PRINT True ELSE PRINT False
  6.  
  7.  
  8.  

Offline SMcNeill

  • QB64 Developer
  • Forum Resident
  • Posts: 3972
    • View Profile
    • Steve’s QB64 Archive Forum
Re: instruction boolean QB64 true o false
« Reply #7 on: October 08, 2020, 05:36:43 pm »
Or maybe this is what you want:

Code: QB64: [Select]
  1. DIM Truth(-1 TO 0) AS STRING
  2. Truth(-1) = “TRUE”
  3. Truth(0) = “FALSE”
  4.  
  5. PRINT Truth(5 < 15)
  6. PRINT Truth(5 > 15)
  7.  

I’m thinking that should work.  If not, you’d just need to set a temp variable to hold the result first, before referencing it with your array.

Result = 5 < 15
PRINT Truth(Result)
https://github.com/SteveMcNeill/Steve64 — A github collection of all things Steve!

Offline TempodiBasic

  • Forum Resident
  • Posts: 1792
    • View Profile
Re: instruction boolean QB64 true o false
« Reply #8 on: October 08, 2020, 07:07:09 pm »
Ho kiara87
See nearer the answer of Fellippe
There Is a clear transformation from your line 12 to his line 12.
In BASIC = Is both association like a =5, both comparison like  in IF a = b THEN ....., When you do multiple assignment in the same line of code you must use parentesis.
Programming isn't difficult, only it's  consuming time and coffee

Offline bplus

  • Global Moderator
  • Forum Resident
  • Posts: 8053
  • b = b + ...
    • View Profile
Re: instruction boolean QB64 true o false
« Reply #9 on: October 08, 2020, 07:31:50 pm »
Or maybe this is what you want:

Code: QB64: [Select]
  1. DIM Truth(-1 TO 0) AS STRING
  2. Truth(-1) = “TRUE”
  3. Truth(0) = “FALSE”
  4.  
  5. PRINT Truth(5 < 15)
  6. PRINT Truth(5 > 15)
  7.  

I’m thinking that should work.  If not, you’d just need to set a temp variable to hold the result first, before referencing it with your array.

Result = 5 < 15
PRINT Truth(Result)



Oh hey how bout this!
Code: QB64: [Select]
  1. PRINT TF$(5 < 15)
  2. PRINT TF$(15)
  3. PRINT TF$(-15)
  4. PRINT TF$(20 - 10 = 10)
  5. PRINT TF$(1000 \ 100 - 10)
  6. PRINT TF$(1000 \ 100 - 10 = 0)
  7.  
  8. FUNCTION TF$ (numberOrExpression)
  9.     IF numberOrExpression = 0 THEN TF$ = "False" ELSE TF$ = "True"
  10.  


« Last Edit: October 08, 2020, 07:33:55 pm by bplus »

Offline Richard Frost

  • Seasoned Forum Regular
  • Posts: 316
  • Needle nardle noo. - Peter Sellers
    • View Profile
Re: instruction boolean QB64 true o false
« Reply #10 on: October 09, 2020, 12:34:28 am »
Because I like to play with fire, I've defined TRUE to be 1 in my current program.
I forget why it seemed like a good idea.  Probably because I think it's cool (and
short) to flip the status with var = var XOR 1.   

Why it's playing with fire is that I must keep in mind that Boolean expressions
will still evaluate to -1.

It works better if you plug it in.

Offline bplus

  • Global Moderator
  • Forum Resident
  • Posts: 8053
  • b = b + ...
    • View Profile
Re: instruction boolean QB64 true o false
« Reply #11 on: October 09, 2020, 10:50:29 am »
Because I like to play with fire, I've defined TRUE to be 1 in my current program.
I forget why it seemed like a good idea.  Probably because I think it's cool (and
short) to flip the status with var = var XOR 1.   

Why it's playing with fire is that I must keep in mind that Boolean expressions
will still evaluate to -1.

For that I like
Code: QB64: [Select]
  1. toggle = 1 - toggle
I think I relearned from you!

and with that you don't mess with the Truth!

Offline SMcNeill

  • QB64 Developer
  • Forum Resident
  • Posts: 3972
    • View Profile
    • Steve’s QB64 Archive Forum
Re: instruction boolean QB64 true o false
« Reply #12 on: October 09, 2020, 11:47:42 am »
For that I like
Code: QB64: [Select]
  1. toggle = 1 - toggle
I think I relearned from you!

and with that you don't mess with the Truth!

And there’s always:

DIM b AS _UNSIGNED _BIT
PRINT b
b = NOT b
PRINT b
b = NOT b
PRINT b
https://github.com/SteveMcNeill/Steve64 — A github collection of all things Steve!

Offline Kiara87

  • Forum Regular
  • Posts: 164
    • View Profile
Re: instruction boolean QB64 true o false
« Reply #13 on: October 09, 2020, 04:59:24 pm »
yes this is of type a boolean variable
thanks

Or maybe this is what you want:

Code: QB64: [Select]
  1. DIM Truth(-1 TO 0) AS STRING
  2. Truth(-1) = “TRUE”
  3. Truth(0) = “FALSE”
  4.  
  5. PRINT Truth(5 < 15)
  6. PRINT Truth(5 > 15)
  7.  

I’m thinking that should work.  If not, you’d just need to set a temp variable to hold the result first, before referencing it with your array.

Result = 5 < 15
PRINT Truth(Result)
se avessi solo un'ora per salvare il mondo, passerei 55 minuti per definire bene il problema e 5 a trovare la soluzione

Offline Kiara87

  • Forum Regular
  • Posts: 164
    • View Profile
Re: instruction boolean QB64 true o false
« Reply #14 on: October 09, 2020, 05:03:09 pm »
si ho notato nella riga 12 le parentesi che racchiudono
adesso mi è piu' chiaro
grazie

Ho kiara87
See nearer the answer of Fellippe
There Is a clear transformation from your line 12 to his line 12.
In BASIC = Is both association like a =5, both comparison like  in IF a = b THEN ....., When you do multiple assignment in the same line of code you must use parentesis.
se avessi solo un'ora per salvare il mondo, passerei 55 minuti per definire bene il problema e 5 a trovare la soluzione