The simple calculator refers to the user each input complete expression (one yuan or two yuan) calculates.
1, design a good interface
2. define three variables in declare Instance variable
Decimal ADD1//storage operand
Char S1//store operator
int flag//Determine if the calculation is complete
3. Double-click on the value and decimal keys to add clicked () function contents
If Flag=0 then sle_1.text= "" flag=1 End If sle_1.text=sle_1.text+this.text
4. Add the contents of the clicked () function within four operators
Choose case S1 case ' * ' sle_1.text=string (Dec (sle_1.text) *add1) //dec (x) function is to convert the X value to a numeric type the role of the//string (x) function is to convert the X value to the character case '/' sle_1.text=string (Add1/dec (sle_1.text)) Case ' + ' sle_1.text=string (Dec (sle_1.text) +add1) Case '-' sle_1.text=string (Add1-dec (sle_1.text)) End Choose Add1=dec (Sle_1.text) //Keep the first input or intermediate result s1=this.text //Keep the operator just pressed flag=0 //Prepare to enter next number
5. Add the clicked () function contents to the equals sign
Choose case S1 case ' * ' sle_1.text=string (Dec (sle_1.text) *add1) Case '/' sle_1.text=string ( Add1/dec (sle_1.text) Case ' + ' sle_1.text=string (Dec (sle_1.text) +add1) Case '-' sle_1.text= String (Add1-dec (sle_1.text)) end Choose flag=0 s1= "
Project file: Click to open link
PowerBuilder Developing a simple calculator