Small Basic Forum
What command should I use to make my program pause until the user presses a key? - Printable Version

+- Small Basic Forum (https://litdev.uk/mybb)
+-- Forum: Small Basic (https://litdev.uk/mybb/forumdisplay.php?fid=1)
+--- Forum: Standard Small Basic (https://litdev.uk/mybb/forumdisplay.php?fid=2)
+--- Thread: What command should I use to make my program pause until the user presses a key? (/showthread.php?tid=93)

Pages: 1 2 3


RE: What command should I use to make my program pause until the user presses a key? - WhTurner - 06-30-2024

Hi Elzaimer,

Your problem is caused by using a "non-english" environment. This causes the output of a calculation
with a floating answer with a , (comma) in it. But if you reuse this figure in a calculation the comma is not accepted as a decimal sign but as a
string. So SommeDesEcartsALaMoyenne concatenates the answers.

A solution can be: if you use the LitDev extension by placing LDUtilities.CurrentCulture="en-US" as the first line.

Or you can do the calculation with integers by multiplying with 10000 and rounding. For the display multiply with 0.00001


RE: What command should I use to make my program pause until the user presses a key? - Elzaimer - 06-30-2024

(06-30-2024, 11:42 AM)litdev Wrote: In Small Basic, whether a variable is treated as number or array or string is context dependent.  The operator + works on all data types with precedence left to right.

Consider the following examples.

Code:
TextWindow.WriteLine(1+2)
TextWindow.WriteLine(1+2+"A")
TextWindow.WriteLine("A"+1+2)
TextWindow.WriteLine(Text.Append(1,2)+"A")

In your code I would also initialise SommeDesEcartsALaMoyenne to 0 before it is added to.  SB does assume variables are "" or 0 initially, but good practice to initialise something before you use it.  Also your SD calculation is unusual, usually it would be RootMeanSquare.

Thanks for these very usefull explanations.
I put the line "SommeDesEcartsALaMoyenne = 0" at the top of my program and now it works !
So we have to define the types of the variables by puting xxx = 0 or xxx = "" at the begining of the programs
okkkay !  [Image: biggrin.png]

(06-30-2024, 12:37 PM)WhTurner Wrote: Hi Elzaimer,

Your problem is caused by using a "non-english" environment. This causes the output of a calculation
with a floating answer with a , (comma) in it. But if you reuse this figure in a calculation the comma is not accepted as a decimal sign but as a
string.  So SommeDesEcartsALaMoyenne concatenates the answers.

A solution can be:  if you use the LitDev extension by placing    LDUtilities.CurrentCulture="en-US" as the first line.

Or you can do the calculation with integers by multiplying with  10000 and rounding. For the display multiply with 0.00001

I tried LitDev's solution which was easier for me, but your answer is very interesting.