找回密码
 加入
搜索
查看: 2315|回复: 8

讨论:想实现混合运算

[复制链接]
发表于 2009-6-19 18:33:00 | 显示全部楼层 |阅读模式
本帖最后由 vfhpai9 于 2009-6-19 18:34 编辑

我已实现单步运算,但无法混合运算。
如:(A+B-E)*C/D
只能算出A+B的结果。
谢谢大哥大姐了,急用啊!!!
发表于 2009-6-19 18:40:29 | 显示全部楼层
你怎么算的,代码贴出来看下?
 楼主| 发表于 2009-6-19 20:15:06 | 显示全部楼层
#include <GUIConstantsEx.au3>
#include <WindowsConstants.au3>

Opt('MustDeclareVars', 1)
Global $lnzong,$Inzong,$nzong

Global $lgmao,$Igmao,$gmao

Global $lgche,$Igche,$gche

Global $lnkuang,$Inkuang,$nkuang
Global $lgkuang,$Igkuang

Global $lgshui,$Igshui,$gshui

Global $lnfei,$Infei,$nfei
Global $lgfei,$Igfei,$gfei

Global $lgshi,$Igshi,$gshi

Global $lG,$IG,$G2,$G3
Example1()

; example 1
Func Example1()
    Local $msg

    GUICreate("计算",1000,500,0,0)  ; will create a dialog box that when displayed is centered
    GUISetState(@SW_SHOW)       ; will display an empty dialog box
$lnzong=GUICtrlCreateLabel("总只数",40,100,50,15)
$Inzong=GUICtrlCreateInput("",20,120,70,15)

$lgmao=GUICtrlCreateLabel("毛重",120,100,50,15)
$Igmao=GUICtrlCreateInput("",100,120,70,15)

$lgkuang=GUICtrlCreateLabel("筐重",200,100,50,15)
$Igkuang=GUICtrlCreateInput("",180,120,50,15)

$lnkuang=GUICtrlCreateLabel("筐的数量",260,100,70,15)
$Inkuang=GUICtrlCreateInput("",260,120,50,15)

$lgche=GUICtrlCreateLabel("车重",340,100,70,15)
$Igche=GUICtrlCreateInput("",320,120,70,15)

$lgshui=GUICtrlCreateLabel("水杂扣重",420,100,70,15)
$Igshui=GUICtrlCreateInput("",400,120,70,15)

$lnfei=GUICtrlCreateLabel("废弃只数",500,100,70,15)
$Infei=GUICtrlCreateInput("",490,120,70,15)

$lgfei=GUICtrlCreateLabel("废弃重量",580,100,70,15)
$Igfei=GUICtrlCreateInput("",570,120,70,15)

$lgshi=GUICtrlCreateLabel("食污扣重",660,100,70,15)
$Igshi=GUICtrlCreateInput("",650,120,70,15)

$lG=GUICtrlCreateLabel("净重",730,100,70,15)
$IG=GUICtrlCreateInput("",730,120,70,15)
    ; Run the GUI until the dialog is closed
       
               
       
    While 1
        $msg = GUIGetMsg()
                do
                $lnzong=GUICtrlRead($Inzong)
                $lgmao=GUICtrlRead($Igmao)
                $lnkuang=GUICtrlRead($Inkuang)
                $lgkuang=GUICtrlRead($Igkuang)
                $lgshui=GUICtrlRead($Igshui)
                $lnfei=GUICtrlRead($Infei)
                $lgche=GUICtrlRead($Igche)
                $lgfei=$lgmao/$lnzong+$lgkuang;            此步混合运算出错
                GUICtrlSetData($Igfei,$lgfei)
                Until $lnzong<0&$lnkuang<0&$lgmao<0
        If $msg = $GUI_EVENT_CLOSE Then ExitLoop
    WEnd
    GUIDelete()
EndFunc   ;==>Example1
发表于 2009-6-20 00:49:57 | 显示全部楼层
#include <GUIConstantsEx.au3>
#include <WindowsConstants.au3>
#Region ### START Koda GUI section ### Form=
$Form1 = GUICreate("混合运算示例", 271, 215, 192, 124)
$Input1 = GUICtrlCreateInput("1", 48, 24, 121, 21)
$Input2 = GUICtrlCreateInput("2", 48, 56, 121, 21)
$Input3 = GUICtrlCreateInput("2", 48, 88, 121, 21)
$Input4 = GUICtrlCreateInput("4", 48, 120, 121, 21)
$Input5 = GUICtrlCreateInput("5", 48, 151, 121, 21)
$Button1 = GUICtrlCreateButton("混合运算", 177, 150, 75, 25, $WS_GROUP)
GUISetState(@SW_SHOW)
#EndRegion ### END Koda GUI section ###
While 1
 $nMsg = GUIGetMsg()
 Switch $nMsg
  Case $GUI_EVENT_CLOSE
   Exit
  Case $Button1
       $a=GUICtrlRead($Input1)
                $b=GUICtrlRead($Input2)
                $c=GUICtrlRead($Input3)
                $d=GUICtrlRead($Input4)
    $e=GUICtrlRead($Input5)
       $result = ($a+$b-$c)*$d/$e
       MsgBox('','',$result)
 EndSwitch
WEnd
可以混合运算啊
看结果:

本帖子中包含更多资源

您需要 登录 才可以下载或查看,没有账号?加入

×
发表于 2009-6-20 00:52:33 | 显示全部楼层
你的代码也没有什么错误啊
发表于 2009-6-20 01:03:31 | 显示全部楼层
搞不懂

(1+2-2) * 4 / 5 难道不是等于0.8吗?汗
 楼主| 发表于 2009-6-20 08:49:17 | 显示全部楼层
谢谢啊,我再试试!!!
 楼主| 发表于 2009-6-20 15:13:40 | 显示全部楼层
问题已解决,谢谢了各位了!!!错在循环语句,用Switch循环语句即可!!!
 楼主| 发表于 2009-6-25 14:07:54 | 显示全部楼层
1# vfhpai9
您需要登录后才可以回帖 登录 | 加入

本版积分规则

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

GMT+8, 2024-6-3 12:26 , Processed in 0.082071 second(s), 25 queries .

Powered by Discuz! X3.5 Licensed

© 2001-2024 Discuz! Team.

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