找回密码
 加入
搜索
查看: 4197|回复: 7

[GUI管理] 函数中的子窗口为什么只运行一次

  [复制链接]
发表于 2012-5-15 02:25:40 | 显示全部楼层 |阅读模式
代码如下:
#include <ButtonConstants.au3>
#include <ComboConstants.au3>
#include <EditConstants.au3>
#include <GUIConstantsEx.au3>
#include <StaticConstants.au3>
#include <WindowsConstants.au3>

#include <SQLite.au3>
#include <SQLite.dll.au3>
#Region ### START Koda GUI section ### Form=
Global $Form1 = GUICreate("铜矿花名册", 1024, 768)
$ListView1 = GUICtrlCreateListView("", 5, 50, 1010, 710)
$Button1 = GUICtrlCreateButton("录入", 24, 13, 124, 25)
$Button2 = GUICtrlCreateButton("修改", 240, 13, 124, 25)
$Button3 = GUICtrlCreateButton("删除", 456, 13, 124, 25)
GUISetState(@SW_SHOW)
#EndRegion ### END Koda GUI section ###

If Not FileExists(@ScriptDir & '\db\name.db') Then createTable()


While 1
        $nMsg = GUIGetMsg()
        Switch $nMsg
                Case $Button1
                        GUISetState(@SW_DISABLE,$Form1)
                        insertName()
                Case $Button2
                        MsgBox(0,'','')
                Case $GUI_EVENT_CLOSE
                        Exit

        EndSwitch
WEnd

Func createTable() ;建表
        _SQLite_Startup()
        _SQLite_Open(@ScriptDir & '\db\name.db')
        
        _SQLite_Exec(-1, 'create table if not exists name(BianHao integer primary key,XinMing text Not Null,GongZhong text,DianHua int,ShenFengZhenHao int Not Null,SFZSaoMiao blob)')
        
        ;字段名全拼音,最后一个是存放身份证扫描件的,还有如果不在矿的话,工种那里直接写离矿,这个办法蛮好。。。
        ;还有 建表时加 if not exists 这样做的好处是不用知道表是不是存在,创建时,如果有表存在,就不会重复创建。
        ;sqlite要插入数据,才建表,这个很郁闷。。。刚测试了下。。
        
        _SQLite_Exec(-1, "insert into name(XinMing,ShenFengZhenHao) values ('赵兴',622225198602101215);") ;这句只是为了建表,sqlite不插入数据不建表的.
        
        
        ;_SQLite_Exec(-1,"truncate table name")   sqlite 不支持truncate table
        _SQLite_Exec(-1, "delete from name") ;删除表内所有行
        
        _SQLite_Close()
        _SQLite_Shutdown()
        
EndFunc   ;==>createTable

Func insertName()
        
        $Form2 = GUICreate("信息录入", 344, 340,-1,-1,-1,-1,$Form1)
        $Label1 = GUICtrlCreateLabel("姓   名", 16, 16, 52, 17)
        $Input1 = GUICtrlCreateInput("Input1", 80, 16, 121, 21)
        $Label2 = GUICtrlCreateLabel("身份证号", 16, 48, 52, 17)
        $Input2 = GUICtrlCreateInput("Input2", 80, 48, 193, 21)
        $Label3 = GUICtrlCreateLabel("职  务", 16, 80, 52, 17)
        $Combo1 = GUICtrlCreateCombo("Combo1", 80, 80, 129, 25, BitOR($CBS_DROPDOWN, $CBS_AUTOHSCROLL))
        $Pic1 = GUICtrlCreatePic("", 8, 152, 212, 180)
        $Label4 = GUICtrlCreateLabel("证件扫描", 16, 112, 52, 17)
        $Input3 = GUICtrlCreateInput("Input3", 80, 112, 129, 21)
        $Button1 = GUICtrlCreateButton("选择图片", 216, 112, 59, 25)
        $Button2 = GUICtrlCreateButton("ok", 232, 168, 35, 161)
        GUISetState(@SW_SHOW,$Form2)
        
        While 1
        $nMsg = GUIGetMsg()
        Switch $nMsg
                
                Case $GUI_EVENT_CLOSE

                        GUISetState(@SW_ENABLE,$Form1)
                        GUIDelete($Form2)
                        ExitLoop

        EndSwitch
    WEnd

        
EndFunc   ;==>insertName
第一次点录入按钮时会出子窗口,第二次就不出了。。。。高手帮忙。。。
论坛看了很多帖也没能搞定
发表于 2012-5-15 11:43:36 | 显示全部楼层
回复 1# 朱雅琼


   

Opt("GUIOnEventMode", 1)
Global $Form1 = GUICreate("铜矿花名册", 1024, 768)
GUISetOnEvent(-3, "_GuiMsg")
$ListView1 = GUICtrlCreateListView("", 5, 50, 1010, 710)
$Button1 = GUICtrlCreateButton("录入", 24, 13, 124, 25)
$Button2 = GUICtrlCreateButton("修改", 240, 13, 124, 25)
$Button3 = GUICtrlCreateButton("删除", 456, 13, 124, 25)
GUISetState(@SW_SHOW)
$Form2 = GUICreate("信息录入", 344, 340)
GUISetOnEvent(-3, "_GuiMsg")
$Button21 = GUICtrlCreateButton("ok", 232, 168, 35, 161)
GUICtrlSetOnEvent($Button21, "_GuiMsg")
GUICtrlSetOnEvent($Button1, "_GuiMsg")
While 1
        Sleep(10)
WEnd
Func _GuiMsg()
        Switch @GUI_CtrlId
                Case - 3
                        Switch @GUI_WinHandle
                                Case $Form1
                                        Exit
                                Case $Form2
                                        GUISetState(@SW_ENABLE, $Form1)
                                        GUISetState(@SW_HIDE, $Form2)
                                                                                EndSwitch        
                                                Case $Button1
                        GUISetState(@SW_SHOW, $Form2)
                        GUISetState(@SW_DISABLE, $Form1)
                        
                Case $Button21
                        MsgBox(64, "测试", "This is a test!")
                                        
        EndSwitch
EndFunc 
 楼主| 发表于 2012-5-15 12:50:06 | 显示全部楼层
谢谢楼上,可是只能是事件模式控制么。。。循环模式下就不能解决么。。。。
发表于 2012-5-15 12:56:09 | 显示全部楼层
把insertName()函数中的$button1,$button2改成$button4,$button5试试
第69,70行
 楼主| 发表于 2012-5-15 13:04:08 | 显示全部楼层
回复 4# 1007236046

谢谢,按你上面的搞定了,但是觉得函数中的局部变量和外边的变量应该不冲突的啊。。
发表于 2012-5-15 13:09:27 | 显示全部楼层
回复  1007236046

谢谢,按你上面的搞定了,但是觉得函数中的局部变量和外边的变量应该不冲突的啊。。
朱雅琼 发表于 2012-5-15 13:04



    那你把insertName()函数中的$button1,$button2改成local $button1,local $button2也可以
发表于 2012-5-15 15:52:17 | 显示全部楼层
本帖最后由 shqf 于 2012-5-15 15:54 编辑

楼上正解啊。某个变量的作用域要看是何时以及如何声明的。如果在某个函数内部声明一个变量,则该变量就只在该函数的Local(局部) 范围内有效,称为局部变量。在函数内创建的变量将在函数结束时自动被销毁。在默认情况下,使用Dim 声明的变量或在函数内部直接赋值而成的变量都是Local(局部)变量,除非有同名的全局变量存在(此时将视此变量为该全局变量)。使用关键字Local 和Global来声明变量以强制变量的作用域是比较好的一种习惯。楼主代码的问题正是由于同名的全局变量存在,故在函数内部直接赋值而成的变量此时将视此变量为该全局变量,因而导致了冲突。
 楼主| 发表于 2012-5-15 19:10:29 | 显示全部楼层
谢谢楼上。。。。刚开始写东西就这么多坏毛病。。。
您需要登录后才可以回帖 登录 | 加入

本版积分规则

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

GMT+8, 2024-5-18 21:37 , Processed in 0.085085 second(s), 24 queries .

Powered by Discuz! X3.5 Licensed

© 2001-2024 Discuz! Team.

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