Author Topic: print using type mismatch error  (Read 1491 times)

0 Members and 1 Guest are viewing this topic.

Offline xra7en

  • Seasoned Forum Regular
  • Posts: 284
print using type mismatch error
« on: June 05, 2019, 09:56:31 pm »
Code: QB64: [Select]
  1.    
  2.     dim zz as double
  3.     ZZ = 9999 * RND
  4.    
  5.     PRINT USING "####.##"; ZZ; "."
  6.  

this produces a mismatch error for me.
amd I missing something, or using the "PRINT USING" incorrectly?
I just like re-writing old DOS book games into modern QB64 code - weird hobby, I know!

Marked as best answer by xra7en on June 05, 2019, 06:35:06 pm

Offline bplus

  • Global Moderator
  • Forum Resident
  • Posts: 8053
  • b = b + ...
Re: print using type mismatch error
« Reply #1 on: June 05, 2019, 10:29:55 pm »
It's the "." that PRINT USING isn't liking, this works if you really want the dot at the end:
Code: QB64: [Select]
  1. zz = 9999 * RND
  2.  
  3. PRINT USING "####.##"; zz;
  4. PRINT "."
  5.  
  6.  
« Last Edit: June 05, 2019, 10:31:35 pm by bplus »

Offline xra7en

  • Seasoned Forum Regular
  • Posts: 284
Re: print using type mismatch error
« Reply #2 on: June 05, 2019, 10:36:24 pm »
WEIRD
But ya. works!

I supposed when I get down the to "how-to's" it make sense. however on the surface, with the ";" at the end, you would think the "." would show up. :-)

thanks for the quick response!!!!
I just like re-writing old DOS book games into modern QB64 code - weird hobby, I know!

Offline bplus

  • Global Moderator
  • Forum Resident
  • Posts: 8053
  • b = b + ...
Re: print using type mismatch error
« Reply #3 on: June 05, 2019, 10:53:58 pm »
And this works!
Code: QB64: [Select]
  1.  
  2. zz = 9999 * RND
  3.  
  4. PRINT USING "####.##."; zz
  5.  
  6.  


Offline bplus

  • Global Moderator
  • Forum Resident
  • Posts: 8053
  • b = b + ...
Re: print using type mismatch error
« Reply #4 on: June 05, 2019, 10:55:59 pm »
Hey where is the % sign coming from?
Code: QB64: [Select]
  1.  
  2. zz = 9999 * RND
  3.  
  4. PRINT USING "####.##, "; zz, RND * zz, 100 * RND * zz, .001 * zz
  5.  
  6.  

Offline Ashish

  • Forum Resident
  • Posts: 630
  • Never Give Up!
Re: print using type mismatch error
« Reply #5 on: June 06, 2019, 12:59:17 am »
I don't know why but this removes % sign
Code: QB64: [Select]
  1.  
  2. zz = 9999 * RND
  3.  
  4. PRINT USING "######.##, "; zz, RND * zz, 100 * RND * zz, .001 * zz
  5.  
if (Me.success) {Me.improve()} else {Me.tryAgain()}


My Projects - https://github.com/AshishKingdom?tab=repositories
OpenGL tutorials - https://ashishkingdom.github.io/OpenGL-Tutorials

Offline RhoSigma

  • QB64 Developer
  • Forum Resident
  • Posts: 565
Re: print using type mismatch error
« Reply #6 on: June 06, 2019, 01:53:03 am »
The % appears, if the number doesn't fit into the given format: 100 * RND * zz can become 999900 in your example, which doesn't fit into "####.##", but in "######.##" as Ashish did.
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 bplus

  • Global Moderator
  • Forum Resident
  • Posts: 8053
  • b = b + ...
Re: print using type mismatch error
« Reply #7 on: June 06, 2019, 09:13:00 am »
The % appears, if the number doesn't fit into the given format: 100 * RND * zz can become 999900 in your example, which doesn't fit into "####.##", but in "######.##" as Ashish did.

Ah yes, now I remember something like that, thanks guys.

Interesting how it prints the whole number breaking format length over, say starting or filling with %'s.
« Last Edit: June 06, 2019, 09:17:01 am by bplus »