S版照你指导的修改了 最终结果这样
程序代码:
frmMain = CREATEOBJECT("C_Form") frmMain.show READ events RETURN DEFINE CLASS C_Form as Form caption = "简单计算器" width = 600 height = 400 autocenter = .T. ADD OBJECT Label1 as label WITH caption="第一个数", Width=60,height=25,Top=100,Left=50 ADD OBJECT Label2 as label WITH caption="第二个数", Width=60,height=25,Top=ThisForm.Label1.Top,Left=ThisForm.Width/2 ADD OBJECT Label3 as label WITH caption= "最终结果",Width=60,height=25 ADD OBJECT Text1 as TextBox WITH value="",Width=100,height=25,Top=ThisForm.Label1.Top,Left=ThisForm.Label1.Left+ThisForm.Label1.Width+5 ADD OBJECT Text2 as TextBox WITH value="",Width=100,height=25,Top=ThisForm.Label1.Top,Left =ThisForm.Label2.Left+ThisForm.Label2.Width+5 ADD OBJECT Text3 as TextBox WITH value="",Width=100,height=25 ADD OBJECT ComboBox1 as ComboBox WITH caption = "计算方式", Height = 20, Width = 50 PROCEDURE init WITH ThisForm.Label3 .Top = ThisForm.Label1.Top + ThisForm.Label1.Height + 50 .Left = ThisForm.Width / 2 - .Width ENDWITH WITH ThisForm.Text3 .Top = ThisForm.Label3.Top .Left = ThisForm.Label3.Left + ThisForm.Label3.Width + 5 ENDWITH WITH Top = ThisForm.Label3.Top .Left = ThisForm.Label3.Left - .Width - 5 .style = 0 .inputmask = .displayvalue .rowsource=[+,-,*,/] && .rowsourcetype=1 && .ColumnCount = 1 .ColumnLines = .F. ENDWITH ENDPROC PROCEDURE destroy CLEAR EVENTS ENDPROC PROCEDURE combobox1.interactivechange LOCAL v as Double WITH ThisForm DO CASE CASE = '+' v = VAL(.Text1.Value) + VAL(.Text2.Value) CASE = '-' v = VAL(.Text1.Value) - VAL(.Text2.Value) CASE = '*' v = VAL(.Text1.Value) * VAL(.Text2.Value) CASE = '/' IF VAL(.Text2.Value) != 0 v = VAL(.Text1.Value) / VAL(.Text2.Value) ELSE MESSAGEBOX("零做除数是非法的", 0) return ENDIF OTHERWISE MESSAGEBOX("错误的计算方法", 0) return ENDCASE .Text3.Value = str(v,10, 2) ENDWITH ENDPROC ENDDEFINE非常感谢你的指教
梅尚程荀
马谭杨奚