none
How to add RRS feed

  • Question

  • This is a very basic (I hope) question but I'm trying to type

    textwindow.writeline("3+4 = " + 3+4)

    and the answer given is 34.

    OK, so how do I do adding and subtracting?

    Is there a nice easy to read glossary anywhere?

    Thanks,

    Davyp314

    Thursday, May 24, 2018 3:48 PM

Answers

  • Small Basic uses the + operator to concatenate strings, or add numbers depending on the context.  It also works left to right.

    In your case:

    "3+4 = " + 3+4

    First "3+4 = " is considered a string, not a number,

    Then you add 3 (+ 3).  This is adding a number to a string , the result is a string

    Finally add another number to the string to get the final string output "3+4 = 34".

    One thing you can do is use brackets, these will be done first, so the following works as hoped.

    textwindow.writeline("3+4 = " + (3+4))

    Note, the following also works since the numbers are added first before the result is considered a string

    textwindow.writeline(3 + 4 + "=3+4")

    Thursday, May 24, 2018 7:21 PM
    Moderator

All replies

  • Try following code

    totalvalue = 3 + 4;
    textwindow.writeline("3+4 = " + totalvalue)

    https://social.technet.microsoft.com/wiki/contents/articles/16766.beginning-microsoft-small-basic.aspx


    Gaurav Khanna | Microsoft MVP | Microsoft Community Contributor


    Thursday, May 24, 2018 5:30 PM
  • Small Basic uses the + operator to concatenate strings, or add numbers depending on the context.  It also works left to right.

    In your case:

    "3+4 = " + 3+4

    First "3+4 = " is considered a string, not a number,

    Then you add 3 (+ 3).  This is adding a number to a string , the result is a string

    Finally add another number to the string to get the final string output "3+4 = 34".

    One thing you can do is use brackets, these will be done first, so the following works as hoped.

    textwindow.writeline("3+4 = " + (3+4))

    Note, the following also works since the numbers are added first before the result is considered a string

    textwindow.writeline(3 + 4 + "=3+4")

    Thursday, May 24, 2018 7:21 PM
    Moderator