找回密码
 加入
搜索
查看: 1158|回复: 4

请各位老师指正我写的第一段脚本

[复制链接]
发表于 2009-5-17 13:57:40 | 显示全部楼层 |阅读模式
本帖最后由 最上世纪 于 2009-5-17 15:07 编辑

下边是我学习AU3第一个成果,我知道写的很粗糙,今天发上来,希望各位老师帮忙指点一下,哪里不好,还需要改进的.
dim $a,$b,$c,$d,$e,$f,$g,$h,$i
dim $t
$a=inputBox("油耗简易计算器","请您输入"&@crlf&"?"&@crlf&"?"&@crlf&"现时每公升油价:")
$b=inputBox("油耗简易计算器","请您输入"&@crlf&"?"&@crlf&"?"&@crlf&"本车加了多少油:")
$c=$b/$a
$d=inputBox("油耗简易计算器","请您输入"&@crlf&"?"&@crlf&"?"&@crlf&$c&@crlf&"升油行驶里程数: ")
$e=$b/$a/$d
$f=Round($e*100,2)
$g=Round($e,2)
$h=Round($g*$a,2)
$i=Round($f*$a,2)
if @error=2 and $a="" and $b="" Then
        Exit
EndIf
if $a="" or $b="" Then
        Exit
        EndIf
MsgBox(0,"油耗简易计算器","油耗"&@CRLF _
&"本车每公里油耗为:"&$g&"升"&@crlf _
&"本车百公里油耗为:"&$f&"升"&@crlf _
&"本车每公里然油费用为"&$h&"元"&@crlf _
&"本车百公里然油费用为"&$i&"元"&@crlf _
 楼主| 发表于 2009-5-17 14:00:27 | 显示全部楼层
我想把
$a=inputBox("油耗简易计算器","请您输入"&@crlf&"?"&@crlf&"?"&@crlf&"现时每公升油价:")

$b=inputBox("油耗简易计算器","请您输入"&@crlf&"?"&@crlf&"?"&@crlf&"本车加了多少油:")

$c=$b/$a

$d=inputBox("油耗简易计算器","请您输入"&@crlf&"?"&@crlf&"?"&@crlf&$c&@crlf&"升油行驶里程数: ")
这一段用GUI实现,不知道要怎么写,请哪位老时不吝赐教
发表于 2009-5-17 14:53:37 | 显示全部楼层
2# 最上世纪
#include <EditConstants.au3>
#include <GUIConstantsEx.au3>
#include <StaticConstants.au3>
#include <WindowsConstants.au3>
#Region ### START Koda GUI section ### Form=
$Form1 = GUICreate("Form1", 332, 188, 192, 124)
$Group1 = GUICtrlCreateGroup("原始数据", 16, 8, 297, 81)
$Label1 = GUICtrlCreateLabel("单价(元/升):", 32, 24, 80, 17)
$Label2 = GUICtrlCreateLabel("总价(元):", 176, 24, 80, 17)
$Label3 = GUICtrlCreateLabel("行驶距离(公里):", 32, 56, 100, 17)
$Input1 = GUICtrlCreateInput("0", 110, 24, 60, 21)
$Input2 = GUICtrlCreateInput("0", 240, 24, 60, 21)
$Input3 = GUICtrlCreateInput("0", 135, 56, 60, 21)
$JS=GUICtrlCreateButton("计算",210,56,90,25)
GUICtrlCreateGroup("", -99, -99, 1, 1)
$Group2 = GUICtrlCreateGroup("计算结果", 16, 96, 297, 81)
$Label4 = GUICtrlCreateLabel("每公里耗油:", 32, 120, 140, 17)
$Label5 = GUICtrlCreateLabel("每百公里耗油:", 176, 120, 140, 17)
$Label6 = GUICtrlCreateLabel("每公里费用:", 32, 144, 140, 17)
$Label7 = GUICtrlCreateLabel("每百公里费用:", 176, 144,140, 17)
GUICtrlCreateGroup("", -99, -99, 1, 1)
GUISetState(@SW_SHOW)
#EndRegion ### END Koda GUI section ###

While 1
        $nMsg = GUIGetMsg()
        Switch $nMsg
                Case $GUI_EVENT_CLOSE
                        Exit
                Case $JS
                        $a=Number(GUICtrlRead($Input1))
                        $b=Number(GUICtrlRead($Input2))
                        $c=Number(GUICtrlRead($Input3))
                        
                        If $a=0 Or $b=0 Or $c=0 Then ContinueCase
                        
                        $Km1Y=Round($b/$a/$c,2)
                        $Km100Y=Round($b/$a/$c*100,2)
                        $Km1F=Round($b/$c,2)
                        $Km100F=Round($b/$c*100,2)
                        
                        GUICtrlSetData($Label4,"每公里耗油:"&$Km1Y)
                        GUICtrlSetData($Label5,"每百公里耗油:"&$Km100Y)
                        GUICtrlSetData($Label6,"每公里费用:"&$Km1F)
                        GUICtrlSetData($Label7,"每百公里费用:"&$Km100F)

        EndSwitch
WEnd
发表于 2009-5-17 15:04:19 | 显示全部楼层
本帖最后由 lm959680 于 2009-5-17 15:05 编辑
#include <ButtonConstants.au3>
#include <EditConstants.au3>
#include <GUIConstantsEx.au3>
#include <StaticConstants.au3>
#include <WindowsConstants.au3>
Opt("GUIOnEventMode", 1)
Global $a,$b,$c,$d,$e,$f,$g,$h,$i
#Region ### START Koda GUI section ### Form=
$Form1 = GUICreate("Form1", 282, 121)
GUISetOnEvent($GUI_EVENT_CLOSE, "Form1Close")
$Label1 = GUICtrlCreateLabel("请您输入现时每公升油价:", 8, 8, 139, 17)
$Input1 = GUICtrlCreateInput("", 152, 5, 121, 21)
$Label2 = GUICtrlCreateLabel("请您输入本车加了多少油:", 8, 32, 139, 17)
$Input2 = GUICtrlCreateInput("", 152, 29, 121, 21)
GUICtrlSetOnEvent(-1, "InputChange")
$Label3 = GUICtrlCreateLabel("行驶里程数:", 8, 56, 139, 17)
$Input3 = GUICtrlCreateInput("", 152, 53, 121, 21)
$Button1 = GUICtrlCreateButton("计算", 88, 88, 75, 25, $WS_GROUP)
GUICtrlSetOnEvent(-1, "Button1Click")
GUISetState(@SW_SHOW)
#EndRegion ### END Koda GUI section ###

While 1
        Sleep(100)
WEnd
Func InputChange()
        $a=GUICtrlRead($Input1)
        $b=GUICtrlRead($Input2)
        Select 
                Case $a<>""or $b<>""
                        $i=Round($b/$a,1)
                        GUICtrlSetData($Label3,$i&" 升油行驶里程数:")
                        EndSelect
        EndFunc
Func Button1Click()
        $c=GUICtrlRead($Input3)
Select 
        Case $a="" 
                MsgBox(0,"","请先输入现时每公升油价!")
                Case $b=""
                MsgBox(0,"","请先输入本车加了多少油!")
                Case $c=""
                MsgBox(0,"","请先输入升油行驶里程数!")
        Case Else
                $d=$b/$a/$c
$e=Round($d * 100, 2)
$f = Round($d, 2)
$g = Round($f * $a, 2)
$h = Round($e * $a, 2)
MsgBox(0, "油耗简易计算器", "油耗" & @CRLF _
                 & "本车每公里油耗为:" & $f & "升" & @crlf _
                 & "本车百公里油耗为:" & $e & "升" & @crlf _
                 & "本车每公里然油费用为" & $g & "元" & @crlf _
                 & "本车百公里然油费用为" & $h & "元" & @crlf)
                EndSelect
EndFunc
Func Form1Close()
exit
EndFunc
 楼主| 发表于 2009-5-17 15:06:42 | 显示全部楼层
谢谢老师,我现在正在看GUI的帮助,这边自己也在试着写,我不是想用别人的代码完成自己的任务,只是我的学习习惯是看别人的代码,然后一个一个的看代码里的函数,和它们的作用,再次谢谢老师
您需要登录后才可以回帖 登录 | 加入

本版积分规则

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

GMT+8, 2024-5-10 15:38 , Processed in 0.080556 second(s), 19 queries .

Powered by Discuz! X3.5 Licensed

© 2001-2024 Discuz! Team.

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