Sign in to follow this  
Followers 0
TSO

GUICtrlDelete question

10 posts in this topic

Simple enough probably, but my GUICtrlDelete isn't closing the form. See anything wrong here?

While 1
    $nMsg = GUIGetMsg()
    Switch $nMsg
        Case $GUI_EVENT_CLOSE
            Exit
     EndSwitch
Select
        Case $nMsg = $RButton2; This is a Cancel Button and I want it to close the form, but it does nothing and the form remains open
    GUICtrlDelete($Form2)
    Case $nMsg = $RButton1 AND GUICtrlRead($RInput1) = ""
    MsgBox(0, "Please Input Tag Number", "Please provide the tag number of the old computer")
    Case $nMsg = $RButton1
    RegWrite("HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows NT\CurrentVersion", "RefreshTag", "REG_SZ", GUICtrlRead($RInput1))
    MsgBox(0, "Updated", "Refresh information has been updated, click OK to exit")
    Exit
        EndSelect
WEnd

Share this post


Link to post
Share on other sites



GUICtrlDelete - Delete's a Control not a GUI !

Use GUIDelete

Share this post


Link to post
Share on other sites

GUICtrlDelete - Delete's a Control not a GUI !

Use GUIDelete

Doh.. yeah it worked, except after I use it to close $Form2, the buttons (Cases) in $Form1 stop working :-X

Share this post


Link to post
Share on other sites

Doh.. yeah it worked, except after I use it to close $Form2, the buttons (Cases) in $Form1 stop working :-X

Can you show the code, or a sample that shows the problem?

Serial port communications UDF Includes functions for binary transmission and reception.printing UDF Useful for graphs, forms, labels, reports etc.Add User Call Tips to SciTE for functions in UDFs not included with AutoIt and for your own scripts.Functions with parameters in OnEvent mode and for Hot Keys One function replaces GuiSetOnEvent, GuiCtrlSetOnEvent and HotKeySet.UDF IsConnected2 for notification of status of connected state of many urls or IPs, without slowing the script.

Share this post


Link to post
Share on other sites

Doh.. yeah it worked, except after I use it to close $Form2, the buttons (Cases) in $Form1 stop working :-X

As Martin wrote, post more of the relevant code it will save you and us a lot of back and forth.

In the meanwhile check the help file for GUIswitch

Example:

#include <GUIConstantsEx.au3>

Opt('MustDeclareVars', 1)

Example()

Func Example()
    Local $parent1, $parent2, $tabitem, $msg
   
    $parent1 = GUICreate("Parent1")
    GUICtrlCreateTab(10, 10)
    $tabitem = GUICtrlCreateTabItem("tab1")
    GUICtrlCreateTabItem("tab2")
    GUICtrlCreateTabItem("")

    $parent2 = GUICreate("Parent2", -1, -1, 100, 100)

    GUISwitch($parent2)
    GUISetState()
    Do
        $msg = GUIGetMsg()
    Until $msg = $GUI_EVENT_CLOSE

    GUISwitch($parent1, $tabitem)
    GUICtrlCreateButton("OK", 50, 50, 50)
    GUICtrlCreateTabItem("")

    GUISetState(@SW_SHOW, $parent1)
    Do
        $msg = GUIGetMsg()
    Until $msg = $GUI_EVENT_CLOSE
EndFunc  ;==>Example

Share this post


Link to post
Share on other sites

#6 ·  Posted (edited)

Can you show the code, or a sample that shows the problem?

This is the entire script...

I believe the problem probably has something to do with maybe the way I'm launching $Form2, or the position I put it in or something... The pertinent part of the code is probably around GUIDelete($Form2)

; AutoIt Version: 3.x
; Language:    English
; Platform:    Win 2000/XP
; Author:        xxx
;
; Script Function:
;   This script will use technician interface to populate the 'Registered Organization' Windows registry key
;   with the support organization determined to be appropriate for the computer the script is run on.
;    The result of this populated key will be a notation under 'My Computer' properties, and the ability
;    for the computer's designated support group to be inventoried by Altiris.

$objWMIService = ObjGet("winmgmts:{impersonationLevel=impersonate}!\\.\root\cimv2")
$colSMBIOS = $objWMIService.ExecQuery ("Select * from Win32_SystemEnclosure")
$wmi = ObjGet("winmgmts:")
$wql = "select * from win32_computersystem"
$results = $wmi.execquery($wql)
$secStat = RegRead("HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows NT\CurrentVersion", "AssignedSector")
$busStat = RegRead("HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows NT\CurrentVersion", "AssignedBusinessUnit")
$supStat = RegRead("HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows NT\CurrentVersion", "AssignedSupportGroup")

If $secStat = "" Then
    $secStat = "Undefined"
EndIf
If $busStat = "" Then
    $busStat = "Undefined"
EndIf
If $supStat = "" Then
    $supStat = "Undefined"
EndIf

For $objSMBIOS in $colSMBIOS
;ConsoleWrite("Serial Number: " & $objSMBIOS.SerialNumber & @CRLF)
;ConsoleWrite("Asset Tag: " & $objSMBIOS.SMBIOSAssetTag & @CRLF)
Next

For $compsys in $results
  ConsoleWrite("Domain:  " & $compsys.domain & @CRLF)
Next

#include <GUIConstants.au3>

#Region ### START Koda GUI section ### Form=C:\Documents and Settings\s830829\Desktop\koda_1.7.0.1\Forms\EUSGUI3.kxf

$Form1 = GUICreate("RoS", 332, 470, 214, 139)
$Label1 = GUICtrlCreateLabel("Select Business Unit:", 144, 224, 130, 17)
GUICtrlSetFont(-1, 8, 800, 0, "MS Sans Serif")
$Label2 = GUICtrlCreateLabel("Select Sector:", 144, 168, 85, 17)
GUICtrlSetFont(-1, 8, 800, 0, "MS Sans Serif")
$Label3 = GUICtrlCreateLabel("Select Support Group:", 144, 280, 130, 17)
GUICtrlSetFont(-1, 8, 800, 0, "MS Sans Serif")
$Group2 = GUICtrlCreateGroup("Change Service:", 136, 144, 185, 185)
GUICtrlSetFont(-1, 8, 800, 0, "MS Sans Serif")
GUICtrlCreateGroup("", -99, -99, 1, 1)
$Label7 = GUICtrlCreateLabel("Redirection of Service", 75, 0, 180, 25)
GUICtrlSetFont(-1, 12, 800, 4, "Arial Unicode MS")
GUICtrlSetColor(-1, 0x000080)
$Button1 = GUICtrlCreateButton("Change", 32, 424, 115, 33, 0)
$Button2 = GUICtrlCreateButton("Cancel", 184, 424, 115, 33, 0)
$Label4 = GUICtrlCreateLabel("Support Group:", 16, 280, 90, 17)
GUICtrlSetFont(-1, 8, 800, 0, "MS Sans Serif")
$Label5 = GUICtrlCreateLabel("Sector:", 16, 168, 45, 17)
GUICtrlSetFont(-1, 8, 800, 0, "MS Sans Serif")
$Label6 = GUICtrlCreateLabel("Business Unit:", 16, 224, 85, 17)
GUICtrlSetFont(-1, 8, 800, 0, "MS Sans Serif")
$Group1 = GUICtrlCreateGroup("Current Status:", 8, 144, 121, 185)
GUICtrlSetFont(-1, 8, 800, 0, "MS Sans Serif")
GUICtrlCreateGroup("", -99, -99, 1, 1)
$secInf = GUICtrlCreateInput($secStat, 16, 184, 105, 21, $ES_READONLY)
GUICtrlSetBkColor(-1, 0xE1E0D2)
$busInf = GUICtrlCreateInput($busStat, 16, 240, 105, 21, $ES_READONLY)
GUICtrlSetBkColor(-1, 0xE1E0D2)
$supInf = GUICtrlCreateInput($supStat, 16, 296, 105, 21, $ES_READONLY)
GUICtrlSetBkColor(-1, 0xE1E0D2)
$Label8 = GUICtrlCreateLabel("Host Name:", 72, 64, 70, 17)
GUICtrlSetFont(-1, 8, 800, 0, "MS Sans Serif")
$Label9 = GUICtrlCreateLabel("Domain:", 88, 88, 50, 17)
GUICtrlSetFont(-1, 8, 800, 0, "MS Sans Serif")
$Label10 = GUICtrlCreateLabel("Serial Number:", 56, 112, 87, 17)
GUICtrlSetFont(-1, 8, 800, 0, "MS Sans Serif")
$hostName = GUICtrlCreateInput(@ComputerName, 152, 56, 121, 21, $ES_READONLY)
GUICtrlSetBkColor(-1, 0xE1E0D2)
$Domain = GUICtrlCreateInput($compsys.domain, 152, 80, 121, 21, $ES_READONLY)
GUICtrlSetBkColor(-1, 0xE1E0D2)
$sNum = GUICtrlCreateInput($objSMBIOS.SerialNumber, 152, 104, 121, 21, $ES_READONLY)
GUICtrlSetBkColor(-1, 0xE1E0D2)
$Group3 = GUICtrlCreateGroup("This Computer Information:", 48, 32, 233, 105)
GUICtrlSetFont(-1, 8, 800, 0, "MS Sans Serif")
$Radio1 = GUICtrlCreateRadio("New Deployment", 56, 368, 113, 17)
$Radio2 = GUICtrlCreateRadio("Refresh Upgrade", 56, 384, 113, 17)
$Radio3 = GUICtrlCreateRadio("Asset Removal", 176, 368, 97, 17)
$Radio4 = GUICtrlCreateRadio("Existing Asset", 176, 384, 97, 17)
$Group4 = GUICtrlCreateGroup("This Computer is a...", 48, 344, 233, 65)
GUICtrlSetFont(-1, 8, 800, 0, "MS Sans Serif")
GUICtrlCreateGroup("", -99, -99, 1, 1)
GUISetState(@SW_SHOW)
$Combo1 = GUICtrlCreateCombo("", 144, 184, 97, 200,BitOR($CBS_DROPDOWNLIST, $WS_VSCROLL))
GUICtrlSetData($Combo1, "SECTOR1|SECTOR2|SECTOR3")
$Combo3 = GUICtrlCreateCombo("", 144, 296, 161, 200,BitOR($CBS_DROPDOWNLIST, $WS_VSCROLL))
GUICtrlSetData($Combo3, "SUPPORT1|SUPPORT2|SUPPORT3")
$Combo2 = GUICtrlCreateCombo("", 144, 240, 161, 200,BitOR($CBS_DROPDOWNLIST, $WS_VSCROLL))
GUICtrlSetData($Combo2, "BUSINESS1|BUSINESS2|BUSINESS3")

While 1
    $nMsg = GUIGetMsg()
    Switch $nMsg
        Case $GUI_EVENT_CLOSE
            Exit

    EndSwitch
Select
    Case $nMsg = $Button2
    Exit
    Case $nMsg = $Button1 AND GUICtrlRead($Combo1) = "" 
    MsgBox(0, "Information Required", "Please choose a Sector")
    Case $nMsg = $Button1 AND NOT (GUICtrlRead($Radio1) = $GUI_CHECKED OR GUICtrlRead($Radio2) = $GUI_CHECKED OR GUICtrlRead($Radio3) = $GUI_CHECKED OR GUICtrlRead($Radio4) = $GUI_CHECKED)
    MsgBox(0, "Select Update Type", "Please select an update type")
    Case $nMsg = $Button1 AND GUICtrlRead($Radio2) = $GUI_CHECKED
    RegWrite("HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows NT\CurrentVersion", "RegisteredOrganization", "REG_SZ", GUICtrlRead($Combo3))
    RegWrite("HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows NT\CurrentVersion", "AssignedSupportGroup", "REG_SZ", GUICtrlRead($Combo3))
    RegWrite("HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows NT\CurrentVersion", "AssignedBusinessUnit", "REG_SZ", GUICtrlRead($Combo2))
    RegWrite("HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows NT\CurrentVersion", "AssignedSector", "REG_SZ", GUICtrlRead($Combo1))
    $Form2 = GUICreate("Insert Old Tag #", 259, 113, 267, 272)
    $RLabel1 = GUICtrlCreateLabel("Please provide FULL asset tag of the OLD computer", 8, 8, 240, 17)
    $RInput1 = GUICtrlCreateInput("", 48, 48, 161, 21)
    $RButton1 = GUICtrlCreateButton("OK", 40, 80, 75, 25, 0)
    $RButton2 = GUICtrlCreateButton("Cancel", 144, 80, 75, 25, 0)
    $RLabel2 = GUICtrlCreateLabel("(Example: ITE0001234)", 64, 24, 115, 17)
    GUISetState(@SW_SHOW)
While 1
    $nMsg = GUIGetMsg()
    Switch $nMsg
        Case $GUI_EVENT_CLOSE
            Exit

    EndSwitch

Select
    Case $nMsg = $RButton1 AND GUICtrlRead($RInput1) = ""
    MsgBox(0, "Please Input Tag Number", "Please provide the tag number of the old computer")
    Case $nMsg = $RButton1
    RegWrite("HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows NT\CurrentVersion", "RefreshTag", "REG_SZ", GUICtrlRead($RInput1))
    MsgBox(0, "Updated", "Refresh information has been updated, click OK to exit")
    Exit
    Case $nMsg = $RButton2
    GUIDelete($Form2)
    
        EndSelect
WEnd
    
    Case $nMsg = $Button1 AND GUICtrlRead($Radio3) = $GUI_CHECKED
    RegWrite("HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows NT\CurrentVersion", "RegisteredOrganization", "REG_SZ", "Asset Removed")
    RegWrite("HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows NT\CurrentVersion", "AssignedSupportGroup", "REG_SZ", "Asset Removed")
    RegWrite("HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows NT\CurrentVersion", "AssignedBusinessUnit", "REG_SZ", "Asset Removed")
    RegWrite("HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows NT\CurrentVersion", "AssignedSector", "REG_SZ", "Asset Removed")
    MsgBox(0, "Updated", "This computer has been removed from the database, click OK to exit")
    Exit
    Case $nMsg = $Button1
    RegWrite("HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows NT\CurrentVersion", "RegisteredOrganization", "REG_SZ", GUICtrlRead($Combo3))
    RegWrite("HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows NT\CurrentVersion", "AssignedSupportGroup", "REG_SZ", GUICtrlRead($Combo3))
    RegWrite("HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows NT\CurrentVersion", "AssignedBusinessUnit", "REG_SZ", GUICtrlRead($Combo2))
    RegWrite("HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows NT\CurrentVersion", "AssignedSector", "REG_SZ", GUICtrlRead($Combo1))
    MsgBox(0, "Updated", "Support information has been updated, click OK to exit")
    Exit


       EndSelect
WEnd
#EndRegion ### END Koda GUI section ###
Edited by TSO

Share this post


Link to post
Share on other sites

When you create a button in form1 it has the reference $button1. That reference is destroyed as far as form1 is concerned because you then set $button1 to the button created in form2.

So you need to give different variable names to the different controls, otherwise when you loose a control you loose control!


Serial port communications UDF Includes functions for binary transmission and reception.printing UDF Useful for graphs, forms, labels, reports etc.Add User Call Tips to SciTE for functions in UDFs not included with AutoIt and for your own scripts.Functions with parameters in OnEvent mode and for Hot Keys One function replaces GuiSetOnEvent, GuiCtrlSetOnEvent and HotKeySet.UDF IsConnected2 for notification of status of connected state of many urls or IPs, without slowing the script.

Share this post


Link to post
Share on other sites

When you create a button in form1 it has the reference $button1. That reference is destroyed as far as form1 is concerned because you then set $button1 to the button created in form2.

So you need to give different variable names to the different controls, otherwise when you loose a control you loose control!

No, I created $Button1 for $Form1 and $RButton1 for $Form2.... Shouldn't the 'R' be enough to make it unique?

Share this post


Link to post
Share on other sites

#9 ·  Posted (edited)

No, I created $Button1 for $Form1 and $RButton1 for $Form2.... Shouldn't the 'R' be enough to make it unique?

So you did, reading has never been a strong point for me. Apologies.

Does this fix it?

$canc = False;<---------------added
            While 1
                $nMsg = GUIGetMsg()
                Switch $nMsg
                    Case $GUI_EVENT_CLOSE
                        Exit

                EndSwitch

                Select
                    Case $nMsg = $RButton1 And GUICtrlRead($RInput1) = ""
                        MsgBox(0, "Please Input Tag Number", "Please provide the tag number of the old computer")
                    Case $nMsg = $RButton1
                        RegWrite("HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows NT\CurrentVersion", "RefreshTag", "REG_SZ", GUICtrlRead($RInput1))
                        MsgBox(0, "Updated", "Refresh information has been updated, click OK to exit")
                        Exit
                    Case $nMsg = $RButton2
                        $canc = True;<------------------------added
                        GUIDelete($Form2)

                EndSelect
                If $canc Then ExitLoop;<-----------------------added
            WEnd
    ;GUIDelete($Form2)
            GUISwitch($Form1);<-----------------------------------added
        Case $nMsg = $Button1 And GUICtrlRead($Radio3) = $GUI_CHECKED
Edited by martin

Serial port communications UDF Includes functions for binary transmission and reception.printing UDF Useful for graphs, forms, labels, reports etc.Add User Call Tips to SciTE for functions in UDFs not included with AutoIt and for your own scripts.Functions with parameters in OnEvent mode and for Hot Keys One function replaces GuiSetOnEvent, GuiCtrlSetOnEvent and HotKeySet.UDF IsConnected2 for notification of status of connected state of many urls or IPs, without slowing the script.

Share this post


Link to post
Share on other sites

So you did, reading has never been a strong point for me. Apologies.

Does this fix it?

$canc = False;<---------------added
            While 1
                $nMsg = GUIGetMsg()
                Switch $nMsg
                    Case $GUI_EVENT_CLOSE
                        Exit

                EndSwitch

                Select
                    Case $nMsg = $RButton1 And GUICtrlRead($RInput1) = ""
                        MsgBox(0, "Please Input Tag Number", "Please provide the tag number of the old computer")
                    Case $nMsg = $RButton1
                        RegWrite("HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows NT\CurrentVersion", "RefreshTag", "REG_SZ", GUICtrlRead($RInput1))
                        MsgBox(0, "Updated", "Refresh information has been updated, click OK to exit")
                        Exit
                    Case $nMsg = $RButton2
                        $canc = True;<------------------------added
                        GUIDelete($Form2)

                EndSelect
                If $canc Then ExitLoop;<-----------------------added
            WEnd
;GUIDelete($Form2)
            GUISwitch($Form1);<-----------------------------------added
        Case $nMsg = $Button1 And GUICtrlRead($Radio3) = $GUI_CHECKED
Okay... now I'm going to spend the next half hour trying to figure out how that fixed it, but most importantly, it fixed it!

Learning programming on the fly is surrrus bidniss :-X

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!


Register a new account

Sign in

Already have an account? Sign in here.


Sign In Now
Sign in to follow this  
Followers 0