Kesbath: Mini Maths Calc

From NSB App Studio
Revision as of 15:44, 12 October 2015 by Ghenne (talk | contribs) (→‎Part B)
Jump to navigation Jump to search

Version 1.0.0

Create a form with 3 buttons and 2 textboxes. Change the background colour. The Buttons need to have the text /\ and V and Reset. The textboxes have a property called placeholder and this has been set to Enter Number here…

The Three buttons need their onclick property set to Button1_onclick() where the 1 changes to 2 or 3 depending on the button.

Now the code below can be pasted in… (No need to type – for once!!)

Rem Version 1.03
StartUp()
Dim TempStore

Function Button1_onclick()

End Function

Function Button2_onclick()
  TempStore = CInt(TextBox1.value)
  TextBox1.value = CInt(TextBox1.value) * CDbl(TextBox2.value)
  TextBox2.value = TempStore
End Function

Function Button3_onclick()
  StartUp()
End Function

Sub StartUp()
  TextBox1.value = 1
  TextBox2.value = 2
End Sub

Version 1.01

The Down arrow (Button2) and Reset (Button3) have code that works. Look at the code and try to think what will happen? Run the program and see if you are correct. Did you expect the numbers to appear in the 2 textboxes? If not have a look back at the code to see if you can work out why they were entered. Can you change the program so 2 appears in the top textbox and 3 in the bottom textbox when the program starts?

Version 1.02

There is no code for Button1. Copy the code from Button2 to Button1. Can you change the code for Button1 so that the present value of Textbox2 is placed in Textbox1 and Textbox2 now become itself divided by 2, that is, it halves itself.

Version 1.03

Now change the code for Button2 so that the present value of Textbox1 becomes itself plus the value of textbox2. Then modify Button1 so that the value of Textbox1 becomes itself minus the value of textbox2. Change the start values of Textbox1 to 0 and Textbox2 to 3. Test your code… With these values the top textbox will go up or down by 3 (ie/\ 0…3..6…9 then \/ 6….3…0…-3)

Version 1.09

Now change the code so that both textboxes reset / start with 1 in. Button2 should be coded so that it makes textbox1 the value of textbox2 and textbox2 becomes the original value of textbox1 + the contents of textbox2. (TempStore will be needed to keep the original value of Textbox2 in!) Pressing Button2 from 1 1 will give 2 … 3 … 5 … 8 …. 13 If you cannot work this code out the answer has been given in the box below.

 TempStore = CInt(TextBox2.value)
 TextBox2.value = CInt(TextBox1.value) + CDbl(TextBox2.value)
 TextBox1.value = TempStore

Version 1.10

Now change Button1 so that the sequence of numbers goes into reverse. That is when 8 & 13 are displayed the button gives 5 & 8, then 3 & 5 then 2 & 3 with the first number being the top textbox1. Do you know the name of this sequence?

Part B

Now with the program working. You should aim to test it as part of your website. To do this make sure you have saved your project. Then… Select Run and Deploy(F6)

If you look in the folder where you have saved the Project (and set in Preferences....) You should see an extra html file and a folder. Click on the folder… Try the index file!