Still do not very good, a lot of advice ah, pay attention to this aspect
Initialize: Display number "dataout". Caption"for 0
1. Extraction of the first factor
When the number is clicked for the first time (when the program initializes, the result is calculated for the next time, when the 0 key is pressed)
--"dataout. Caption"=" "
--"dataout. Caption"=dataout. caption& Index
Explanation: The purpose here is: Click on the initial display number to the number of clicks, then click on the stitching
When it's not the first time you click
--"dataout. Caption"=dataout. caption& Index
The question that needs to be considered is: here the computer work standard Resflag is unfinished
This out of the pre-explanation, the number 0-9, the symbol +-*/ is two digital array button control, about how to do it, take the digital 0-9 button For example:
Each of these buttons uses the name num,
Just the Index property is different, just like an array, the way to create a set of buttons is to first build on the form
Set a button (num), then right-clickon num , select Copy,
Then right-click anywhere on the form, choose Paste (Paste), and you'll be prompted to create a group of controls.
Select "Yes" to repeat the above steps until you have created a ten button.
2 about the extraction of symbols
Each element of the symbol array sign corresponds to a unique Index
When triggered, two things are done:
1. Situation: Consideration should be given to "dataout." Caption, "the illegality of
Behavior: Will be "dataout." Caption"assigns a value to the global variable Num1, requires string-to-numeric conversion, there are value,clng,cint various. Given the calculation of decimals, value is used
Method: "dataout. Caption"! =""
2. Situation: Consider when +-*/ click multiple times
Behavior: Assigns the index corresponding to each symbol to the global variable signope (rate)
Method: When clicked multiple times, directly regardless of him, using the Exit Sub
3. Settlement of results
Click action with the "=" button
3.1 The value of the second factor
First of all, explain why the first factor is extracted after the "dataout." Caption"empty?"
Because this version of the calculator is to use the display string to convert to floating-point numbers to determine, if for the effect will +-*/(other symbols such as (),Sin,con,tan , etc.) on the screen, The second factor is hard to extract and has not yet been thought of, (the Great God sees, hints, thanks) have to use this method to extract
Eg:num2=val(dataout. Caption);
3.2 to consider that the operation is in the calculation state of the operation, otherwise the results have been calculated, when you keep clicking the "=" button, the factor in memory:num1 and Num2 still operate continuously
Workaround: Use the resflag flag bit:
If not Resflag Then
Calculation
Else
The display displays the previous calculation result
3.2 Determines +-*/ operations based on global variable symbol flags
In the symbol button array, use Index(not the same as on 2 ) to determine, using the select in VB Statement.
Issue 1: Consider The case of denominator 0
Method: When it is division and the denominator is zero, the special output is "infinity"
Question 2: When one factor is used, but the next symbol is pressed, the display displays the first factor
When you press the = button directly, the display displays the previous result
Note: After the completion of the calculation, after the 0 button , it will be like when the program started thinking:
Status change flag after completion: Calculation completion flag Resflag clear 0, decimal mark clear 0, first number sign clear 0
Extra button, just stick to the code, dizzy.
Backspace button:
Clear 0 C Button
The decimal point button.
Avoid multiple occurrences of the decimal point
The structure analysis of VB Calculator project algorithm