PowerBuilder Developing a simple calculator

Source: Internet
Author: User

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

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.