locked
Number Variable problem RRS feed

  • Question

  • i'm currently in the process of making a calculator, but when i try to write two variables with numerical values, for example when you click button number 1 and then number 5 it should change the textbox text to 15 but it always changes to 6.

    how can i change this so it says 15?

    Sunday, May 20, 2012 1:56 PM

Answers

  • Because SmallBasic only has a single data type, the best thing to do would have a certain number of boxes for digits so you can inject the numbers in to the appropriate box.

    1 + 5 = 6 because the SmallBasic "Primitive" data type cannot distinguish between a number that is a string and a number than is an integer or decimal.

    Sunday, May 20, 2012 2:07 PM
  • You can use Text.Append to just add values as strings, even numbers.

    See the different effects below:

    value1 = Text.Append(1,5)
    TextWindow.WriteLine(value1)
    
    value2 = 1+5
    TextWindow.WriteLine(value2)

    It is certainly possible - so persevere.  There have been several full featured working SmallBasic calculators before.

    Sunday, May 20, 2012 3:19 PM

All replies

  • Because SmallBasic only has a single data type, the best thing to do would have a certain number of boxes for digits so you can inject the numbers in to the appropriate box.

    1 + 5 = 6 because the SmallBasic "Primitive" data type cannot distinguish between a number that is a string and a number than is an integer or decimal.

    Sunday, May 20, 2012 2:07 PM
  • so is it impossible to do what i want it to do then? 
    Sunday, May 20, 2012 2:10 PM
  • so is it impossible to do what i want it to do then? 
    Aside from erase and re-write, not that I can immediately see.
    Sunday, May 20, 2012 2:25 PM
  • You can use Text.Append to just add values as strings, even numbers.

    See the different effects below:

    value1 = Text.Append(1,5)
    TextWindow.WriteLine(value1)
    
    value2 = 1+5
    TextWindow.WriteLine(value2)

    It is certainly possible - so persevere.  There have been several full featured working SmallBasic calculators before.

    Sunday, May 20, 2012 3:19 PM
  • hi,

    You can do it with StringBuilder.

    StringBuilder sb=new StringBuilder();

    ///Write the below line of Code in Button1 click event

    sb.Append(textBox1.Text);

    textbox1.Text=sb.ToString(); ///Display in textBox

    ///Write the below line of Code in Button5 click event

    sb.Append(textBox5.Text);

    textbox1.Text=sb.ToString();


    PS.Shakeer Hussain

    Sunday, May 20, 2012 3:37 PM
  • Syed,

    This is SmallBasic language, not C#.

    Sunday, May 20, 2012 3:58 PM