找回密码
 加入
搜索
查看: 4356|回复: 5

[效率算法] 如何让同步输入框的数据自动计算并输出【已解决】

  [复制链接]
发表于 2011-2-9 18:58:06 | 显示全部楼层 |阅读模式
本帖最后由 清风飘飘 于 2011-2-12 07:46 编辑

每月发工资时候总是觉得太少了,想做个工资计算器,遇到了点问题,麻烦那位朋友指点迷津。
代码
#include <ButtonConstants.au3>
#include <EditConstants.au3>
#include <GUIConstantsEx.au3>
#include <StaticConstants.au3>
#include <WindowsConstants.au3>
#include <GUIConstantsEx.au3>
#Region ### START Koda GUI section ### Form=c:\documents and settings\administrator\my documents\form1.kxf
$Form1 = GUICreate("工资计算器", 409, 260, 434, 170)
$Label1 = GUICtrlCreateLabel("工资底薪", 40, 32, 86, 17)
$Input1 = GUICtrlCreateInput("", 120, 32, 121, 21, BitOR($GUI_SS_DEFAULT_INPUT,$ES_NUMBER))
$Label2 = GUICtrlCreateLabel("1.5倍加班", 40, 64, 86, 17)
$Input2 = GUICtrlCreateInput("", 120, 64, 121, 21, BitOR($GUI_SS_DEFAULT_INPUT,$ES_NUMBER))
$Label3 = GUICtrlCreateLabel("2倍加班", 40, 96, 86, 17)
$Input3 = GUICtrlCreateInput("", 120, 96, 121, 21, BitOR($GUI_SS_DEFAULT_INPUT,$ES_NUMBER))
$Label4 = GUICtrlCreateLabel("三倍加班", 40, 128, 86, 17)
$Input4 = GUICtrlCreateInput("", 120, 128, 121, 21, BitOR($GUI_SS_DEFAULT_INPUT,$ES_NUMBER))
$Label5 = GUICtrlCreateLabel("当月总工资", 40, 160, 86, 17)
$Input5 = GUICtrlCreateInput("", 120, 160, 121, 21)
$Button1 = GUICtrlCreateButton("重新计算", 304, 208, 75, 25)
GUISetState(@SW_SHOW)
#EndRegion ### END Koda GUI section ###

While 1
        $nMsg = GUIGetMsg()
        Switch $nMsg
                Case $GUI_EVENT_CLOSE
                        Exit

EndSwitch
GUICtrlSetData($Input5,GUICtrlRead($Input2)+GUICtrlRead($Input3)+GUICtrlRead($Input4))
WEnd
我想做的是当底薪输入后,当月总工资会自动同步输出。1.5、2、3倍加班小时输入后会自动计算然后把加班费也加入到总工资。加班费的算法是:底薪/174算出一个小时的工资,然后再分别乘以1.5、2、3倍小时数。我昨晚写了很久,就是无法计算加班费,请朋友们帮帮忙!
发表于 2011-2-9 19:04:28 | 显示全部楼层
参考这个
发表于 2011-2-10 17:38:39 | 显示全部楼层

#include <ButtonConstants.au3>
#include <EditConstants.au3>
#include <GUIConstantsEx.au3>
#include <StaticConstants.au3>
#include <WindowsConstants.au3>
Opt("GUIOnEventMode", 1)
#Region ### START Koda GUI section ### Form=
$Form1 = GUICreate("工资计算     By Lovexia", 232, 202, -1, -1, BitOR($WS_CAPTION, $WS_SYSMENU))
GUISetOnEvent($GUI_EVENT_CLOSE, "Form1Close")
$Label1 = GUICtrlCreateLabel("基本工资:", 16, 32, 64, 17)
$Input1 = GUICtrlCreateInput("", 80, 25, 121, 21)
$Label2 = GUICtrlCreateLabel("1.5倍小时:", 16, 64, 67, 17)
$Label3 = GUICtrlCreateLabel("2.0倍小时:", 16, 96, 67, 17)
$Label4 = GUICtrlCreateLabel("3.0倍小时:", 16, 129, 67, 17)
$Input2 = GUICtrlCreateInput("", 80, 58, 121, 21)
$Input3 = GUICtrlCreateInput("", 80, 90, 121, 21)
$Input4 = GUICtrlCreateInput("", 80, 122, 121, 21)
$Label5 = GUICtrlCreateLabel("总工资=", 16, 168, 46, 17)
$Button1 = GUICtrlCreateButton("清空(&X)", 152, 152, 57, 41)
GUICtrlSetOnEvent(-1, "Button1Click")
$Label6 = GUICtrlCreateLabel("这里显示总工资", 64, 168, 88, 17)

GUISetState(@SW_SHOW)
#EndRegion ### END Koda GUI section ###
AdlibRegister('Jisuan', 1000)
While 1
        Sleep(100)
WEnd

Func Button1Click()
        GUICtrlSetData($Input1, '')
        GUICtrlSetData($Input2, '')
        GUICtrlSetData($Input3, '')
        GUICtrlSetData($Input4, '')
EndFunc   ;==>Button1Click
Func Form1Close()
        Exit
EndFunc   ;==>Form1Close


Func Jisuan()
        Local $Xs,$X1x5,$X2,$X3,$Zong,$In1,$In2,$In3,$In4
        If GUICtrlRead($Input1) <> '' Then $In1 = GUICtrlRead($Input1)
        If GUICtrlRead($Input2) <> '' Then $In2 = GUICtrlRead($Input2)
        If GUICtrlRead($Input3) <> '' Then $In3 = GUICtrlRead($Input3)
        If GUICtrlRead($Input4) <> '' Then $In4 = GUICtrlRead($Input4)
        $Xs = $In1 /174
        $X1x5 = $In2*Number(1.5)
        $X2 = $In3*Number(2)
        $X3 = $In4*Number(3)
        $Zong = Round($X1x5+$X2+$X3+$In1,2)
        GUICtrlSetData($Label6,$Zong)
EndFunc   ;==>Jisuan


我的理解 。不知道合不合意

评分

参与人数 1金钱 +30 收起 理由
ceoguang + 30 30

查看全部评分

发表于 2011-2-10 17:50:38 | 显示全部楼层
[au3]#include <ButtonConstants.au3>
#include <EditConstants.au3>
#include <GUIConstantsEx.au3>
#include <StaticConstants.au3>
#include <WindowsConstants.au3>
#include <GUIConstantsEx.au3>
#Region ### START Koda GUI section ### Form=c:\documents and settings\administrator\my documents\form1.kxf
$Form1 = GUICreate("工资计算器", 409, 260, 434, 170)
$Label1 = GUICtrlCreateLabel("工资底薪", 40, 32, 86, 17)
$Input1 = GUICtrlCreateInput("", 120, 32, 121, 21, BitOR($GUI_SS_DEFAULT_INPUT, $ES_NUMBER))
$Label2 = GUICtrlCreateLabel("1.5倍加班", 40, 64, 86, 17)
$Input2 = GUICtrlCreateInput("", 120, 64, 121, 21, BitOR($GUI_SS_DEFAULT_INPUT, $ES_NUMBER))
$Label3 = GUICtrlCreateLabel("2倍加班", 40, 96, 86, 17)
$Input3 = GUICtrlCreateInput("", 120, 96, 121, 21, BitOR($GUI_SS_DEFAULT_INPUT, $ES_NUMBER))
$Label4 = GUICtrlCreateLabel("三倍加班", 40, 128, 86, 17)
$Input4 = GUICtrlCreateInput("", 120, 128, 121, 21, BitOR($GUI_SS_DEFAULT_INPUT, $ES_NUMBER))
$Label5 = GUICtrlCreateLabel("当月总工资", 40, 160, 86, 17)
$Input5 = GUICtrlCreateInput("", 120, 160, 121, 21)
$Button1 = GUICtrlCreateButton("重新计算", 304, 208, 75, 25)
GUIRegisterMsg($WM_COMMAND, "MY_WM_COMMAND")
GUISetState(@SW_SHOW)
#EndRegion ### END Koda GUI section ###

While 1
        $nMsg = GUIGetMsg()
        Switch $nMsg
                Case $GUI_EVENT_CLOSE
                        Exit

        EndSwitch
WEnd



Func MY_WM_COMMAND($hWnd, $msg, $wParam, $lParam)
        Local Const $EN_CHANGE = 0x300

        Local $nNotifyCode = BitShift($wParam, 16)
        Local $nID = BitAND($wParam, 0xFFFF)
        Local $hCtrl = $lParam
        If $nNotifyCode = $EN_CHANGE Then
                GUICtrlSetData($Input5, Number(GUICtrlRead($Input2)) + Number(GUICtrlRead($Input3)) + Number(GUICtrlRead($Input4)))
        EndIf
EndFunc   ;==>MY_WM_COMMAND[/au3]

评分

参与人数 1金钱 +30 收起 理由
ceoguang + 30

查看全部评分

发表于 2011-2-11 10:05:45 | 显示全部楼层
顶上面几位
 楼主| 发表于 2011-2-12 07:46:22 | 显示全部楼层
回复 3# chenronting


    嗯,谢谢你!我要的就是这样的!
您需要登录后才可以回帖 登录 | 加入

本版积分规则

QQ|手机版|小黑屋|AUTOIT CN ( 鲁ICP备19019924号-1 )谷歌 百度

GMT+8, 2024-5-20 22:52 , Processed in 0.088452 second(s), 29 queries .

Powered by Discuz! X3.5 Licensed

© 2001-2024 Discuz! Team.

快速回复 返回顶部 返回列表