Jump to content

Resetting Variables (Solved)


Recommended Posts

I'm trying to write a small program to get familiar with the aspects of AutoIT features. I'm starting off with making a GUI that will later be the main menu, but for now, it goes directly to the first available "function", which would be a way to enter events into a calendar/excel file. The problem is, I include a reset button at the bottom that is supposed to reset the entry form, and it does. However, as soon as you click on any of the input places, all the previous text (which was supposed to be reset) shows up. And you can only use the button once.

I know it is something simple that I'm overlooking, but I can't seem to find anything when I search the forum. Here is the script (after this, the next step is going to be saving the variables to locations like an excel file or a document, that's why everything seems to be a variable):

#include <GuiConstantsEx.au3>
#include <AVIConstants.au3>
#include <TreeViewConstants.au3>

;Set up variables to be used later
Local $filemenu, $newitem, $edititem, $deleteitem, $uploaditem, $exititem;File menu items
Local $Button_NE1, $Button_NE2, $Button_NE3;New event items
    Local $NE_Location = ""
    Local $NE_Myplans = ""
    Local $NE_Herplans = ""

;;BEGIN PROGRAM HERE;;
GUICreate("Event Log Maker",235,500)

;Creates the file menu.  However, for now, we will use it very little.  In the future, however, it will handle multiple tasks.
$filemenu = GuiCtrlCreateMenu("File")
$newitem = GUICtrlCreateMenuItem("Record Event", $filemenu)
GUICtrlSetState(-1, $GUI_DISABLE)
$edititem = GUICtrlCreateMenuItem("Edit Last Event", $filemenu)
GUICtrlSetState(-1, $GUI_DISABLE)
$deleteitem = GUICtrlCreateMenuItem("Delete Last Event", $filemenu)
GUICtrlSetState(-1, $GUI_DISABLE)
GUICtrlCreateMenuItem("", $filemenu,5)
$exititem = GUICtrlCreateMenuItem("Quit Program", $filemenu)

;THIS WILL START US LOOKING AT A RECORD KILL AREA
NewEvent()
;REMOVE THESE 3 LINES OF CODE WHEN THE PROGRAM IS COMPLETED

;Func Start()
GUISetState()

While 1
    $msg = GUIGetMsg()
;If $msg = $newitem Then NewEvent()
        If $msg = $Button_NE3 Then ResetNewEvent()
    If $msg = $GUI_EVENT_CLOSE Or $msg = $exititem Then Terminate()
WEnd

Func NewEvent()
GUICtrlCreateLabel("Date:", 2, 9);Record the date
    GuiCtrlCreateDate("", 31, 5, 200, 20)
GUICtrlCreateLabel("One Person:", 2, 34);decides if it will save both inputs, or just one
    GUICtrlCreateCombo("Yes", 55, 29, 45, 30);
        GUICtrlSetData(-1, "No", "Yes");values (default = Yes)
GUICtrlCreateLabel("Time:", 2, 54);Record time (hour, minute, am|pm)
    GUICtrlCreateCombo("1", 31, 54, 38, 30);hour
        GUICtrlSetData(-1, "2|3|4|5|6|7|8|9|10|11|12", "12");values (default = 12)
    GUICtrlCreateCombo("00", 73, 54, 38, 30);minute
        GUICtrlSetData(-1, "01|02|03|04|05|06|07|08|09|10|11|12|13|14|15|16|17|18|19|20|21|22|23|24|25|26|27|28|29|30|31|32|



33|34|35|36|37|38|39|40|41|42|43|44|45|46|47|48|49|50|51|52|53|54|55|56|57|58|59", "00");values (default = 00)
    GUICtrlCreateCombo("AM", 116, 54, 40, 30);AM or PM
        GUICtrlSetData(-1, "PM", "AM");values (default = AM)
GUICtrlCreateLabel("Location:", 2, 78);location box
    GUICtrlCreateInput($NE_Location, 2, 92, 231, 20)
GUICtrlCreateLabel("Me:", 2, 116);My Plans
    GUICtrlCreateEdit($NE_Myplans, 2, 132, 231, 70)
GUICtrlCreateLabel("Her:", 2, 204);Her Plans
    GUICtrlCreateEdit($NE_Herplans, 2, 220, 231, 220)
;Create buttons to complete the process
$Button_NE1 = GuiCtrlCreateButton("Preview", 2, 445, 85, 30)
$Button_NE2 = GuiCtrlCreateButton("Save", 93, 445, 65, 30)
$button_NE3 = GuiCtrlCreateButton("Reset Form", 165, 445, 65, 30)
EndFunc

Func ResetNewEvent()
Dim $NE_Location = "", $NE_Myplans = "", $NE_Herplans = ""
NewEvent()
EndFunc

Func Terminate()
    Exit 0
EndFunc

Like I said, I'm sure it is something really stupid that I'm doing wrong, but I can't figure it out. The input boxes will clear when you hit the reset button, but the variables don't change, so clicking the input the box puts the old text back in.

Edited by moviemadnessman
Link to comment
Share on other sites

I'm trying to write a small program to get familiar with the aspects of AutoIT features. I'm starting off with making a GUI that will later be the main menu, but for now, it goes directly to the first available "function", which would be a way to enter events into a calendar/excel file. The problem is, I include a reset button at the bottom that is supposed to reset the entry form, and it does. However, as soon as you click on any of the input places, all the previous text (which was supposed to be reset) shows up. And you can only use the button once.

I know it is something simple that I'm overlooking, but I can't seem to find anything when I search the forum. Here is the script (after this, the next step is going to be saving the variables to locations like an excel file or a document, that's why everything seems to be a variable):

#include <GuiConstantsEx.au3>
#include <AVIConstants.au3>
#include <TreeViewConstants.au3>

;Set up variables to be used later
Local $filemenu, $newitem, $edititem, $deleteitem, $uploaditem, $exititem;File menu items
Local $Button_NE1, $Button_NE2, $Button_NE3;New event items
    Local $NE_Location = ""
    Local $NE_Myplans = ""
    Local $NE_Herplans = ""

;;BEGIN PROGRAM HERE;;
GUICreate("Event Log Maker",235,500)

;Creates the file menu.  However, for now, we will use it very little.  In the future, however, it will handle multiple tasks.
$filemenu = GuiCtrlCreateMenu("File")
$newitem = GUICtrlCreateMenuItem("Record Event", $filemenu)
GUICtrlSetState(-1, $GUI_DISABLE)
$edititem = GUICtrlCreateMenuItem("Edit Last Event", $filemenu)
GUICtrlSetState(-1, $GUI_DISABLE)
$deleteitem = GUICtrlCreateMenuItem("Delete Last Event", $filemenu)
GUICtrlSetState(-1, $GUI_DISABLE)
GUICtrlCreateMenuItem("", $filemenu,5)
$exititem = GUICtrlCreateMenuItem("Quit Program", $filemenu)

;THIS WILL START US LOOKING AT A RECORD KILL AREA
NewEvent()
;REMOVE THESE 3 LINES OF CODE WHEN THE PROGRAM IS COMPLETED

;Func Start()
GUISetState()

While 1
    $msg = GUIGetMsg()
;If $msg = $newitem Then NewEvent()
        If $msg = $Button_NE3 Then ResetNewEvent()
    If $msg = $GUI_EVENT_CLOSE Or $msg = $exititem Then Terminate()
WEnd

Func NewEvent()
GUICtrlCreateLabel("Date:", 2, 9);Record the date
    GuiCtrlCreateDate("", 31, 5, 200, 20)
GUICtrlCreateLabel("One Person:", 2, 34);decides if it will save both inputs, or just one
    GUICtrlCreateCombo("Yes", 55, 29, 45, 30);
        GUICtrlSetData(-1, "No", "Yes");values (default = Yes)
GUICtrlCreateLabel("Time:", 2, 54);Record time (hour, minute, am|pm)
    GUICtrlCreateCombo("1", 31, 54, 38, 30);hour
        GUICtrlSetData(-1, "2|3|4|5|6|7|8|9|10|11|12", "12");values (default = 12)
    GUICtrlCreateCombo("00", 73, 54, 38, 30);minute
        GUICtrlSetData(-1, "01|02|03|04|05|06|07|08|09|10|11|12|13|14|15|16|17|18|19|20|21|22|23|24|25|26|27|28|29|30|31|32|


33|34|35|36|37|38|39|40|41|42|43|44|45|46|47|48|49|50|51|52|53|54|55|56|57|58|59", "00");values (default = 00)
    GUICtrlCreateCombo("AM", 116, 54, 40, 30);AM or PM
        GUICtrlSetData(-1, "PM", "AM");values (default = AM)
GUICtrlCreateLabel("Location:", 2, 78);location box
    GUICtrlCreateInput($NE_Location, 2, 92, 231, 20)
GUICtrlCreateLabel("Me:", 2, 116);My Plans
    GUICtrlCreateEdit($NE_Myplans, 2, 132, 231, 70)
GUICtrlCreateLabel("Her:", 2, 204);Her Plans
    GUICtrlCreateEdit($NE_Herplans, 2, 220, 231, 220)
;Create buttons to complete the process
$Button_NE1 = GuiCtrlCreateButton("Preview", 2, 445, 85, 30)
$Button_NE2 = GuiCtrlCreateButton("Save", 93, 445, 65, 30)
$button_NE3 = GuiCtrlCreateButton("Reset Form", 165, 445, 65, 30)
EndFunc

Func ResetNewEvent()
Dim $NE_Location = "", $NE_Myplans = "", $NE_Herplans = ""
NewEvent()
EndFunc

Func Terminate()
    Exit 0
EndFunc

Like I said, I'm sure it is something really stupid that I'm doing wrong, but I can't figure it out. The input boxes will clear when you hit the reset button, but the variables don't change, so clicking the input the box puts the old text back in.

Don't try to clear the data by recreating another set of controls. Only create the controls once, but give them each a unique global variable name. If you don't give them an id then you will make it difficult to read the data from them when the form is completed.

$Edit1 = GuiCtrlCreateEdit(...

Then, when you want to clear, or reset, the inputs do this for each input

GuiCtrlSetData($Edit1,"").

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

I had initially misread the last post made. I changed the code to add new variables to the Input areas, making sure they were globally defined in the start of the program. I ran it testing the code, and it now correctly erases (and doesn't bring back) the data. Thank you, martin.

However, I am still finding that I can only reset one time. After that, clicking the rest button does nothing ... The program should still be watching for changes in the gui, though, so I don't know why the reset button only works one time. I even tried making that part of the code its own function, but that didn't work either. Any further thoughts?

Link to comment
Share on other sites

I had initially misread the last post made. I changed the code to add new variables to the Input areas, making sure they were globally defined in the start of the program. I ran it testing the code, and it now correctly erases (and doesn't bring back) the data. Thank you, martin.

However, I am still finding that I can only reset one time. After that, clicking the rest button does nothing ... The program should still be watching for changes in the gui, though, so I don't know why the reset button only works one time. I even tried making that part of the code its own function, but that didn't work either. Any further thoughts?

Can you show the script?
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

#include <GuiConstantsEx.au3>
#include <AVIConstants.au3>
#include <TreeViewConstants.au3>

;Set up variables to be used later
Global $filemenu, $newitem, $edititem, $deleteitem, $uploaditem, $exititem;File menu items
Global $Button_NE1, $Button_NE2, $Button_NE3;New event items
    Global $NE_Location, $NE_Myplans, $NE_Herplans
    Global $NELocation, $NEMyplans, $NEHerplans
    
;;BEGIN PROGRAM HERE;;
GUICreate("Event Log Maker",235,500)

;Creates the file menu.  However, for now, we will use it very little.  In the future, however, it will handle multiple tasks.
$filemenu = GuiCtrlCreateMenu("File")
$newitem = GUICtrlCreateMenuItem("Record Event", $filemenu)
GUICtrlSetState(-1, $GUI_DISABLE)
$edititem = GUICtrlCreateMenuItem("Edit Last Event", $filemenu)
GUICtrlSetState(-1, $GUI_DISABLE)
$deleteitem = GUICtrlCreateMenuItem("Delete Last Event", $filemenu)
GUICtrlSetState(-1, $GUI_DISABLE)
GUICtrlCreateMenuItem("", $filemenu,5)
$exititem = GUICtrlCreateMenuItem("Quit Program", $filemenu)

;THIS WILL START US LOOKING AT A RECORD EVENT AREA
NewEvent()
;REMOVE THESE 3 LINES OF CODE WHEN THE PROGRAM IS COMPLETED

GUISetState()

While 1
    $msg = GUIGetMsg()
;If $msg = $newitem Then NewEvent()
    If $msg = $Button_NE3 Then ResetNewEvent()
    If $msg = $GUI_EVENT_CLOSE Or $msg = $exititem Then Terminate()
WEnd

Func NewEvent()
GUICtrlCreateLabel("Date:", 2, 9);Record the date
    GuiCtrlCreateDate("", 31, 5, 200, 20)
GUICtrlCreateLabel("One Person:", 2, 34);decides if it will save both inputs, or just one
    GUICtrlCreateCombo("Yes", 62, 29, 45, 30);
        GUICtrlSetData(-1, "No", "Yes");values (default = Yes)
GUICtrlCreateLabel("Time:", 2, 54);Record time (hour, minute, am|pm)
    GUICtrlCreateCombo("1", 31, 54, 38, 30);hour
        GUICtrlSetData(-1, "2|3|4|5|6|7|8|9|10|11|12", "12");values (default = 12)
    GUICtrlCreateCombo("00", 73, 54, 38, 30);minute
        GUICtrlSetData(-1, "01|02|03|04|05|06|07|08|09|10|11|12|13|14|15|16|17|18|19|20|21|22|23|24|25|26|27|28|29|30|31|32|


33|34|35|36|37|38|39|40|41|42|43|44|45|46|47|48|49|50|51|52|53|54|55|56|57|58|59", "00");values (default = 00)
    GUICtrlCreateCombo("AM", 116, 54, 40, 30);AM or PM
        GUICtrlSetData(-1, "PM", "AM");values (default = AM)
GUICtrlCreateLabel("Location:", 2, 78);location box
    $NELocation = GUICtrlCreateInput($NE_Location, 2, 92, 231, 20)
GUICtrlCreateLabel("Me:", 2, 116);My Plans
    $NEMyplans = GUICtrlCreateEdit($NE_Myplans, 2, 132, 231, 70)
GUICtrlCreateLabel("Her:", 2, 204);Her Plans
    $NEHerplans = GUICtrlCreateEdit($NE_Herplans, 2, 220, 231, 220)
;Create buttons to complete the process
$Button_NE1 = GuiCtrlCreateButton("Preview", 2, 445, 85, 30)
$Button_NE2 = GuiCtrlCreateButton("Save", 93, 445, 65, 30)
$button_NE3 = GuiCtrlCreateButton("Reset Form", 165, 445, 65, 30)
EndFunc

Func ResetNewEvent()
GuiCtrlSetData($NELocation,"")
GuiCtrlSetData($NEMyplans,"")
GuiCtrlSetData($NEHerplans,"")
NewEvent()
EndFunc

Func Terminate()
    Exit 0
EndFunc

The code creates the GUI, and allows you to reset all the data 1 time. After that, though, the reset button does nothing, whereas it should be allowing me to reset whenever I push it. I'm unable to figure out why that is, though. I tried using GuiCtrlSetData to reset the $msg variable, but that didn't work. I also tried making:

GUISetState()

While 1
    $msg = GUIGetMsg()
;If $msg = $newitem Then NewEvent()
    If $msg = $Button_NE3 Then ResetNewEvent()
    If $msg = $GUI_EVENT_CLOSE Or $msg = $exititem Then Terminate()
WEnd

into another function, so that at the end of the NewEvent() function, it would go back to the state where it is watching, but that didn't work, either.

Edited by moviemadnessman
Link to comment
Share on other sites

#include <GuiConstantsEx.au3>
#include <AVIConstants.au3>
#include <TreeViewConstants.au3>

;Set up variables to be used later
Global $filemenu, $newitem, $edititem, $deleteitem, $uploaditem, $exititem;File menu items
Global $Button_NE1, $Button_NE2, $Button_NE3;New event items
    Global $NE_Location, $NE_Myplans, $NE_Herplans
    Global $NELocation, $NEMyplans, $NEHerplans
    
;;BEGIN PROGRAM HERE;;
GUICreate("Event Log Maker",235,500)

;Creates the file menu.  However, for now, we will use it very little.  In the future, however, it will handle multiple tasks.
$filemenu = GuiCtrlCreateMenu("File")
$newitem = GUICtrlCreateMenuItem("Record Event", $filemenu)
GUICtrlSetState(-1, $GUI_DISABLE)
$edititem = GUICtrlCreateMenuItem("Edit Last Event", $filemenu)
GUICtrlSetState(-1, $GUI_DISABLE)
$deleteitem = GUICtrlCreateMenuItem("Delete Last Event", $filemenu)
GUICtrlSetState(-1, $GUI_DISABLE)
GUICtrlCreateMenuItem("", $filemenu,5)
$exititem = GUICtrlCreateMenuItem("Quit Program", $filemenu)

;THIS WILL START US LOOKING AT A RECORD EVENT AREA
NewEvent()
;REMOVE THESE 3 LINES OF CODE WHEN THE PROGRAM IS COMPLETED

GUISetState()

While 1
    $msg = GUIGetMsg()
;If $msg = $newitem Then NewEvent()
    If $msg = $Button_NE3 Then ResetNewEvent()
    If $msg = $GUI_EVENT_CLOSE Or $msg = $exititem Then Terminate()
WEnd

Func NewEvent()
GUICtrlCreateLabel("Date:", 2, 9);Record the date
    GuiCtrlCreateDate("", 31, 5, 200, 20)
GUICtrlCreateLabel("One Person:", 2, 34);decides if it will save both inputs, or just one
    GUICtrlCreateCombo("Yes", 62, 29, 45, 30);
        GUICtrlSetData(-1, "No", "Yes");values (default = Yes)
GUICtrlCreateLabel("Time:", 2, 54);Record time (hour, minute, am|pm)
    GUICtrlCreateCombo("1", 31, 54, 38, 30);hour
        GUICtrlSetData(-1, "2|3|4|5|6|7|8|9|10|11|12", "12");values (default = 12)
    GUICtrlCreateCombo("00", 73, 54, 38, 30);minute
        GUICtrlSetData(-1, "01|02|03|04|05|06|07|08|09|10|11|12|13|14|15|16|17|18|19|20|21|22|23|24|25|26|27|28|29|30|31|32|



33|34|35|36|37|38|39|40|41|42|43|44|45|46|47|48|49|50|51|52|53|54|55|56|57|58|59", "00");values (default = 00)
    GUICtrlCreateCombo("AM", 116, 54, 40, 30);AM or PM
        GUICtrlSetData(-1, "PM", "AM");values (default = AM)
GUICtrlCreateLabel("Location:", 2, 78);location box
    $NELocation = GUICtrlCreateInput($NE_Location, 2, 92, 231, 20)
GUICtrlCreateLabel("Me:", 2, 116);My Plans
    $NEMyplans = GUICtrlCreateEdit($NE_Myplans, 2, 132, 231, 70)
GUICtrlCreateLabel("Her:", 2, 204);Her Plans
    $NEHerplans = GUICtrlCreateEdit($NE_Herplans, 2, 220, 231, 220)
;Create buttons to complete the process
$Button_NE1 = GuiCtrlCreateButton("Preview", 2, 445, 85, 30)
$Button_NE2 = GuiCtrlCreateButton("Save", 93, 445, 65, 30)
$button_NE3 = GuiCtrlCreateButton("Reset Form", 165, 445, 65, 30)
EndFunc

Func ResetNewEvent()
GuiCtrlSetData($NELocation,"")
GuiCtrlSetData($NEMyplans,"")
GuiCtrlSetData($NEHerplans,"")
NewEvent()
EndFunc

Func Terminate()
    Exit 0
EndFunc

The code creates the GUI, and allows you to reset all the data 1 time. After that, though, the reset button does nothing, whereas it should be allowing me to reset whenever I push it. I'm unable to figure out why that is, though. I tried using GuiCtrlSetData to reset the $msg variable, but that didn't work. I also tried making:

GUISetState()

While 1
    $msg = GUIGetMsg()
;If $msg = $newitem Then NewEvent()
    If $msg = $Button_NE3 Then ResetNewEvent()
    If $msg = $GUI_EVENT_CLOSE Or $msg = $exititem Then Terminate()
WEnd

into another function, so that at the end of the NewEvent() function, it would go back to the state where it is watching, but that didn't work, either.

You appear to have missed or misunderstood my previous advice, so here is the bit you have ignore/overlooked and which was why you had the problem in the first place and is why you have the same problem now.

Don't try to clear the data by recreating another set of controls.

Once you have created them leave them there, just clear the contents. So don't put NewEvent() in your reset function.
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

That seems to have fixed the problem. I guess I had misunderstood the post a little the first time around, since I didn't know it would keep looping around on its own. There will eventually be other UDFs in the code, so I wanted to make sure it was going back to the right one (in this case, the NewEvent part of the code). Hence why it was being built into the Reset function. Seems to work now.

Thanks for your help into the matter.

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...