Author Topic: Changing number string to text value  (Read 165 times)

adept

  • Newbie
  • *
  • Posts: 26
Changing number string to text value
« on: September 03, 2017, 08:03:18 am »
Wanting to make numbers move on screen, I ran into this:

Code: [Select]
number = 1
_PRINTSTRING (10, 10), number

Which (ofc) doesnt work...

Changing a to a% or a$ doesnt help,

Cannot figure this out, wrong string value?

Been looking trough the wiki, no clue  :(

FellippeHeitor

  • QB64 Partner Site Owner
  • Hero Member
  • *
  • Posts: 1522
  • LET IT = BE
    • QB64.org
Re: Changing number string to text value
« Reply #1 on: September 03, 2017, 08:04:38 am »
_PRINTSTRING (10, 10), STR$(number)

adept

  • Newbie
  • *
  • Posts: 26
Re: Changing number string to text value
« Reply #2 on: September 08, 2017, 12:23:54 pm »
thank you for this FellippeHeitor..!

so question solved, bonus question:

if anyone would care to give some words on how and why this is the case and why it would seem obvious for a "normal" person that any letter or symbol would do as a variable, when clearly it doesnt work like that.

best regards.




SMcNeill

  • Moderator
  • Hero Member
  • *****
  • Posts: 6071
Re: Changing number string to text value
« Reply #3 on: September 08, 2017, 12:35:35 pm »
thank you for this FellippeHeitor..!

so question solved, bonus question:

if anyone would care to give some words on how and why this is the case and why it would seem obvious for a "normal" person that any letter or symbol would do as a variable, when clearly it doesnt work like that.

best regards.

There's two basic variable types in computing --  numeric and string -- and there needs to be someway to tell them apart.

X = 1
X = X + 1

Now with the above, X = 2.  Right?? 

It does IF we assume X is numerical, but what if it's a string?  Wouldn't it be 11 then?  Like saying Dog + food = Dogfood...

So, generally speaking, in BASIC we use the dollar sign at the end of a variable name to visibly signify that it's a string.

X$ = "1"
X$ = X$ + "1"

X = 1
X = X + 1

With the above, X$ is "11" and X is 2...

$ at the end of a variable defines it as a string.  Lack of that $ *generally* defines it as a number.

You can use the STR$ command to convert a number to a string, and the VAL command to convert strings to numbers.
http://bit.ly/TextImage -- Library of QB64 code to manipulate text and images, as a BM library.

http://bit.ly/Color32 -- A set of color CONST for use in 32 bit mode, as a BI library.

Kobolt

  • Moderator
  • Sr. Member
  • *****
  • Posts: 347
  • "Badges, we don't need no stinkin badges!"
Re: Changing number string to text value
« Reply #4 on: September 12, 2017, 07:08:37 pm »
expanding on SMcNeill's work a little,
in terms of numerical data in programing there are "sub-types" too, in QB64 are as follows;
_BIT-- " ` "-- value -1 or 0

_BYTE-- '%%'-- value from -128 to 127(signed) 0 to 255(unsigned)

INTEGER-- '%'-- value from -32768 to 32767(signed) 0 to 65535(unsigned)

LONG(INTEGER) -- "&"-- value from -2,147,483,648 to 2,147,483,647(signed) 0-4,294,967,295(unsigned)

SINGLE -- "!"--value from -2.802597E-45 to +3.402823E+38    <-- this is the default variable type(usually) if no symbol is used.

DOUBLE -- "#" --value from -4.490656458412465E-324  to +1.797693134862310E+308

_INTEGER64 -- "" -- value from -9,223,372,036,854,775,808 to 9,223,372,036,854,775,807(signed)

_FLOAT -- "##" -- value from -1.18E−4932 to +1.18E+4932

more information can be found here:
http://www.qb64.net/wiki/index.php/Variable_Types

adept

  • Newbie
  • *
  • Posts: 26
Re: Changing number string to text value
« Reply #5 on: September 14, 2017, 06:50:59 am »
very interesting and informative. thank you SMcNeill and Kobolt!