Jump to content

File>New


 Share

Recommended Posts

I made a pulldown menu with the "New" selection and all I want it to do is to reset my GUI, meaning empty all variables and input boxes, etc.

I can use GUICtrlSetData() and GUICtrlSetState() for each variables but I have tons of variables and it's ugly. :)

There's gotta be an easier way. Any advice?

Edited by aslani

[font="Georgia"]Chances are, I'm wrong.[/font]HotKey trouble?Stringregexp GuideAutoIT Current Version

Link to comment
Share on other sites

I made a pulldown menu with the "New" selection and all I want it to do is to reset my GUI, meaning empty all variables and input boxes, etc.

I can use GUICtrlSetData() and GUICtrlSetState() for each variables but I have tons of variables and it's ugly. :)

There's gotta be an easier way. Any advice?

Keep the control IDs or handles in an array when you create them. Makes it easy to loop through them quickly and change something like text, enable/disable, check/uncheck, etc.

;)

Valuater's AutoIt 1-2-3, Class... Is now in Session!For those who want somebody to write the script for them: RentACoder"Any technology distinguishable from magic is insufficiently advanced." -- Geek's corollary to Clarke's law
Link to comment
Share on other sites

Keep the control IDs or handles in an array when you create them. Makes it easy to loop through them quickly and change something like text, enable/disable, check/uncheck, etc.

:)

That's what I have right now and I don't like how it looks. ;)

I was hoping that theres a function that already exist that can clear everything as if you just opened the GUI for the first time...but it seems that the task is for me. :P

[font="Georgia"]Chances are, I'm wrong.[/font]HotKey trouble?Stringregexp GuideAutoIT Current Version

Link to comment
Share on other sites

That's what I have right now and I don't like how it looks. ;)

I was hoping that theres a function that already exist that can clear everything as if you just opened the GUI for the first time...but it seems that the task is for me. :P

No problem:

GuiDelete($hGUI)
$hGUI = GuiCreate("My GUI")

:P

But, all seriousness aside, what do mean about 'how it looks'? If you could post some code for an example it would help to understand the problem.

:)

Edited by PsaltyDS
Valuater's AutoIt 1-2-3, Class... Is now in Session!For those who want somebody to write the script for them: RentACoder"Any technology distinguishable from magic is insufficiently advanced." -- Geek's corollary to Clarke's law
Link to comment
Share on other sites

Ok here's part of the code that I'm using.

$data = ""
$vArray = _ArrayCreate($data)
...
$user = IniRead(@ScriptDir & "\mmrConfig.ini", "Login", "Username", "")
$username = GuiCtrlCreateInput("" & $user, 100, 60, 55, 20)
_ArrayAdd($vArray, $username) ; This goes to every variable I want to reset thru out my script
...
$pass = IniRead(@ScriptDir & "\mmrConfig.ini", "Login", "Password", "")
$password = GuiCtrlCreateInput("" & $pass, 75, 85, 120, 20, $ES_PASSWORD)
_ArrayAdd($vArray, $password)
...
$file_path = GuiCtrlCreateCombo("", 75, 20, 200, 20)
_ArrayAdd($vArray, $file_path)
...
; Pull Down Menu
$filemenu = GUICtrlCreateMenu ("&File")
$f_login = GUICtrlCreateMenuItem ("&Login", $filemenu)
GUICtrlSetState(-1, $GUI_DEFBUTTON)
$f_new = GUICtrlCreateMenuItem ("&New", $filemenu)
$f_separator = GUICtrlCreateMenuitem ("",$filemenu,2)
$f_exit = GUICtrlCreateMenuItem ("E&xit", $filemenu)
...
While 1
$msg = GUIGetMsg()
Select
Case $msg = $f_new
For $i = 0 To UBound($vArray)-1 Step 1
GUICtrlSetData($vArray[$i], "")
Next
EndSelect
WEnd

Basically I don't like how _ArrayAdd($vArray, $some_var) gets repeated over and over, but the alternative is not pleasant to look at either. But I think this is the only way.

Edited by aslani

[font="Georgia"]Chances are, I'm wrong.[/font]HotKey trouble?Stringregexp GuideAutoIT Current Version

Link to comment
Share on other sites

This is the kind of thing I use (not a full running demo):

$hGUI = GUICreate("etc...")

Dim $avInputs[1] = [0]; array of inputs to clear
Dim $avCombos[1] = [0]; array of combos default

$username = GUICtrlCreateInput($user, 100, 60, 55, 20)
_ArrayAdd($avInputs, ControlGetHandle($hGUI, "", $username))

; ...add more inputs

$file_path = GUICtrlCreateCombo("", 75, 20, 200, 20)
_ArrayAdd($avCombos, ControlGetHandle($hGUI, "", $file_path))

; ...add more combos

; ...detect operator wants to reset form controls...

_Reset()

Func _Reset()
    $avInputs[0] = UBound($avInputs) - 1
    For $n = 1 To $avInputs[0]
        GUICtrlSetData($avInputs[$n], ""); Clear text in all inputs
    Next
    
    $avCombos[0] = UBound($avCombos) - 1
    For $n = 1 To $avCombos[0]
        _GUICtrlComboSetCurSel($avCombos[$n], 0); select first index as default in all combos
    Next
EndFunc  ;==>_Reset

Note it save the control handles, not the ControlID, making some reset operations more reliable.

:)

Valuater's AutoIt 1-2-3, Class... Is now in Session!For those who want somebody to write the script for them: RentACoder"Any technology distinguishable from magic is insufficiently advanced." -- Geek's corollary to Clarke's law
Link to comment
Share on other sites

I haven't played around with handles yet since I don't really understand how it works. All I need is to simply empty all variables when "New" is selected.

Basically what my script does is to extract information from an Excel Spreadsheet, then place all data in an array to be logged into a database. So all I do is provide the Excel Form Number then my script does the rest (i.e. Open Excel -> Extract Data -> Close Excel -> Open/Activate Database -> Log Data -> Rinse and repeat)

So I have this list of Excel File Number in an array and the script goes thru that list, but if one of them has, for example, 10 items, then the one after it has 8 items, the left over 2 items are arrayed into the one with only 8 items. This is where the "New" option and emptying all variables comes into play.

As for now, what I have works the way I want it to (but I'm think I'll be studying handles some time soon :))

Edited by aslani

[font="Georgia"]Chances are, I'm wrong.[/font]HotKey trouble?Stringregexp GuideAutoIT Current Version

Link to comment
Share on other sites

Ok, I got more problem.

I manage to clear the values in GUI variables, but all my non-GUI variables still keeps their value. Anybody have an idea on how to reset the non-GUI variables?

What do you mean by non-GUI variables? Such as labels? Global variables declared at the top of the script? Variables where? And why do they need to be cleared... shouldn't it reset itself when you enter in new values inside of the gui text boxes?

Link to comment
Share on other sites

One technique that might work is to place the entire GUI creation inside a function. Then when you want to clear it just GUIDelete and re-execute the function.

Simple example:

#include <GUIConstants.au3>

$gui = GUICreate('', 200, 200)
$me_File = GUICtrlCreateMenu('&File')
$mi_New = GUICtrlCreateMenuItem('New', $me_File)

$gui_Child = _New($gui)
GUISetState(@SW_SHOW, $gui)
GUISetState(@SW_SHOW, $gui_Child)

While 1
    $gm = GUIGetMsg()
    Switch $gm
        Case $mi_New
            GUISetState(@SW_LOCK, $gui)
            GUIDelete($gui_Child)
            $gui_Child = _New($gui)
            GUISetState(@SW_SHOW, $gui_Child)
            GUISetState(@SW_UNLOCK, $gui)
        Case $GUI_EVENT_CLOSE
            ExitLoop
    EndSwitch
WEnd


Func _New($hParent)
    Local $guiChild = GUICreate('', 200, 200, 0, 0, $WS_CHILD, Default, $hParent)
    GUICtrlCreateLabel('Label', 5, 5, 30, 20, $SS_CENTERIMAGE)
    GUICtrlCreateInput('Default', 40, 5, 100, 20)
    GUICtrlCreateCheckbox('Default unchecked', 5, 25, 150, 20)
    GUICtrlCreateCheckbox('Default checked', 5, 45, 150, 20)
        GUICtrlSetState(-1, $GUI_CHECKED)
    GUICtrlCreateCombo('', 5, 65, 150, 100)
        GUICtrlSetData(-1, 'One|Two|Three|Four', 'One')
    Return $guiChild
EndFunc
Link to comment
Share on other sites

  • 2 weeks later...

Sorry I completely lost track of this thread since I was too busy working on another project.

What do you mean by non-GUI variables? Such as labels? Global variables declared at the top of the script? Variables where? And why do they need to be cleared... shouldn't it reset itself when you enter in new values inside of the gui text boxes?

non-GUI variables as arrays, return value, etc.

One technique that might work is to place the entire GUI creation inside a function. Then when you want to clear it just GUIDelete and re-execute the function.

Simple example:

#include <GUIConstants.au3>

$gui = GUICreate('', 200, 200)
$me_File = GUICtrlCreateMenu('&File')
$mi_New = GUICtrlCreateMenuItem('New', $me_File)

$gui_Child = _New($gui)
GUISetState(@SW_SHOW, $gui)
GUISetState(@SW_SHOW, $gui_Child)

While 1
    $gm = GUIGetMsg()
    Switch $gm
        Case $mi_New
            GUISetState(@SW_LOCK, $gui)
            GUIDelete($gui_Child)
            $gui_Child = _New($gui)
            GUISetState(@SW_SHOW, $gui_Child)
            GUISetState(@SW_UNLOCK, $gui)
        Case $GUI_EVENT_CLOSE
            ExitLoop
    EndSwitch
WEnd
Func _New($hParent)
    Local $guiChild = GUICreate('', 200, 200, 0, 0, $WS_CHILD, Default, $hParent)
    GUICtrlCreateLabel('Label', 5, 5, 30, 20, $SS_CENTERIMAGE)
    GUICtrlCreateInput('Default', 40, 5, 100, 20)
    GUICtrlCreateCheckbox('Default unchecked', 5, 25, 150, 20)
    GUICtrlCreateCheckbox('Default checked', 5, 45, 150, 20)
        GUICtrlSetState(-1, $GUI_CHECKED)
    GUICtrlCreateCombo('', 5, 65, 150, 100)
        GUICtrlSetData(-1, 'One|Two|Three|Four', 'One')
    Return $guiChild
EndFunc
Oooh, that might just work. I like it. :) Edited by aslani

[font="Georgia"]Chances are, I'm wrong.[/font]HotKey trouble?Stringregexp GuideAutoIT Current Version

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