以下是引用sdta在2012-9-14 23:46:18的发言:
[计算]按钮可以不要
PROCEDURE Button1.CLick
可改为:
PROCEDURE combobox1.interactivechange
前面相应部分可以不要
[计算]按钮可以不要
PROCEDURE Button1.CLick
可改为:
PROCEDURE combobox1.interactivechange
前面相应部分可以不要
这样貌似出不了结果。。。。

梅尚程荀
马谭杨奚
程序代码:CLEAR ALL
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
ADD OBJECT Label2 as label WITH caption = "第二个数", Width = 60, height = 25
ADD OBJECT Label3 as label WITH caption = "最终结果", Width = 60, height = 25
ADD OBJECT Text1 as TextBox WITH value = "", Width = 100, height = 25
ADD OBJECT Text2 as TextBox WITH value = "", Width = 100, height = 25
ADD OBJECT Text3 as TextBox WITH value = "", Width = 100, height = 25
ADD OBJECT ComboBox1 as ComboBox WITH caption = "计算方式", Height = 20, Width = 50
PROCEDURE Arrange
WITH ThisForm.Label1
.Top = 100
.Left = 50
ENDWITH
WITH ThisForm.Text1
.Top = ThisForm.Label1.Top
.Left = ThisForm.Label1.Left + ThisForm.Label1.Width + 5
ENDWITH
WITH ThisForm.Label2
.Top = ThisForm.Label1.Top
.Left = ThisForm.Width / 2
ENDWITH
WITH ThisForm.Text2
.Top = ThisForm.Label1.Top
.Left = ThisForm.Label2.Left + ThisForm.Label2.Width + 5
ENDWITH
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 Activate
ThisForm.Arrange
ENDPROC
PROCEDURE Resize
ThisForm.Arrange
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
程序代码: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
ADD OBJECT Label2 as label WITH caption = "第二个数", Width = 60, height = 25
ADD OBJECT Label3 as label WITH caption = "最终结果", Width = 60, height = 25
ADD OBJECT Text1 as TextBox WITH value = "", Width = 100, height = 25
ADD OBJECT Text2 as TextBox WITH value = "", Width = 100, height = 25
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.Label1
.Top = 100
.Left = 50
ENDWITH
WITH ThisForm.Text1
.Top = ThisForm.Label1.Top
.Left = ThisForm.Label1.Left + ThisForm.Label1.Width + 5
ENDWITH
WITH ThisForm.Label2
.Top = ThisForm.Label1.Top
.Left = ThisForm.Width / 2
ENDWITH
WITH ThisForm.Text2
.Top = ThisForm.Label1.Top
.Left = ThisForm.Label2.Left + ThisForm.Label2.Width + 5
ENDWITH
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
ENDWITH
WITH ThisForm
.Text3.Value = str(v,10, 2)
ENDWITH
ENDPROC
ENDDEFINE

程序代码: 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
删除INIT处的相应代码

程序代码: 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
