| 网站首页 | 业界新闻 | 小组 | 威客 | 人才 | 下载频道 | 博客 | 代码贴 | 在线编程 | 编程论坛
欢迎加入我们,一同切磋技术
用户名:   
 
密 码:  
共有 1801 人关注过本帖
标题:计算器?
只看楼主 加入收藏
有容就大
Rank: 16Rank: 16Rank: 16Rank: 16
来 自:东土大唐
等 级:版主
威 望:74
帖 子:9048
专家分:14309
注 册:2011-11-11
收藏
得分:0 
以下是引用sdta在2012-9-14 23:46:18的发言:

[计算]按钮可以不要
    PROCEDURE Button1.CLick
可改为:
    PROCEDURE combobox1.interactivechange
前面相应部分可以不要

这样貌似出不了结果。。。。

梅尚程荀
马谭杨奚







                                                       
2012-09-14 23:54
sdta
Rank: 20Rank: 20Rank: 20Rank: 20Rank: 20
来 自:江苏省连云港市
等 级:版主
威 望:335
帖 子:9841
专家分:27213
注 册:2012-2-5
收藏
得分:0 
*!*        ADD OBJECT Button1 as CommandButton WITH caption = "计算", height = 25

*!*            WITH ThisForm.Button1
*!*               .Top = ThisForm.Label3.Top + ThisForm.Label3.Height + 30
*!*               .Left = ThisForm.Width / 2 - .Width / 2
*!*            ENDWITH
上面代码可以不要

坚守VFP最后的阵地
2012-09-14 23:59
sdta
Rank: 20Rank: 20Rank: 20Rank: 20Rank: 20
来 自:江苏省连云港市
等 级:版主
威 望:335
帖 子:9841
专家分:27213
注 册:2012-2-5
收藏
得分:0 
以下是引用有容就大在2012-9-14 23:54:13的发言:


这样貌似出不了结果。。。。
试下就知道了

坚守VFP最后的阵地
2012-09-14 23:59
有容就大
Rank: 16Rank: 16Rank: 16Rank: 16
来 自:东土大唐
等 级:版主
威 望:74
帖 子:9048
专家分:14309
注 册:2011-11-11
收藏
得分:0 
回复 12楼 sdta
吼吼 改了下确实是这样的程序简洁多了
程序代码:
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


梅尚程荀
马谭杨奚







                                                       
2012-09-15 00:06
sdta
Rank: 20Rank: 20Rank: 20Rank: 20Rank: 20
来 自:江苏省连云港市
等 级:版主
威 望:335
帖 子:9841
专家分:27213
注 册:2012-2-5
收藏
得分:0 
减肥后代码
程序代码:
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

INIT中的代码可以放在各自的ADD中设置

[ 本帖最后由 sdta 于 2012-9-15 00:12 编辑 ]

坚守VFP最后的阵地
2012-09-15 00:08
有容就大
Rank: 16Rank: 16Rank: 16Rank: 16
来 自:东土大唐
等 级:版主
威 望:74
帖 子:9048
专家分:14309
注 册:2011-11-11
收藏
得分:0 
回复 15楼 sdta
厉害
PROCEDURE init 默认包含 PROCEDURE Activate 和 PROCEDURE Resize吗?

梅尚程荀
马谭杨奚







                                                       
2012-09-15 00:13
有容就大
Rank: 16Rank: 16Rank: 16Rank: 16
来 自:东土大唐
等 级:版主
威 望:74
帖 子:9048
专家分:14309
注 册:2011-11-11
收藏
得分:0 
以下是引用sdta在2012-9-15 00:08:46的发言:


INIT中的代码可以放在各自的ADD中设置
ADD是什么东西 ?

梅尚程荀
马谭杨奚







                                                       
2012-09-15 00:15
sdta
Rank: 20Rank: 20Rank: 20Rank: 20Rank: 20
来 自:江苏省连云港市
等 级:版主
威 望:335
帖 子:9841
专家分:27213
注 册:2012-2-5
收藏
得分:0 
程序代码:
    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处的相应代码

坚守VFP最后的阵地
2012-09-15 00:18
sdta
Rank: 20Rank: 20Rank: 20Rank: 20Rank: 20
来 自:江苏省连云港市
等 级:版主
威 望:335
帖 子:9841
专家分:27213
注 册:2012-2-5
收藏
得分:0 
程序代码:
    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处的相应代码

坚守VFP最后的阵地
2012-09-15 00:18
有容就大
Rank: 16Rank: 16Rank: 16Rank: 16
来 自:东土大唐
等 级:版主
威 望:74
帖 子:9048
专家分:14309
注 册:2011-11-11
收藏
得分:0 
以下是引用有容就大在2012-9-15 00:15:58的发言:

ADD是什么东西 ?

这个问的太傻了 哈哈 原来就是ADD OBJECT


梅尚程荀
马谭杨奚







                                                       
2012-09-15 00:20
快速回复:计算器?
数据加载中...
 
   



关于我们 | 广告合作 | 编程中国 | 清除Cookies | TOP | 手机版

编程中国 版权所有,并保留所有权利。
Powered by Discuz, Processed in 0.047419 second(s), 7 queries.
Copyright©2004-2024, BCCN.NET, All Rights Reserved