Sign in to follow this  
Followers 0
xsnow

How do I close a created gui within a gui?

5 posts in this topic

my code.

GUICreate("Checkbook Finance",200,250)
 $adddeposit=GUICtrlCreateButton ("Deposit", 65,10,70,25)
 $addwithdrawl=GUICtrlCreateButton ("Withdrawal", 65,45,70,25)
 $update=GUICtrlCreateButton ("Update Balance", 55,80,90,25)
 $test=GUICtrlCreateButton ("test", 55,110,90,25)
 $close=GUICtrlCreateButton ("Close", 65,145,70,25)
 GUICtrlCreateLabel ("Account Balance : $"&$balance, 65,175,70,75)

;then under test i run

Func test()


GUICreate(" Withdrawal Information ", 320,175)
GUICtrlCreateLabel ("Date : ", 10,5,125,25)
$date = GUICtrlCreateInput ( "Withdrawal", 135,  5, 300, 20)
GUICtrlCreateLabel ("Withdrawal Date : ", 10,35,125,25)
$name = GUICtrlCreateInput ( "Withdrawal", 135,  35, 300, 20)
GUICtrlCreateLabel ("Withdrawal Name : ", 10,35,125,25)
$amount = GUICtrlCreateInput ( "Withdrawal", 135,  65, 300, 20)
GUICtrlCreateLabel ("Withdrawal Amount : ", 10,65,125,25)
$btn = GUICtrlCreateButton ("Ok", 40,  95, 60, 20)

GUISetState () 

$msg = 0
While $msg <> $GUI_EVENT_CLOSE
       $msg = GUIGetMsg()
       Select
            Case $msg = $btn
                $msg = $GUI_EVENT_CLOSE 
                Exitloop
       EndSelect
Wend

;MsgBox (4096, "drag drop file", GUICtrlRead($name))
EndFunc

but it closes both guis

what do i need to do different?

Share this post


Link to post
Share on other sites



#include <GUIConstantsEx.au3>

GUICreate("Checkbook Finance",200,250)
$adddeposit=GUICtrlCreateButton ("Deposit", 65,10,70,25)
$addwithdrawl=GUICtrlCreateButton ("Withdrawal", 65,45,70,25)
$update=GUICtrlCreateButton ("Update Balance", 55,80,90,25)
$test=GUICtrlCreateButton ("test", 55,110,90,25)
$close=GUICtrlCreateButton ("Close", 65,145,70,25)
GUICtrlCreateLabel ("Account Balance : $", 65,175,70,75)
GUiSetState()
;then under test i run

test()

Func test()
    GUICreate(" Withdrawal Information ", 320,175)
    GUICtrlCreateLabel ("Date : ", 10,5,125,25)
    $date = GUICtrlCreateInput ( "Withdrawal", 135,  5, 300, 20)
    GUICtrlCreateLabel ("Withdrawal Date : ", 10,35,125,25)
    $name = GUICtrlCreateInput ( "Withdrawal", 135,  35, 300, 20)
    GUICtrlCreateLabel ("Withdrawal Name : ", 10,35,125,25)
    $amount = GUICtrlCreateInput ( "Withdrawal", 135,  65, 300, 20)
    GUICtrlCreateLabel ("Withdrawal Amount : ", 10,65,125,25)
    $btn = GUICtrlCreateButton ("Ok", 40,  95, 60, 20)

    GUISetState ()

    While 1
        Switch GUiGetMsg()
            Case $GUI_EVENT_CLOSE
                GUIDelete()
        EndSwitch
    Wend

;MsgBox (4096, "drag drop file", GUICtrlRead($name))
EndFunc
This is a kind of messy way to do it. I don't think you'll be able to manage both GUI at once if you do it this way. Look at the function GUICtrlSetOnEvent(), it would make your job easier.


My Programs[list][*]Knight Media Player[*]Multiple Desktops[*]Daily Comics[*]Journal[/list]

Share this post


Link to post
Share on other sites

#include <GUIConstantsEx.au3>

GUICreate("Checkbook Finance",200,250)
$adddeposit=GUICtrlCreateButton ("Deposit", 65,10,70,25)
$addwithdrawl=GUICtrlCreateButton ("Withdrawal", 65,45,70,25)
$update=GUICtrlCreateButton ("Update Balance", 55,80,90,25)
$test=GUICtrlCreateButton ("test", 55,110,90,25)
$close=GUICtrlCreateButton ("Close", 65,145,70,25)
GUICtrlCreateLabel ("Account Balance : $", 65,175,70,75)
GUiSetState()
;then under test i run

test()

Func test()
    GUICreate(" Withdrawal Information ", 320,175)
    GUICtrlCreateLabel ("Date : ", 10,5,125,25)
    $date = GUICtrlCreateInput ( "Withdrawal", 135,  5, 300, 20)
    GUICtrlCreateLabel ("Withdrawal Date : ", 10,35,125,25)
    $name = GUICtrlCreateInput ( "Withdrawal", 135,  35, 300, 20)
    GUICtrlCreateLabel ("Withdrawal Name : ", 10,35,125,25)
    $amount = GUICtrlCreateInput ( "Withdrawal", 135,  65, 300, 20)
    GUICtrlCreateLabel ("Withdrawal Amount : ", 10,65,125,25)
    $btn = GUICtrlCreateButton ("Ok", 40,  95, 60, 20)

    GUISetState ()

    While 1
        Switch GUiGetMsg()
            Case $GUI_EVENT_CLOSE
                GUIDelete()
        EndSwitch
    Wend

;MsgBox (4096, "drag drop file", GUICtrlRead($name))
EndFunc
This is a kind of messy way to do it. I don't think you'll be able to manage both GUI at once if you do it this way. Look at the function GUICtrlSetOnEvent(), it would make your job easier.
It will close but cancels my close button on my other gui.

full code for you

#include <String.au3>
#include <array.au3>
#include <file.au3>
#include <GUIConstants.au3>

Global $deposit = "C:\Documents and Settings\Parker\Desktop\BA\deposits.txt"
Global $withdrawal = "C:\Documents and Settings\Parker\Desktop\BA\withdrawals.txt"

 dim  $depositamount, $withdrawalamount, $balance, $filedeposit, $filedeposit, $line, $flag, $adddeposit, $addwithdrawl, $totaldeposits = 0, $totalwithdrawals = 0, $close, $update
 $filedeposit = FileOpen($deposit, 1)
 $filewithdrawal = FileOpen($withdrawal, 1)
 
 Balance()
 
 GUICreate("Checkbook Finance",200,250)
 $adddeposit=GUICtrlCreateButton ("Deposit", 65,10,70,25)
 $addwithdrawl=GUICtrlCreateButton ("Withdrawal", 65,45,70,25)
 $update=GUICtrlCreateButton ("Update Balance", 55,80,90,25)
 $test=GUICtrlCreateButton ("test", 55,110,90,25)
 $close=GUICtrlCreateButton ("Close", 65,145,70,25)
 GUICtrlCreateLabel ("Account Balance : $"&$balance, 65,175,70,75)
 
 GUISetState ()
 $msg = 0
 While $msg <> $GUI_EVENT_CLOSE
    $msg = GUIGetMsg()

    Select
        case $msg = $adddeposit
           Deposit()
        case $msg = $addwithdrawl
           Withdrawal()
        case $msg = $update
            Balance()
            GUICtrlCreateLabel ("Account Balance : $"&$balance, 65,175,70,75)
        case $msg = $test
            test()
        case $msg = $close
            FileClose($deposit)
            FileClose($Withdrawal)
            Exit
    EndSelect
 Wend
 
 Func Balance()
 $balance = 0
 $totaldeposits = 0
 $totalwithdrawals = 0
 $line = 0
      If Not _FileReadToArray($deposit,$line) Then
    MsgBox(4096,"Error", " Error reading log to Array    error:" & @error)
    Exit
 EndIf
 For $i = 1 to $line[0]
    $totaldeposits = $line[$i] + $totaldeposits
Next

 If Not _FileReadToArray($withdrawal,$line) Then
    MsgBox(4096,"Error", " Error reading log to Array    error:" & @error)
    Exit
 EndIf
 For $i = 1 to $line[0]
    $totalwithdrawals = $line[$i] + $totalwithdrawals
 Next
 $balance = $totaldeposits - $totalwithdrawals
 EndFunc
 
 Func Deposit()
    $depositamount = Inputbox("Deposit", "How much?")
    If @Error = 1 Then
        MsgBox(4096, "Deposit Canceled", "No Deposit Was Entered")
    Else
        If @Error = 0 Then
            $flag = Msgbox (4, "Is the information correct?", "Deposit of $"&$depositamount)
            If $flag = 6 Then
                FileWrite($deposit, $depositamount & @CRLF)
            Else
                MsgBox(4096, "Deposit Canceled", "No Deposit Was Entered")
            EndIf
        EndIf
    EndIf
 EndFunc
 
 Func Withdrawal()
    $withdrawalamount = Inputbox("Withdrawal", "How much?")
    If @Error = 1 Then
        MsgBox(4096, "Withdrawal Canceled", "No Withdrawal Was Entered")
    Else
        If @Error = 0 Then
        $flag = Msgbox (4, "Is the information correct?", "Withdrawal of $"&$withdrawalamount)
            If $flag = 6 Then
                FileWrite($withdrawal, $withdrawalamount & @CRLF)
            Else
                MsgBox(4096, "Withdrawal Canceled", "No Withdrawal Was Entered")
            EndIf
        EndIf   
    EndIf
EndFunc

Func test()


GUICreate(" Withdrawal Information ", 320,175)
GUICtrlCreateLabel ("Date : ", 10,5,125,25)
$date = GUICtrlCreateInput ( "Withdrawal", 135,  5, 300, 20)
GUICtrlCreateLabel ("Withdrawal Date : ", 10,35,125,25)
$name = GUICtrlCreateInput ( "Withdrawal", 135,  35, 300, 20)
GUICtrlCreateLabel ("Withdrawal Name : ", 10,35,125,25)
$amount = GUICtrlCreateInput ( "Withdrawal", 135,  65, 300, 20)
GUICtrlCreateLabel ("Withdrawal Amount : ", 10,65,125,25)
$btn = GUICtrlCreateButton ("Ok", 40,  95, 60, 20)

GUISetState ()

    While 1
        Switch GUiGetMsg()
            Case $GUI_EVENT_CLOSE
                GUIDelete()
        EndSwitch
    Wend

;MsgBox (4096, "drag drop file", GUICtrlRead($name))
EndFunc

I'll look over it at work a bit, don't have AI there but i'll see what I can dig through on the forums

Share this post


Link to post
Share on other sites

#4 ·  Posted (edited)

If not for functional purposes, then for clarity/documentation purposes, I'd think you'd be wanting to assign the handle/object returned by your GUICreate calls to program variables to make it clear what is the target of your GUIDelete.

$GUI_Checkbook = GUICreate("Checkbook Finance",200,250)
$GUI_Withdrawal = GUICreate(" Withdrawal Information ", 320,175)
GUIDelete($GUI_Withdrawal)

Edit:

I chopped it up a little, hope you don't mind. Might give you something to play with (I just did what I'd mentioned above, and split up your balance label and disabled your main gui until the secondary is closed):

#include <String.au3>
#include <array.au3>
#include <file.au3>
#include <GUIConstants.au3>

Global $deposit = "C:\Documents and Settings\Parker\Desktop\BA\deposits.txt"
Global $withdrawal = "C:\Documents and Settings\Parker\Desktop\BA\withdrawals.txt"

dim  $depositamount, $withdrawalamount, $balance, $filedeposit, $filedeposit, $line, $flag, $adddeposit, $addwithdrawl, $totaldeposits = 0, $totalwithdrawals = 0, $close, $update
dim $GUI_Withdrawal, $Label_Balance, $btn

$GUI_Checkbook = GUICreate("Checkbook Finance",200,250)
$adddeposit=GUICtrlCreateButton ("Deposit", 65,10,70,25)
$addwithdrawl=GUICtrlCreateButton ("Withdrawal", 65,45,70,25)
$update=GUICtrlCreateButton ("Update Balance", 55,80,90,25)
$test=GUICtrlCreateButton ("test", 55,110,90,25)
$close=GUICtrlCreateButton ("Close", 65,145,70,25)
GUICtrlCreateLabel ("Account Balance: $", 30,192,96,20)
$Label_Balance = GUICtrlCreateLabel ($balance, 128,192,80,20)
GUISetState ()

$filedeposit = FileOpen($deposit, 1)
$filewithdrawal = FileOpen($withdrawal, 1)
Balance()

;--------------------------------------------------------------------------------------
While 1
    $msg = GUIGetMsg()
    Switch $msg
        case $adddeposit
           Deposit()
        case $addwithdrawl
            Withdrawal()
        case $update
            Balance()
        case $test
            test()
        Case $close, $GUI_EVENT_CLOSE
            ExitLoop
    EndSwitch
Wend
Exit

;--------------------------------------------------------------------------------------
Func Balance()
$balance = 0
$totaldeposits = 0
$totalwithdrawals = 0
$line = 0
      If Not _FileReadToArray($deposit,$line) Then
    MsgBox(4096,"Error", " Error reading log to Array    error:" & @error)
    Exit
EndIf
For $i = 1 to $line[0]
    $totaldeposits += $line[$i]
Next

If Not _FileReadToArray($withdrawal,$line) Then
    MsgBox(4096,"Error", " Error reading log to Array    error:" & @error)
    Exit
EndIf
For $i = 1 to $line[0]
    $totalwithdrawals += $line[$i]
Next
$balance = $totaldeposits - $totalwithdrawals
GUICtrlSetData($Label_Balance, $balance)
EndFunc

;--------------------------------------------------------------------------------------
Func Deposit()
    $depositamount = Inputbox("Deposit", "How much?")
    If @Error = 1 Then
        MsgBox(4096, "Deposit Canceled", "No Deposit Was Entered")
    Else
        If @Error = 0 Then
            $flag = Msgbox (4, "Is the information correct?", "Deposit of $"&$depositamount)
            If $flag = 6 Then
                FileWrite($deposit, $depositamount & @CRLF)
            Else
                MsgBox(4096, "Deposit Canceled", "No Deposit Was Entered")
            EndIf
        EndIf
    EndIf
EndFunc

;--------------------------------------------------------------------------------------
Func Withdrawal()
    $withdrawalamount = Inputbox("Withdrawal", "How much?")
    If @Error = 1 Then
        MsgBox(4096, "Withdrawal Canceled", "No Withdrawal Was Entered")
    Else
        If @Error = 0 Then
        $flag = Msgbox (4, "Is the information correct?", "Withdrawal of $"&$withdrawalamount)
            If $flag = 6 Then
                FileWrite($withdrawal, $withdrawalamount & @CRLF)
            Else
                MsgBox(4096, "Withdrawal Canceled", "No Withdrawal Was Entered")
            EndIf
        EndIf   
    EndIf
EndFunc

;--------------------------------------------------------------------------------------
Func test()
    GUISetState(@SW_DISABLE,$GUI_Checkbook)
    $GUI_Withdrawal = GUICreate(" Withdrawal Information ", 320,175)
    GUICtrlCreateLabel ("Date : ", 10,5,125,25)
    $date = GUICtrlCreateInput ( "Withdrawal", 135,  5, 300, 20)
    GUICtrlCreateLabel ("Withdrawal Date : ", 10,35,125,25)
    $name = GUICtrlCreateInput ( "Withdrawal", 135,  35, 300, 20)
    GUICtrlCreateLabel ("Withdrawal Name : ", 10,35,125,25)
    $amount = GUICtrlCreateInput ( "Withdrawal", 135,  65, 300, 20)
    GUICtrlCreateLabel ("Withdrawal Amount : ", 10,65,125,25)
    $btn = GUICtrlCreateButton ("Ok", 40,  95, 60, 20)
    GUISetState ()

    While 1
        Switch GUiGetMsg()
            Case $btn, $GUI_EVENT_CLOSE
                GUISetState(@SW_ENABLE,$GUI_Checkbook)
                GUIDelete($GUI_Withdrawal)
                ExitLoop
        EndSwitch
    Wend

;   MsgBox (4096, "drag drop file", GUICtrlRead($name))
EndFunc
Edited by Spiff59

Share this post


Link to post
Share on other sites

ok that works quite well.

I see you did a few things different than I had them which is a good thing.

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