Sign in to follow this  
Followers 0
nitekram

UPdating GuiCtrlSetData

8 posts in this topic

ok, so i have a gui filled with input boxes (50+), some of them depend on a value to be entered in another input box to be computed to get a new value. my question, without reading each value and comparing it to the previous value using a temp variable - is there any way to determine if a value has change. Please let there be an easy way!

here is what i have using the temp variable, but using this method would create a lot of extra code and variables - is there a better way?

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

Opt('MustDeclareVars', 1)

Global $aInputValues[5], $aTempInputValues[5], $Total = 0, $bChanged = 0

Example1()

; example 1
Func Example1()
    Local $msg

    GUICreate("My GUI") ; will create a dialog box that when displayed is centered
    $aInputValues[0] = GUICtrlCreateInput('', 5, 5, 40)
    GUICtrlCreateLabel('value one', 75, 5)
    $aInputValues[1] = GUICtrlCreateInput('', 5, 45, 40)
    GUICtrlCreateLabel('value two', 75, 45)
    $aInputValues[2] = GUICtrlCreateInput('', 5, 85, 40)
    GUICtrlCreateLabel('value three', 75, 85)
    $aInputValues[3] = GUICtrlCreateInput('', 5, 125, 40)
    GUICtrlCreateLabel('value four', 75, 125)
    $aInputValues[4] = GUICtrlCreateInput('', 5, 165, 40)
    GUICtrlCreateLabel('total', 75, 165)
    GUISetState(@SW_SHOW) ; will display an empty dialog box

    ; Run the GUI until the dialog is closed
    While 1
        $msg = GUIGetMsg()

        If $msg = $GUI_EVENT_CLOSE Then ExitLoop

        For $i = 0 To UBound($aInputValues) - 2 ; do not want to add total to the total
            If $aTempInputValues[$i] <> GUICtrlRead($aInputValues[$i]) Then
                If GUICtrlRead($aInputValues[$i]) > '' And $aTempInputValues[$i] <> GUICtrlRead($aInputValues[$i]) Then
                    $aTempInputValues[$i] = GUICtrlRead($aInputValues[$i])
                    $Total += $aTempInputValues[$i]
                    $bChanged = 1
                Else
                    If GUICtrlRead($aInputValues[$i]) = '' Or GUICtrlRead($aInputValues[$i]) = 0 Then
                        $Total -= $aTempInputValues[$i]
                        $aTempInputValues[$i] = GUICtrlRead($aInputValues[$i])
                        $bChanged = 1
                    EndIf
                EndIf
            EndIf

        Next
        If $bChanged Then
            GUICtrlSetData($aInputValues[4], $Total)
            $bChanged = 0
            ;$Total = 0
        EndIf
    WEnd
    GUIDelete()
EndFunc   ;==>Example1

All by me:

"Sometimes you have to go back to where you started, to get to where you want to go." 

"Everybody catches up with everyone, eventually" 

"As you teach others, you are really teaching yourself."

From my dad

"Do not worry about yesterday, as the only thing that you can control is tomorrow."

 

WindowsError.gif

WIKI | Tabs; | Arrays; | Strings | Wiki Arrays | How to ask a Question | Forum Search | FAQ | Tutorials | Original FAQ | ONLINE HELP | UDF's Wiki | AutoIt PDF

AutoIt Snippets | Multple Guis | Interrupting a running function | Another Send

StringRegExp | StringRegExp Help | RegEXTester | REG TUTOR | Reg TUTOT 2

AutoItSetOption | Macros | AutoIt Snippets | Wrapper | Autoit  Docs

SCITE | SciteJump | BB | MyTopics | Programming | UDFs | AutoIt 123 | UDFs Form | UDF

Learning to script | Tutorials | Documentation | IE.AU3 | Games? | FreeSoftware | Path_Online | Core Language

Programming Tips

Excel Changes

ControlHover.UDF

GDI_Plus

Draw_On_Screen

GDI Basics

GDI_More_Basics

GDI Rotate

GDI Graph

GDI  CheckExistingItems

GDI Trajectory

Replace $ghGDIPDll with $__g_hGDIPDll

DLL 101?

Array via Object

GDI Swimlane

GDI Plus French 101 Site

GDI Examples UEZ

GDI Basic Clock

GDI Detection

Ternary operator

Share this post


Link to post
Share on other sites



nitekram,

I would use a message handler to do the counting only if an input had been changed - cuts down the CPU load a bit: :x

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

Opt('MustDeclareVars', 1)

Global $aInputValues[5], $aTempInputValues[5], $Total = 0, $bChanged = 0

Example1()

; example 1
Func Example1()
    Local $msg

    GUICreate("My GUI") ; will create a dialog box that when displayed is centered
    $aInputValues[0] = GUICtrlCreateInput('', 5, 5, 40)
    GUICtrlCreateLabel('value one', 75, 5)
    $aInputValues[1] = GUICtrlCreateInput('', 5, 45, 40)
    GUICtrlCreateLabel('value two', 75, 45)
    $aInputValues[2] = GUICtrlCreateInput('', 5, 85, 40)
    GUICtrlCreateLabel('value three', 75, 85)
    $aInputValues[3] = GUICtrlCreateInput('', 5, 125, 40)
    GUICtrlCreateLabel('value four', 75, 125)
    $aInputValues[4] = GUICtrlCreateInput('', 5, 165, 40)
    GUICtrlCreateLabel('total', 75, 165)
    GUISetState(@SW_SHOW) ; will display an empty dialog box

    GUIRegisterMsg($WM_COMMAND, "MY_WM_COMMAND")

    ; Run the GUI until the dialog is closed
    While 1
        $msg = GUIGetMsg()

        If $msg = $GUI_EVENT_CLOSE Then ExitLoop

    WEnd
    GUIDelete()
EndFunc   ;==>Example1

Func MY_WM_COMMAND($hWnd, $iMsg, $wParam, $lParam)

    Local $iIDFrom = BitAND($wParam, 0xFFFF);LoWord
    Local $iCode = BitShift($wParam, 16)    ;HiWord

    If $iCode = $EN_CHANGE Then ; Has an input been changed? <<<<<<<<<<<<<<<<<<<<<<

        For $i = 0 To UBound($aInputValues) - 2
            If $iIDFrom = $aInputValues[$i] Then ; Is it one of ours? <<<<<<<<<<<<<<<<<<<<<<<<<<
                $Total = 0
                For $j = 0 To UBound($aInputValues) - 2
                    $Total += GUICtrlRead($aInputValues[$j]) ; Calculate the total <<<<<<<<<<<<<<<
                Next
                GUICtrlSetData($aInputValues[4], $Total) ; Display it <<<<<<<<<<<<<<<
                ExitLoop ; No point in looking any further! <<<<<<<<<<<<<<<<<<<<<<
            EndIf
        Next
    EndIf

EndFunc;==>_WM_COMMAND

I hope everything is clear - you know what to do if it is not! :P

M23


Any of my own code posted anywhere on the forum is available for use by others without any restriction of any kind._______My UDFs:

Spoiler

ArrayMultiColSort ---- Sort arrays on multiple columns
ChooseFileFolder ---- Single and multiple selections from specified path treeview listing
Date_Time_Convert -- Easily convert date/time formats, including the language used
ExtMsgBox --------- A highly customisable replacement for MsgBox
GUIExtender -------- Extend and retract multiple sections within a GUI
GUIFrame ---------- Subdivide GUIs into many adjustable frames
GUIListViewEx ------- Insert, delete, move, drag, sort, edit and colour ListView items
GUITreeViewEx ------ Check/clear parent and child checkboxes in a TreeView
Marquee ----------- Scrolling tickertape GUIs
NoFocusLines ------- Remove the dotted focus lines from buttons, sliders, radios and checkboxes
Notify ------------- Small notifications on the edge of the display
Scrollbars ----------Automatically sized scrollbars with a single command
StringSize ---------- Automatically size controls to fit text
Toast -------------- Small GUIs which pop out of the notification area

 

Share this post


Link to post
Share on other sites

WOW - I mean WOW, I wish that I had posted this 3 days ago when i was plulling my hair out. I would have never found this in the help sections, as I would not have been able to find this (not sure even what to search for) - thanks a lot for your help.


All by me:

"Sometimes you have to go back to where you started, to get to where you want to go." 

"Everybody catches up with everyone, eventually" 

"As you teach others, you are really teaching yourself."

From my dad

"Do not worry about yesterday, as the only thing that you can control is tomorrow."

 

WindowsError.gif

WIKI | Tabs; | Arrays; | Strings | Wiki Arrays | How to ask a Question | Forum Search | FAQ | Tutorials | Original FAQ | ONLINE HELP | UDF's Wiki | AutoIt PDF

AutoIt Snippets | Multple Guis | Interrupting a running function | Another Send

StringRegExp | StringRegExp Help | RegEXTester | REG TUTOR | Reg TUTOT 2

AutoItSetOption | Macros | AutoIt Snippets | Wrapper | Autoit  Docs

SCITE | SciteJump | BB | MyTopics | Programming | UDFs | AutoIt 123 | UDFs Form | UDF

Learning to script | Tutorials | Documentation | IE.AU3 | Games? | FreeSoftware | Path_Online | Core Language

Programming Tips

Excel Changes

ControlHover.UDF

GDI_Plus

Draw_On_Screen

GDI Basics

GDI_More_Basics

GDI Rotate

GDI Graph

GDI  CheckExistingItems

GDI Trajectory

Replace $ghGDIPDll with $__g_hGDIPDll

DLL 101?

Array via Object

GDI Swimlane

GDI Plus French 101 Site

GDI Examples UEZ

GDI Basic Clock

GDI Detection

Ternary operator

Share this post


Link to post
Share on other sites

nitekram,

It is not in the Help sections as such - it is one of those little things you pick up as you go along. :x

We could do with some tutorials about the various messages and when they can be useful - I will see what I can put together over the next few weeks. :P

M23


Any of my own code posted anywhere on the forum is available for use by others without any restriction of any kind._______My UDFs:

Spoiler

ArrayMultiColSort ---- Sort arrays on multiple columns
ChooseFileFolder ---- Single and multiple selections from specified path treeview listing
Date_Time_Convert -- Easily convert date/time formats, including the language used
ExtMsgBox --------- A highly customisable replacement for MsgBox
GUIExtender -------- Extend and retract multiple sections within a GUI
GUIFrame ---------- Subdivide GUIs into many adjustable frames
GUIListViewEx ------- Insert, delete, move, drag, sort, edit and colour ListView items
GUITreeViewEx ------ Check/clear parent and child checkboxes in a TreeView
Marquee ----------- Scrolling tickertape GUIs
NoFocusLines ------- Remove the dotted focus lines from buttons, sliders, radios and checkboxes
Notify ------------- Small notifications on the edge of the display
Scrollbars ----------Automatically sized scrollbars with a single command
StringSize ---------- Automatically size controls to fit text
Toast -------------- Small GUIs which pop out of the notification area

 

Share this post


Link to post
Share on other sites

@M23

Thanks for your help once again - you are an MVP in my book.

Let me know when you get a chance to do something like that, it might be helpful in my current script and who knows what I might be able to use for future scripts.


All by me:

"Sometimes you have to go back to where you started, to get to where you want to go." 

"Everybody catches up with everyone, eventually" 

"As you teach others, you are really teaching yourself."

From my dad

"Do not worry about yesterday, as the only thing that you can control is tomorrow."

 

WindowsError.gif

WIKI | Tabs; | Arrays; | Strings | Wiki Arrays | How to ask a Question | Forum Search | FAQ | Tutorials | Original FAQ | ONLINE HELP | UDF's Wiki | AutoIt PDF

AutoIt Snippets | Multple Guis | Interrupting a running function | Another Send

StringRegExp | StringRegExp Help | RegEXTester | REG TUTOR | Reg TUTOT 2

AutoItSetOption | Macros | AutoIt Snippets | Wrapper | Autoit  Docs

SCITE | SciteJump | BB | MyTopics | Programming | UDFs | AutoIt 123 | UDFs Form | UDF

Learning to script | Tutorials | Documentation | IE.AU3 | Games? | FreeSoftware | Path_Online | Core Language

Programming Tips

Excel Changes

ControlHover.UDF

GDI_Plus

Draw_On_Screen

GDI Basics

GDI_More_Basics

GDI Rotate

GDI Graph

GDI  CheckExistingItems

GDI Trajectory

Replace $ghGDIPDll with $__g_hGDIPDll

DLL 101?

Array via Object

GDI Swimlane

GDI Plus French 101 Site

GDI Examples UEZ

GDI Basic Clock

GDI Detection

Ternary operator

Share this post


Link to post
Share on other sites

One more question about this resolution - is there a way to slow down how often it runs the function? The reason I ask is I would like a little bit of time between the calls to allow for more than one digit, if there is more than one.


All by me:

"Sometimes you have to go back to where you started, to get to where you want to go." 

"Everybody catches up with everyone, eventually" 

"As you teach others, you are really teaching yourself."

From my dad

"Do not worry about yesterday, as the only thing that you can control is tomorrow."

 

WindowsError.gif

WIKI | Tabs; | Arrays; | Strings | Wiki Arrays | How to ask a Question | Forum Search | FAQ | Tutorials | Original FAQ | ONLINE HELP | UDF's Wiki | AutoIt PDF

AutoIt Snippets | Multple Guis | Interrupting a running function | Another Send

StringRegExp | StringRegExp Help | RegEXTester | REG TUTOR | Reg TUTOT 2

AutoItSetOption | Macros | AutoIt Snippets | Wrapper | Autoit  Docs

SCITE | SciteJump | BB | MyTopics | Programming | UDFs | AutoIt 123 | UDFs Form | UDF

Learning to script | Tutorials | Documentation | IE.AU3 | Games? | FreeSoftware | Path_Online | Core Language

Programming Tips

Excel Changes

ControlHover.UDF

GDI_Plus

Draw_On_Screen

GDI Basics

GDI_More_Basics

GDI Rotate

GDI Graph

GDI  CheckExistingItems

GDI Trajectory

Replace $ghGDIPDll with $__g_hGDIPDll

DLL 101?

Array via Object

GDI Swimlane

GDI Plus French 101 Site

GDI Examples UEZ

GDI Basic Clock

GDI Detection

Ternary operator

Share this post


Link to post
Share on other sites

#7 ·  Posted (edited)

nitekram,

If you want to wait a bit, then I would set a timer as an input changes and then not run the "total" function until a certain time has elapsed: :x

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

Opt('MustDeclareVars', 1)

Global $aInputValues[5], $iBegin = 0

Example1()

; example 1
Func Example1()
    Local $msg, $Total

    GUICreate("My GUI") ; will create a dialog box that when displayed is centered
    $aInputValues[0] = GUICtrlCreateInput('', 5, 5, 40)
    GUICtrlCreateLabel('value one', 75, 5)
    $aInputValues[1] = GUICtrlCreateInput('', 5, 45, 40)
    GUICtrlCreateLabel('value two', 75, 45)
    $aInputValues[2] = GUICtrlCreateInput('', 5, 85, 40)
    GUICtrlCreateLabel('value three', 75, 85)
    $aInputValues[3] = GUICtrlCreateInput('', 5, 125, 40)
    GUICtrlCreateLabel('value four', 75, 125)
    $aInputValues[4] = GUICtrlCreateInput('', 5, 165, 40)
    GUICtrlCreateLabel('total', 75, 165)
    GUISetState(@SW_SHOW) ; will display an empty dialog box

    GUIRegisterMsg($WM_COMMAND, "MY_WM_COMMAND")

    ; Run the GUI until the dialog is closed
    While 1
        $msg = GUIGetMsg()

        If $msg = $GUI_EVENT_CLOSE Then ExitLoop

        If $iBegin Then
            If TimerDiff($iBegin) > 1000 Then ; wait 1 sec <<<<<<<<<<<<<<<
                $Total = 0
                For $j = 0 To UBound($aInputValues) - 2
                    $Total += GUICtrlRead($aInputValues[$j])
                Next
                GUICtrlSetData($aInputValues[4], $Total)
                $iBegin = 0
            EndIf
        EndIf

    WEnd
    GUIDelete()
EndFunc   ;==>Example1

Func MY_WM_COMMAND($hWnd, $iMsg, $wParam, $lParam)

    Local $iIDFrom = BitAND($wParam, 0xFFFF);LoWord
    Local $iCode = BitShift($wParam, 16)    ;HiWord

    If $iCode = $EN_CHANGE Then

        For $i = 0 To UBound($aInputValues) - 2
            If $iIDFrom = $aInputValues[$i] Then
                $iBegin = TimerInit() ; Start timer flag
                ExitLoop
            EndIf
        Next
    EndIf

EndFunc;==>_WM_COMMAND

You can adjust the delay in the <<<<<<<<<<< line to meet your personal requirements. :P

M23

Edit: Best I put in some <<<<<<<<<<< as I asked you to look for them! :shifty:

Edited by Melba23

Any of my own code posted anywhere on the forum is available for use by others without any restriction of any kind._______My UDFs:

Spoiler

ArrayMultiColSort ---- Sort arrays on multiple columns
ChooseFileFolder ---- Single and multiple selections from specified path treeview listing
Date_Time_Convert -- Easily convert date/time formats, including the language used
ExtMsgBox --------- A highly customisable replacement for MsgBox
GUIExtender -------- Extend and retract multiple sections within a GUI
GUIFrame ---------- Subdivide GUIs into many adjustable frames
GUIListViewEx ------- Insert, delete, move, drag, sort, edit and colour ListView items
GUITreeViewEx ------ Check/clear parent and child checkboxes in a TreeView
Marquee ----------- Scrolling tickertape GUIs
NoFocusLines ------- Remove the dotted focus lines from buttons, sliders, radios and checkboxes
Notify ------------- Small notifications on the edge of the display
Scrollbars ----------Automatically sized scrollbars with a single command
StringSize ---------- Automatically size controls to fit text
Toast -------------- Small GUIs which pop out of the notification area

 

Share this post


Link to post
Share on other sites

no wories on the line, i found it after some digging.

it appears to have resolve the issue i was having - again thanks for the help


All by me:

"Sometimes you have to go back to where you started, to get to where you want to go." 

"Everybody catches up with everyone, eventually" 

"As you teach others, you are really teaching yourself."

From my dad

"Do not worry about yesterday, as the only thing that you can control is tomorrow."

 

WindowsError.gif

WIKI | Tabs; | Arrays; | Strings | Wiki Arrays | How to ask a Question | Forum Search | FAQ | Tutorials | Original FAQ | ONLINE HELP | UDF's Wiki | AutoIt PDF

AutoIt Snippets | Multple Guis | Interrupting a running function | Another Send

StringRegExp | StringRegExp Help | RegEXTester | REG TUTOR | Reg TUTOT 2

AutoItSetOption | Macros | AutoIt Snippets | Wrapper | Autoit  Docs

SCITE | SciteJump | BB | MyTopics | Programming | UDFs | AutoIt 123 | UDFs Form | UDF

Learning to script | Tutorials | Documentation | IE.AU3 | Games? | FreeSoftware | Path_Online | Core Language

Programming Tips

Excel Changes

ControlHover.UDF

GDI_Plus

Draw_On_Screen

GDI Basics

GDI_More_Basics

GDI Rotate

GDI Graph

GDI  CheckExistingItems

GDI Trajectory

Replace $ghGDIPDll with $__g_hGDIPDll

DLL 101?

Array via Object

GDI Swimlane

GDI Plus French 101 Site

GDI Examples UEZ

GDI Basic Clock

GDI Detection

Ternary operator

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