Jump to content

Passing A variable from one window to another


pillbug
 Share

Recommended Posts

Hi,

I'm having trouble with this code. I want to be able to pass some information I type of the first window, and have it display on the next. When I hit forward the first time, I get a 0. However, if I hit back, type text, and then hit forward, the text now appears.

#include <GUIConstantsEx.au3>
#include <WindowsConstants.au3>

Opt("GUIOnEventMode", 1) ; Change to OnEvent mode

Global $window[3]; Make room for three elements
Global $windpos=0; Window positions I am on
$sizex=@DesktopWidth*.7
$sizey=@DesktopHeight*.7
$title="Automated Auction Template"
Global $name =""

WINCreate($windpos)
GUISetState()
$name=GUICtrlRead($name)

While 1
  Sleep(1000) ; Idle around
WEnd

Func WINCreate($windpos)
Select
    Case $windpos=0
    $window[0] = GUICreate($title, $sizex, $sizey, -1, 0x00000018)
    GUICtrlCreateLabel("Samplescript", 30, 10)
Global $name=GUICtrlCreateInput($name, 10, 5, 300, 20)
GUICtrlSetState(-1, $GUI_DROPACCEPTED)

    
GUISetOnEvent($GUI_EVENT_CLOSE, "CLOSEClicked")
$forwardbutton = GUICtrlCreateButton("FORWARD>", $sizex/2+20, $sizey-50, 80)
GUICtrlSetOnEvent($forwardbutton, "FWRDButton")


Case $windpos=1
$window[1] = GUICreate($title, $sizex, $sizey, -1, 0x00000018)
AllControls()
GUICtrlCreateLabel($name, 30, 10)


Case $windpos=2
$window[2] = GUICreate($title, $sizex, $sizey, -1, 0x00000018)
AllControls()
msgbox(0,"","")
EndSelect
EndFunc

Func AllControls()
GUISetOnEvent($GUI_EVENT_CLOSE, "CLOSEClicked")
$forwardbutton = GUICtrlCreateButton("FORWARD>", $sizex/2+20, $sizey-50, 80)
GUICtrlSetOnEvent($forwardbutton, "FWRDButton")
$backbutton = GUICtrlCreateButton("<BACK", $sizex/2-100, $sizey-50, 80)
GUICtrlSetOnEvent($backbutton, "BCKButton")

EndFunc


Func FWRDButton()
    $name=GUICtrlRead($name)
    GUISetState(@SW_HIDE)
    $windpos=$windpos+1
    WINCreate($windpos)
    GUISwitch($window[$windpos])
    GUISetState(@SW_SHOW); When created, windows are hidden, so we show them when we want them

EndFunc

Func BCKButton()
    $name=GUICtrlRead($name)
    GUISetState(@SW_HIDE)
    $windpos=$windpos-1
    WINCreate($windpos)
    GUISwitch($window[$windpos])
    GUISetState(@SW_SHOW); When created, windows are hidden, so we show them when we want them
EndFunc

Func CLOSEClicked()
Exit
EndFunc
Link to comment
Share on other sites

The main problem is that you have declared $name as global in two places. You should have a different variable for the edit and the text.

The window style 0x18 I assume is to have the extended styles $WS_EX_ACCEPTFILES and $WS_EX_TOPMOST, but you had some parameters missing.

But there is another problem which is that I you might not be doing what you think with your script. Or maybe I am assuming the wrong intention. In the code below I have made it work, but I also stopped the windows from being hidden so you can see what is happening. (I also made them a bit smaller and offset each new one.)

#include <GUIConstantsEx.au3>
#include <WindowsConstants.au3>

Opt("GUIOnEventMode", 1); Change to OnEvent mode

Global $window[3]; Make room for three elements
Global $windpos = 0; Window positions I am on
$sizex = @DesktopWidth /2;* .7
$sizey = @DesktopHeight/2; * .7
$title = "Automated Auction Template"
Global $name = "",$nameA
Global $shiftx=0,$shifty=0
WINCreate($windpos)
GUISetState()
$name = GUICtrlRead($name)

While 1
    Sleep(1000); Idle around
WEnd

Func WINCreate($windpos)
    ConsoleWrite($windpos & @CRLF)
    Select
        Case $windpos = 0
            $window[0] = GUICreate($title, $sizex, $sizey, $shiftx,$shifty,-1, BitOR($WS_EX_ACCEPTFILES,$WS_EX_TOPMOST));, 0x00000018);accepot files , topmost
            GUICtrlCreateLabel("Samplescript", 30, 10)
            $nameA = GUICtrlCreateInput($name, 10, 5, 300, 20)
            GUICtrlSetState(-1, $GUI_DROPACCEPTED)


            GUISetOnEvent($GUI_EVENT_CLOSE, "CLOSEClicked")
            $forwardbutton = GUICtrlCreateButton("FORWARD>", $sizex / 2 + 20, $sizey - 50, 80)
            GUICtrlSetOnEvent($forwardbutton, "FWRDButton")


        Case $windpos = 1
            ConsoleWrite("in case 1, $name = " & $name & @CRLF)
            $window[1] = GUICreate($title, $sizex, $sizey,$shiftx,$shifty,-1, BitOR($WS_EX_ACCEPTFILES,$WS_EX_TOPMOST));, 0x00000018)
            AllControls()
            GUICtrlCreateLabel($name, 30, 10)


        Case $windpos = 2
            $window[2] = GUICreate($title, $sizex, $sizey,$shiftx,$shifty,-1, BitOR($WS_EX_ACCEPTFILES,$WS_EX_TOPMOST));, 0x00000018)
            AllControls()
            MsgBox(0, "", "")
    EndSelect
    $shiftx += 50
    $shifty = 50
EndFunc  ;==>WINCreate

Func AllControls()
    GUISetOnEvent($GUI_EVENT_CLOSE, "CLOSEClicked")
    $forwardbutton = GUICtrlCreateButton("FORWARD>", $sizex / 2 + 20, $sizey - 50, 80)
    GUICtrlSetOnEvent($forwardbutton, "FWRDButton")
    $backbutton = GUICtrlCreateButton("<BACK", $sizex / 2 - 100, $sizey - 50, 80)
    GUICtrlSetOnEvent($backbutton, "BCKButton")

EndFunc  ;==>AllControls


Func FWRDButton()
    $name = GUICtrlRead($nameA)
    ConsoleWrite($name & @CRLF)
;GUISetState(@SW_HIDE)
    $windpos = $windpos + 1
    WINCreate($windpos)
    GUISwitch($window[$windpos])
    GUISetState(@SW_SHOW); When created, windows are hidden, so we show them when we want them

EndFunc  ;==>FWRDButton

Func BCKButton()
    $name = GUICtrlRead($name)
;GUISetState(@SW_HIDE)
    $windpos = $windpos - 1
    WINCreate($windpos)
    GUISwitch($window[$windpos])
    GUISetState(@SW_SHOW); When created, windows are hidden, so we show them when we want them
EndFunc  ;==>BCKButton

Func CLOSEClicked()
    Exit
EndFunc  ;==>CLOSEClicked
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.
Link to comment
Share on other sites

The main problem is that you have declared $name as global in two places. You should have a different variable for the edit and the text.

The window style 0x18 I assume is to have the extended styles $WS_EX_ACCEPTFILES and $WS_EX_TOPMOST, but you had some parameters missing.

But there is another problem which is that I you might not be doing what you think with your script. Or maybe I am assuming the wrong intention. In the code below I have made it work, but I also stopped the windows from being hidden so you can see what is happening. (I also made them a bit smaller and offset each new one.)

#include <GUIConstantsEx.au3>
#include <WindowsConstants.au3>

Opt("GUIOnEventMode", 1); Change to OnEvent mode

Global $window[3]; Make room for three elements
Global $windpos = 0; Window positions I am on
$sizex = @DesktopWidth /2;* .7
$sizey = @DesktopHeight/2; * .7
$title = "Automated Auction Template"
Global $name = "",$nameA
Global $shiftx=0,$shifty=0
WINCreate($windpos)
GUISetState()
$name = GUICtrlRead($name)

While 1
    Sleep(1000); Idle around
WEnd

Func WINCreate($windpos)
    ConsoleWrite($windpos & @CRLF)
    Select
        Case $windpos = 0
            $window[0] = GUICreate($title, $sizex, $sizey, $shiftx,$shifty,-1, BitOR($WS_EX_ACCEPTFILES,$WS_EX_TOPMOST));, 0x00000018);accepot files , topmost
            GUICtrlCreateLabel("Samplescript", 30, 10)
            $nameA = GUICtrlCreateInput($name, 10, 5, 300, 20)
            GUICtrlSetState(-1, $GUI_DROPACCEPTED)


            GUISetOnEvent($GUI_EVENT_CLOSE, "CLOSEClicked")
            $forwardbutton = GUICtrlCreateButton("FORWARD>", $sizex / 2 + 20, $sizey - 50, 80)
            GUICtrlSetOnEvent($forwardbutton, "FWRDButton")


        Case $windpos = 1
            ConsoleWrite("in case 1, $name = " & $name & @CRLF)
            $window[1] = GUICreate($title, $sizex, $sizey,$shiftx,$shifty,-1, BitOR($WS_EX_ACCEPTFILES,$WS_EX_TOPMOST));, 0x00000018)
            AllControls()
            GUICtrlCreateLabel($name, 30, 10)


        Case $windpos = 2
            $window[2] = GUICreate($title, $sizex, $sizey,$shiftx,$shifty,-1, BitOR($WS_EX_ACCEPTFILES,$WS_EX_TOPMOST));, 0x00000018)
            AllControls()
            MsgBox(0, "", "")
    EndSelect
    $shiftx += 50
    $shifty = 50
EndFunc ;==>WINCreate

Func AllControls()
    GUISetOnEvent($GUI_EVENT_CLOSE, "CLOSEClicked")
    $forwardbutton = GUICtrlCreateButton("FORWARD>", $sizex / 2 + 20, $sizey - 50, 80)
    GUICtrlSetOnEvent($forwardbutton, "FWRDButton")
    $backbutton = GUICtrlCreateButton("<BACK", $sizex / 2 - 100, $sizey - 50, 80)
    GUICtrlSetOnEvent($backbutton, "BCKButton")

EndFunc ;==>AllControls


Func FWRDButton()
    $name = GUICtrlRead($nameA)
    ConsoleWrite($name & @CRLF)
;GUISetState(@SW_HIDE)
    $windpos = $windpos + 1
    WINCreate($windpos)
    GUISwitch($window[$windpos])
    GUISetState(@SW_SHOW); When created, windows are hidden, so we show them when we want them

EndFunc ;==>FWRDButton

Func BCKButton()
    $name = GUICtrlRead($name)
;GUISetState(@SW_HIDE)
    $windpos = $windpos - 1
    WINCreate($windpos)
    GUISwitch($window[$windpos])
    GUISetState(@SW_SHOW); When created, windows are hidden, so we show them when we want them
EndFunc ;==>BCKButton

Func CLOSEClicked()
    Exit
EndFunc ;==>CLOSEClicked
Thank you for this help.

I'm going to make some modifications.

Also, what does @CRLF mean? I looked it up and it says it is @CR & @LF ;occasionally used for line breaks. So carriage returns and line breaks? What does that do?

Link to comment
Share on other sites

I figured out what @CRLF does

I also improved the code. Thanks for the help again

#include <GUIConstantsEx.au3>
#include <WindowsConstants.au3>


Opt("GUIOnEventMode", 1); Change to OnEvent mode

Global $window[3]; Make room for three elements
Global $windpos = 0; Window position I am on
$sizex = @DesktopWidth /2;* .7
$sizey = @DesktopHeight/2; * .7
$title = "Automated Auction Template"
;$start=1; If Beginning with a blank slate
Global $name = "", $nameA
Global $shiftx=0,$shifty=0


WINCreate($windpos)
GUISetState()

While 1
    Sleep(1000)
WEnd

Func WINCreate($windpos)
   
    Select
        Case $windpos = 0
            $window[0] = GUICreate($title, $sizex, $sizey, $shiftx,$shifty,-1, BitOR($WS_EX_ACCEPTFILES,$WS_EX_TOPMOST))
             GUICtrlCreateLabel("What window are you on:" & $windpos, 20, 100);ConsoleWrite($windpos & @CRLF)
            $nameA = GUICtrlCreateInput($name, 10, 5, 300, 20)
            GUICtrlSetState(-1, $GUI_DROPACCEPTED)
            
            GUISetOnEvent($GUI_EVENT_CLOSE, "CLOSEClicked")
            $forwardbutton = GUICtrlCreateButton("FORWARD>", $sizex / 2 + 20, $sizey - 50, 80)
            GUICtrlSetOnEvent($forwardbutton, "FWRDButton")
            
        Case $windpos = 1
            $window[1] = GUICreate($title, $sizex, $sizey,$shiftx,$shifty,-1, BitOR($WS_EX_ACCEPTFILES,$WS_EX_TOPMOST))
            AllControls()
            ;ConsoleWrite("in case 1, $name = " & $name & @CRLF)
            GUICtrlCreateLabel($name, 30, 10)

        Case $windpos = 2
            $window[2] = GUICreate($title, $sizex, $sizey,$shiftx,$shifty,-1, BitOR($WS_EX_ACCEPTFILES,$WS_EX_TOPMOST))
            AllControls()
            msgbox(0,"","")
    EndSelect

EndFunc ;==>WINCreate

Func AllControls()
    GUISetOnEvent($GUI_EVENT_CLOSE, "CLOSEClicked")
    $forwardbutton = GUICtrlCreateButton("FORWARD>", $sizex / 2 + 20, $sizey - 50, 80)
    GUICtrlSetOnEvent($forwardbutton, "FWRDButton")
    $backbutton = GUICtrlCreateButton("<BACK", $sizex / 2 - 100, $sizey - 50, 80)
    GUICtrlSetOnEvent($backbutton, "BCKButton")
    GUISetBkColor(0x00E0FFFF)
    GUISetFont(12, 400, 2)
EndFunc ;==>AllControls


Func FWRDButton()
    MOVingVar();These are the variables passed around in the program
    ConsoleWrite($name & @CRLF)
    GUISetState(@SW_HIDE)
    $windpos = $windpos + 1
    WINCreate($windpos)
    GUISwitch($window[$windpos])
    GUISetState(@SW_SHOW); When created, windows are hidden, so we show them when we want them

EndFunc ;==>FWRDButton

Func BCKButton()
    MOVingVar();These are the variables passed around in the program
    GUISetState(@SW_HIDE)
    $windpos = $windpos - 1
    WINCreate($windpos)
    GUISwitch($window[$windpos])
    GUISetState(@SW_SHOW); When created, windows are hidden, so we show them when we want them
EndFunc ;==>BCKButton

Func CLOSEClicked()
    Exit
EndFunc ;==>CLOSEClicked

Func MOVingVar()
        $name = GUICtrlRead($nameA);THIS IS A GUI-READ-OUT
EndFunc
Link to comment
Share on other sites

I also improved the code.

Yes, some good improvements.

Thanks for the help again

that's ok. :)

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.
Link to comment
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
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...