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

[AU3基础] [已解决]请教关于 使用两个 Form 时的问题

  [复制链接]
发表于 2014-5-22 14:50:31 | 显示全部楼层 |阅读模式
本帖最后由 hnfeng 于 2014-10-24 15:12 编辑

没有玩过两个 Form,可能是格式不对?语法不对?总之是有大问题,无从下手了,只好求助。

当点击了 $Form1 中的【批量网址】后,想得到一批有规律的网址,目前的问题是:
1、在 $Form2 中,点击 取消、右上角X 时,会直接退出程序。如果编译成exe运行,有Error:Variable used without being declared  提示,然后退出。
  (我希望的是 退回到 $Form1 界面)
2、当 “结束数值”小于“开始数值”时, 会直接退出程序。如果编译成exe运行,有Error:Variable subscript badly formatted  提示,然后退出。
  (我希望有 Msgbox 提示,然后仍然在 $Form2 中)

看不懂Error信息,不知道哪里的问题,请高手帮忙看看,谢谢。
#include <ButtonConstants.au3>
#include <EditConstants.au3>
#include <GUIConstantsEx.au3>
#include <StaticConstants.au3>
#include <Array.au3>

$Form1 = GUICreate("xxxxx", 874, 456)
Global $gu_Button[18]
$gu_Button[5] = GUICtrlCreateButton("开始", 392, 208, 89, 25)
$gu_Button[6] = GUICtrlCreateButton("退出", 392, 248, 89, 25)
$gu_Button[17] = GUICtrlCreateButton("批量网址", 392, 288, 89, 25)

GUISetState(@SW_SHOW, $Form1)

While 1
        $nMsg = GUIGetMsg()
        Switch $nMsg
                Case $GUI_EVENT_CLOSE
                        Exit
                Case $gu_Button[5]
                        _GOGOGO()
                Case $gu_Button[6]
                        Exit
                Case $gu_Button[17]
                        _BatchUrl()
        EndSwitch
WEnd

Func _GOGOGO()
        MsgBox(0, "", "按了【开始】")
EndFunc

Func _BatchUrl()
        GUISetState(@SW_HIDE, $Form1)
        $Form2 = GUICreate("Form2", 615, 260, -1, -1, -1, -1, $Form1)
        $Group21 = GUICtrlCreateGroup("URL", 8, 8, 601, 73)
        $Label21 = GUICtrlCreateLabel("A-固定不变", 232, 60, 62, 17)
        $Label22 = GUICtrlCreateLabel("B-变动", 480, 60, 38, 17)
        $Label23 = GUICtrlCreateLabel("C-固定不变", 536, 60, 62, 17)
        $Input21 = GUICtrlCreateInput("http://www.abcdefg.com/abcd/keys-", 16, 32, 441, 21)
        $Input22 = GUICtrlCreateInput("####", 464, 32, 65, 21, $ES_CENTER + $ES_READONLY)
        $Input23 = GUICtrlCreateInput(".html", 536, 32, 65, 21)
        GUICtrlCreateGroup("", -99, -99, 1, 1)
        $Group22 = GUICtrlCreateGroup("B-变动", 8, 88, 601, 49)
        $Input24 = GUICtrlCreateInput("1", 216, 104, 105, 21, $ES_NUMBER)
        $Label24 = GUICtrlCreateLabel("起始数值:", 160, 108, 55, 17)
        $Input25 = GUICtrlCreateInput("50", 464, 104, 105, 21, $ES_NUMBER)
        $Label25 = GUICtrlCreateLabel("结束数值:", 408, 108, 55, 17)
        GUICtrlCreateGroup("", -99, -99, 1, 1)
        $Edit21 = GUICtrlCreateEdit("", 8, 152, 601, 70)
        $Button21 = GUICtrlCreateButton("确定", 171, 226, 105, 25)
        $Button22 = GUICtrlCreateButton("取消", 339, 226, 105, 25)
        GUISetState(@SW_SHOW, $Form2)
        While 1
                $nMsg = GUIGetMsg()
                GUICtrlSetData($Edit21, GUICtrlRead($Input21) & GUICtrlRead($Input24) & GUICtrlRead($Input23) & @CRLF & "......" & _
                                @CRLF & GUICtrlRead($Input21) & GUICtrlRead($Input25) & GUICtrlRead($Input23))
                Switch $nMsg
                        Case $GUI_EVENT_CLOSE
                                GUISetState(@SW_HIDE, $Form2)
                                GUISetState(@SW_SHOW, $Form1)
                                ExitLoop
                        Case $Button21
                                If GUICtrlRead($Input24) < GUICtrlRead($Input25) Then
                                        Local $n = GUICtrlRead($Input25) - GUICtrlRead($Input24)
                                        Local $batArray[$n + 1][2]
                                        For $i = 0 To $n
                                                $batArray[$i][0] = "Url_" & $i + 1
                                                $batArray[$i][1] = GUICtrlRead($Input21) & GUICtrlRead($Input24) + $i & GUICtrlRead($Input23)
                                        Next
                                        ExitLoop
                                Else
                                        MsgBox(0, "", "“结束数值”必须大于“开始数值”")
                                EndIf
                        Case $Button22
                                GUISetState(@SW_HIDE, $Form2)
                                GUISetState(@SW_SHOW, $Form1)
                                ExitLoop
                EndSwitch
        WEnd
        GUISetState(@SW_HIDE, $Form2)
        GUISetState(@SW_SHOW, $Form1)
        $sUrl_b = $batArray
        _ArrayDisplay($sUrl_b)
EndFunc
发表于 2014-5-23 06:15:58 | 显示全部楼层
Local $batArray
发表于 2014-5-23 15:35:51 | 显示全部楼层
两个窗口不是这么搞的,你看看帮助中的“GUI界面相关”-“GUI 相关 - 消息循环模式“的有关内容吧!
 楼主| 发表于 2014-5-26 10:58:38 | 显示全部楼层
回复 4# shqf


    谢谢,已经搞掂了
发表于 2014-6-20 17:33:05 | 显示全部楼层
学习了,2个窗口还真是基础
您需要登录后才可以回帖 登录 | 加入

本版积分规则

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

GMT+8, 2024-9-20 23:28 , Processed in 0.085588 second(s), 23 queries .

Powered by Discuz! X3.5 Licensed

© 2001-2024 Discuz! Team.

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