找回密码
 加入
搜索
查看: 3462|回复: 11

编程练习06

  [复制链接]
发表于 2012-5-7 19:43:58 | 显示全部楼层 |阅读模式
以下是小弟的码,请各位前辈多多的指教哦
;~ 编写一个程序,要求用户输入小时数和分钟数。
;~ 在MAIN()函数中,传递给一个void函数,后者以下面这样的格式显示这两个值:
;~ Enter the Number of hours : 9
;~ Enter the Number of minutes : 28
;~ Time : 9:28
$Form1 = GUICreate("练习",200,150,-1,-1)
GUICtrlCreateLabel("小时数:",5,2)
GUICtrlCreateLabel("分钟数:",5,22)
$input = GUICtrlCreateInput("",65,2,80,15)
$input1 = GUICtrlCreateInput("",65,22,80,15)
$button = GUICtrlCreateButton("确定",60,40,30,20)
GUISetState()
While 1
        $nMsg = GUIGetMsg()
        Switch $nMsg
                Case -3
                        Exit
                                        Case $button
                                        main()
                EndSwitch
        wend
Func main()
                $Rinput = GUICtrlRead($input)
                $Rinput1 = GUICtrlRead($input1)
                shizhong($Rinput,$Rinput1)
EndFunc
Func shizhong($Rinput,$Rinput1)
                If $Rinput > 23 Or $Rinput < 0 Or $Rinput1 > 59 Or $Rinput1 < 0 Then  
                MsgBox(0,'提示','请输入正确的小值和分钟值')
                ElseIf 1 = StringIsInt($Rinput) And 1 = StringIsInt($Rinput1)  Then
                MsgBox(0,'你输入的时间','Enter the Number of hours : '&$Rinput _
                &@CRLF&'Enter the Number of minutes : '&$Rinput1 _
                &@CRLF&'Time : '&$Rinput&':'&$Rinput1)
                Else
                MsgBox(0,'提示','请输入整数')
        EndIf
        EndFunc

本帖子中包含更多资源

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

×
发表于 2012-5-7 22:10:06 | 显示全部楼层
先判断整数,再看是否小时或分钟数

评分

参与人数 1金钱 +10 贡献 +2 收起 理由
魔导 + 10 + 2 谢谢,小弟研究一下明天上码

查看全部评分

发表于 2012-5-8 03:25:56 | 显示全部楼层
回复 1# 魔导


    你这么喜欢用func ???很好玩啊???有事没事别弄得很复杂似的,到时候把自己都搞蒙了。
#include <EditConstants.au3>
$Form1 = GUICreate("练习",200,150)
GUICtrlCreateLabel("小时数:",5,2)
GUICtrlCreateLabel("分钟数:",5,22)
$input = GUICtrlCreateInput("",65,2,80,15,$ES_NUMBER)
$input1 = GUICtrlCreateInput("",65,22,80,15,$ES_NUMBER)
$button = GUICtrlCreateButton("确定",60,40,30,20)
GUISetState()
While 1
        $nMsg = GUIGetMsg()
        Switch $nMsg
                Case -3
                        Exit
                    Case $button
                $Rinput = GUICtrlRead($input)
                $Rinput1 = GUICtrlRead($input1)
                                If $Rinput<24 And $Rinput> 0 And $Rinput1<60 And $Rinput1> 0 And StringLen($Rinput)<3 And StringLen($Rinput1)<3 then
                                 MsgBox(0,'你输入的时间','Enter the Number of hours : '&$Rinput _
                &@CRLF&'Enter the Number of minutes : '&$Rinput1 _
                &@CRLF&'Time : '&$Rinput&':'&$Rinput1)
               Else
                                MsgBox(0,'提示','请输入正确的小时数和分钟数')
               EndIf
                EndSwitch
 wend
发表于 2012-5-8 03:30:12 | 显示全部楼层
你看一下你原来的代码:输入以下图片中……

本帖子中包含更多资源

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

×

评分

参与人数 1金钱 +40 贡献 +8 收起 理由
魔导 + 40 + 8 感谢前辈,小弟这就改正。

查看全部评分

 楼主| 发表于 2012-5-8 08:10:33 | 显示全部楼层
回复  魔导


    你这么喜欢用func ???很好玩啊???有事没事别弄得很复杂似的,到时候把自己都搞蒙了 ...
半芯竹 发表于 2012-5-8 03:25


没没没,前辈。真是道出了小弟的心声啊,小弟自己把自己都弄得晕乎乎的。
是.....题目要求: 用一个函数 传递参数 给另一个函数
小弟才这么写的,真抱歉   给您添麻烦了
 楼主| 发表于 2012-5-8 08:30:30 | 显示全部楼层
本帖最后由 魔导 于 2012-5-8 08:41 编辑

回复 4# 半芯竹


    前辈的意思是把值  限制  为  两位数  吗?   
请前辈在帮看看 是不是这样的:
$Form1 = GUICreate("练习",200,150,-1,-1)
GUICtrlCreateLabel("小时数:",5,2)
GUICtrlCreateLabel("分钟数:",5,22)
$input = GUICtrlCreateInput("",65,2,80,15)
$input1 = GUICtrlCreateInput("",65,22,80,15)
$button = GUICtrlCreateButton("确定",60,40,30,20)
GUISetState()
While 1
        $nMsg = GUIGetMsg()
        Switch $nMsg
                Case -3
                        Exit
                                Case $button
                                        $Rinput = GUICtrlRead($input)
                                        $Rinput1 = GUICtrlRead($input1)
                                        If 0 = StringIsInt($Rinput) Or 0 = StringIsInt($Rinput1) Or $Rinput > 23 Or $Rinput < 0 Or $Rinput1 > 59 Or $Rinput1 < 0 Or StringLen($Rinput) > 2 Or StringLen($Rinput1) > 2 Then  
                                        MsgBox(0,'提示','请输入正确的小时值和分钟值'&@crlf&'《小时值:0 至 23  整数,分钟值:0 至 59  整数》')
                                        Else 
                                        MsgBox(0,'你输入的时间','Enter the Number of hours : '&$Rinput _
                                        &@CRLF&'Enter the Number of minutes : '&$Rinput1 _
                                        &@CRLF&'Time : '&$Rinput&':'&$Rinput1)
                                        Endif          
                EndSwitch
        wend
 楼主| 发表于 2012-5-8 08:48:59 | 显示全部楼层
先判断整数,再看是否小时或分钟数
whitehead 发表于 2012-5-7 22:10

小弟  改为 ( 先  是否整形  再 是否小时  再  是否分钟 再  是否两位数以内  )
请问先判断  是否整形  是不是为了  方便以后判断 位数?
修改后的码  发在 6楼  请前辈  再帮看看  。。
发表于 2012-5-8 10:01:49 | 显示全部楼层
本帖最后由 半芯竹 于 2012-5-8 10:05 编辑

回复 6# 魔导


    难道我的代码还不够清晰吗?为什么你喜欢这样表达?在INPUT里加个扩展不就可以只限输入数字了吗?

 If 0 = StringIsInt($Rinput) Or 0 = StringIsInt($Rinput1) Or $Rinput > 23 Or $Rinput < 0 Or $Rinput1 > 59 Or $Rinput1 < 0 Or StringLen($Rinput) > 2 Or StringLen($Rinput1) > 2 Then

对比以下我的:
 If $Rinput<24 And $Rinput> 0 And $Rinput1<60 And $Rinput1> 0 And StringLen($Rinput)<3 And StringLen($Rinput1)<3 then
发表于 2012-5-8 10:08:01 | 显示全部楼层
我等只是新手学者,若有不对的地方,见谅。
高手未曾出现,我等半桶水者乱响了……
 楼主| 发表于 2012-5-8 10:21:00 | 显示全部楼层
回复 8# 半芯竹
    回前辈的话  代码已经够清晰了   喜欢这样的表达是因为小弟经验不足(想不出其它办法所至)
替换这个码后小弟又出现了这类的问题:

本帖子中包含更多资源

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

×
发表于 2012-5-8 21:42:42 | 显示全部楼层
回复 10# 魔导

如8楼建议,改成
   $input = GUICtrlCreateInput("",65,2,80,15, $ES_NUMBER)
就只能输入数字,也就不用判断是否整数了
 楼主| 发表于 2012-5-9 23:08:06 | 显示全部楼层
回复 11# whitehead


    改这个码是在  3楼 的,  8楼 的  And  小弟觉得有问题
您需要登录后才可以回帖 登录 | 加入

本版积分规则

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

GMT+8, 2024-9-30 13:17 , Processed in 0.131886 second(s), 21 queries .

Powered by Discuz! X3.5 Licensed

© 2001-2024 Discuz! Team.

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