Sign in to follow this  
Followers 0
Ontosy

$EN_CHANGE with Updown control

14 posts in this topic

i use:

if $iCode=$EN_CHANGE Then

GUICtrlSetData($Input[0],StringFormat('%d', GUICtrlRead($Input[0])*1000))

endif

i use $Input[0] with Updown control

when i click down it is ok

when i click up it change data but after return to original

when i click up up up up it ad 3 step.

how to solve?

(excuse my poor english)

Share this post


Link to post
Share on other sites



i use:

if $iCode=$EN_CHANGE Then

GUICtrlSetData($Input[0],StringFormat('%d', GUICtrlRead($Input[0])*1000))

endif

i use $Input[0] with Updown control

when i click down it is ok

when i click up it change data but after return to original

when i click up up up up it ad 3 step.

how to solve?

(excuse my poor english)

Post a short script we can run to reproduce your symtoms. The less English you know, the more important a good demonstration of your issue in the code is.

:D


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

Share this post


Link to post
Share on other sites

#3 ·  Posted (edited)

this is the script:

test.au3

Edited by Ontosy

Share this post


Link to post
Share on other sites

this is the script:

#include <ButtonConstants.au3>
#include <EditConstants.au3>
#include <GUIConstantsEx.au3>
#include <StaticConstants.au3>
#include <WindowsConstants.au3>
#include <WinAPI.au3> ; used for Lo/Hi word
Opt("TrayIconDebug",1)
Opt("TrayIconHide",0)
dim $Input[2],$Updown[1]

$Form1_1 = GUICreate("ReDate", 161, 208, 192, 114, -1,  $WS_EX_ACCEPTFILES)
$Label1 = GUICtrlCreateLabel("&Years", 16, 8, 37, 17)
$Input[0] = GUICtrlCreateInput("2", 143, 8, 1, 21, BitOR($ES_NUMBER, $ES_RIGHT))
$input[1] = GUICtrlCreateInput("2000",72,8,56,21)
$Updown[0] = GUICtrlCreateUpdown($Input[0])
GUISetState(@SW_SHOW)

GUIRegisterMsg($WM_COMMAND, "WM_COMMAND")
Do
Until GUIGetMsg() = $GUI_EVENT_CLOSE
GUIDelete()

Func WM_COMMAND($hWnd, $iMsg, $iwParam, $ilParam)
    #forceref $hWnd, $iMsg
    Local $hWndFrom, $iIDFrom, $iCode, $hWndEdit
    If Not IsHWnd($Input[0]) Then $hWndAnno = GUICtrlGetHandle($Input[0])
    $hWndFrom = $ilParam
    $iIDFrom = _WinAPI_LoWord($iwParam)
    $iCode = _WinAPI_HiWord($iwParam)
    Switch $hWndFrom
        Case $GUI_EVENT_CLOSE
            Exit
        Case $hWndAnno, $Input[0]
            if $iCode=$EN_CHANGE Then
                    GUICtrlSetData($Input[1],StringFormat('%d', GUICtrlRead($Input[0])*1000))
            EndIf
    EndSwitch
EndFunc

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.

Share this post


Link to post
Share on other sites

#5 ·  Posted (edited)

It does not always work.

Often misfires.

#include <ButtonConstants.au3>
#include <EditConstants.au3>
#include <GUIConstantsEx.au3>
#include <StaticConstants.au3>
#include <WindowsConstants.au3>
#include <WinAPI.au3> ; used for Lo/Hi word
Opt("TrayIconDebug",1)
Opt("TrayIconHide",0)
dim $Input[2],$Updown[1]

$Form1_1 = GUICreate("ReDate", 161, 208, 192, 114, -1,  $WS_EX_ACCEPTFILES)
$Label1 = GUICtrlCreateLabel("&Years", 16, 8, 37, 17)
$Input[0] = GUICtrlCreateInput("2000", 143, 8, 1, 21, BitOR($ES_NUMBER, $ES_RIGHT))
$input[1] = GUICtrlCreateInput("2000",72,8,56,21)
$Updown[0] = GUICtrlCreateUpdown($Input[0])
GUISetState(@SW_SHOW)

GUIRegisterMsg($WM_COMMAND, "WM_COMMAND")
Do
Until GUIGetMsg() = $GUI_EVENT_CLOSE
GUIDelete()

Func WM_COMMAND($hWnd, $iMsg, $iwParam, $ilParam)
    #forceref $hWnd, $iMsg
    Local $hWndFrom, $iIDFrom, $iCode, $hWndEdit
    If Not IsHWnd($Input[0]) Then $hWndAnno = GUICtrlGetHandle($Input[0])
    $hWndFrom = $ilParam
    $iIDFrom = _WinAPI_LoWord($iwParam)
    $iCode = _WinAPI_HiWord($iwParam)
    Switch $hWndFrom
        Case $GUI_EVENT_CLOSE
            Exit
        Case $hWndAnno, $Input[0]
            if $iCode=$EN_CHANGE Then
                    GUICtrlSetData($Input[1],StringFormat('%d', GUICtrlRead($Input[0])*1000))
            EndIf
    EndSwitch
EndFunc
Edited by Ontosy

Share this post


Link to post
Share on other sites

It does not always work.

Often misfires.

#include <ButtonConstants.au3>
#include <EditConstants.au3>
#include <GUIConstantsEx.au3>
#include <StaticConstants.au3>
#include <WindowsConstants.au3>
#include <WinAPI.au3> ; used for Lo/Hi word
Opt("TrayIconDebug",1)
Opt("TrayIconHide",0)
dim $Input[2],$Updown[1]

$Form1_1 = GUICreate("ReDate", 161, 208, 192, 114, -1,  $WS_EX_ACCEPTFILES)
$Label1 = GUICtrlCreateLabel("&Years", 16, 8, 37, 17)
$Input[0] = GUICtrlCreateInput("2000", 143, 8, 1, 21, BitOR($ES_NUMBER, $ES_RIGHT))
$input[1] = GUICtrlCreateInput("2000",72,8,56,21)
$Updown[0] = GUICtrlCreateUpdown($Input[0])
GUISetState(@SW_SHOW)

GUIRegisterMsg($WM_COMMAND, "WM_COMMAND")
Do
Until GUIGetMsg() = $GUI_EVENT_CLOSE
GUIDelete()

Func WM_COMMAND($hWnd, $iMsg, $iwParam, $ilParam)
    #forceref $hWnd, $iMsg
    Local $hWndFrom, $iIDFrom, $iCode, $hWndEdit
    If Not IsHWnd($Input[0]) Then $hWndAnno = GUICtrlGetHandle($Input[0])
    $hWndFrom = $ilParam
    $iIDFrom = _WinAPI_LoWord($iwParam)
    $iCode = _WinAPI_HiWord($iwParam)
    Switch $hWndFrom
        Case $GUI_EVENT_CLOSE
            Exit
        Case $hWndAnno, $Input[0]
            if $iCode=$EN_CHANGE Then
                    GUICtrlSetData($Input[1],StringFormat('%d', GUICtrlRead($Input[0])*1000))
            EndIf
    EndSwitch
EndFunc
When it reads the string from the edit, it gets formatted with thousands separators. So when you click "Up", it goes from "2000" to "2,001". The comma screws up your calculation of the new value. You can see it with this change:
if $iCode=$EN_CHANGE Then
                    $sRead = GUICtrlRead($Input[0])
                    $sWrite = StringFormat('%d', $sRead)
                    $iWrite = $sWrite * 1000
                    ConsoleWrite("Debug: $sRead = " & $sRead & ", $sWrite = " & $sWrite & ", $iWrite = " & $iWrite & @LF)
                    GUICtrlSetData($Input[1], $iWrite)
            EndIf

Just strip the thousands sep out of the string before processing.

:D


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

Share this post


Link to post
Share on other sites

@Ontosy The value set into input[0] should be 2 not 2000 like I showed in my script.

When the input[0] is read it won't have a value like 2000 but 2 which will change to 3 so there is no comma to confuse anything. The 2 is multiplied by 1000 and the result put in input[1]. There won't be a problewm untill you get past 1000 (which will be displayed as 1000,000) so then you would need to remove the comma or full stop as PsaltyDS says.

Maybe I didn't understand what you want to do.


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.

Share this post


Link to post
Share on other sites

When i click UpDown would:

2001

2002

2003

2004

and not

2.001

2.002

2.003

2.004

and not

2000

3000

4000

5000

Share this post


Link to post
Share on other sites

#9 ·  Posted (edited)

When i click UpDown would:

2001

2002

2003

2004

and not

2.001

2.002

2.003

2.004

and not

2000

3000

4000

5000

Why the bizzare arrangement of two input boxes then? You are reading 2000, 2001, 2002, etc. from $Input[0], and then multiplying it by 1000, giving you 2000000, 2001000, 2002000 to write to Input[1] (provided you fixed the thousands sep)? If you just want that number why not use just one input and leave the value in it alone?

:D

Edit: I just noticed that arrangement wasn't in your original, and the multiplication was because you didn't know it was clipping the value at the first comma. So the whole point was just to get rid of the thousands sep. Try it like this:

#include <ButtonConstants.au3>
#include <EditConstants.au3>
#include <GUIConstantsEx.au3>
#include <StaticConstants.au3>
#include <WindowsConstants.au3>
#include <WinAPI.au3> ; used for Lo/Hi word

Opt("TrayIconDebug", 1)
Opt("TrayIconHide", 0)

Dim $Input[1], $Updown[1]

$Form1_1 = GUICreate("ReDate", 161, 208, 192, 114, -1, $WS_EX_ACCEPTFILES)
$Label1 = GUICtrlCreateLabel("&Years", 16, 8, 37, 17)
$Input[0] = GUICtrlCreateInput("2000", 72, 8, 72, 21, BitOR($ES_NUMBER, $ES_RIGHT))
$Updown[0] = GUICtrlCreateUpdown($Input[0])
GUISetState(@SW_SHOW)

GUIRegisterMsg($WM_COMMAND, "WM_COMMAND")
Do
Until GUIGetMsg() = $GUI_EVENT_CLOSE
GUIDelete()

Func WM_COMMAND($hWnd, $iMsg, $iwParam, $ilParam)
    #forceref $hWnd, $iMsg
    Local $hWndFrom, $iIDFrom, $iCode, $hWndEdit
    If Not IsHWnd($Input[0]) Then $hWndAnno = GUICtrlGetHandle($Input[0])
    $hWndFrom = $ilParam
    $iIDFrom = _WinAPI_LoWord($iwParam)
    $iCode = _WinAPI_HiWord($iwParam)
    Switch $hWndFrom
        Case $GUI_EVENT_CLOSE
            Exit
        Case $hWndAnno, $Input[0]
            If $iCode = $EN_CHANGE Then
                GUICtrlSetData($Input[0], StringFormat('%d', StringReplace(GUICtrlRead($Input[0]), ",", "")))
            EndIf
    EndSwitch
EndFunc   ;==>WM_COMMAND

:D

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

Share this post


Link to post
Share on other sites

#10 ·  Posted (edited)

Why the bizzare arrangement of two input boxes then? You are reading 2000, 2001, 2002, etc. from $Input[0], and then multiplying it by 1000, giving you 2000000, 2001000, 2002000 to write to Input[1] (provided you fixed the thousands sep)? If you just want that number why not use just one input and leave the value in it alone?

:D

I inizialize $Input[0] with 2000 but when i clik UpDown it become 2.001 1.999 2.002

see:

http://www.autoitscript.com/forum/index.php?showtopic=101859&view=findpost&p=723748&hl=&fromsearch=1

I'm italian.

with:

ConsoleWrite(GUICtrlRead($Input[0]) & @LF)

it return:

2000

2.001

2.001

2.002

2.002

2.002

Edited by Ontosy

Share this post


Link to post
Share on other sites

I inizialize $Input[0] with 2000 but when i clik UpDown it become 2.001 1.999 2.002

see:

http://www.autoitscript.com/forum/index.php?showtopic=101859&view=findpost&p=723748&hl=&fromsearch=1

I'm italian.

with:

ConsoleWrite(GUICtrlRead($Input[0]) & @LF)

it return:

2000

2.001

2.001

2.002

2.002

2.002

See Edit in my post above.

:D


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

Share this post


Link to post
Share on other sites

See Edit in my post above.

:D

This code not do nothing now:

#include <ButtonConstants.au3>
#include <EditConstants.au3>
#include <GUIConstantsEx.au3>
#include <StaticConstants.au3>
#include <WindowsConstants.au3>
#include <WinAPI.au3> ; used for Lo/Hi word
Opt("TrayIconDebug",1)
Opt("TrayIconHide",0)
dim $Input[2],$Updown[1]

$Form1_1 = GUICreate("ReDate", 161, 208, 192, 114, -1,  $WS_EX_ACCEPTFILES)
$Label1 = GUICtrlCreateLabel("&Years", 16, 8, 37, 17)
$Input[0] = GUICtrlCreateInput("2000", 143, 8, 1, 21, BitOR($ES_NUMBER, $ES_RIGHT))
$Updown[0] = GUICtrlCreateUpdown($Input[0])
$input[1] = GUICtrlCreateInput("2000",72,8,56,21)
GUISetState(@SW_SHOW)

GUIRegisterMsg($WM_COMMAND, "WM_COMMAND")
Do
Until GUIGetMsg() = $GUI_EVENT_CLOSE
GUIDelete()

Func WM_COMMAND($hWnd, $iMsg, $iwParam, $ilParam)
    #forceref $hWnd, $iMsg
    Local $hWndFrom, $iIDFrom, $iCode, $hWndEdit
    If Not IsHWnd($Input[0]) Then $hWndAnno = GUICtrlGetHandle($Input[0])
    $hWndFrom = $ilParam
    $iIDFrom = _WinAPI_LoWord($iwParam)
    $iCode = _WinAPI_HiWord($iwParam)
    Switch $hWndFrom
        Case $GUI_EVENT_CLOSE
            Exit
        Case $hWndAnno, $Input[0]
            if $iCode=$EN_CHANGE Then
                $sRead = GUICtrlRead($Input[0])
                $sWrite = StringFormat('%d', $sRead)
                $iWrite = $sWrite * 1000
                ConsoleWrite("Debug: $sRead = " & $sRead & ", $sWrite = " & $sWrite & ", $iWrite = " & $iWrite & @LF)
                GUICtrlSetData($Input[1], $iWrite)
            EndIf
    EndSwitch
EndFunc

Share this post


Link to post
Share on other sites

I didn't understand from your first 2 posts that you just wanted to remove the commas and I still don't understand what the porblem is you are having.

Can you tell us what is wrong with the code PsaltyDS posted because it seems to work fine for me.

The code you posted doesn't work because you ignoring what you have been told about commas.

This is a correction to what you posted, but I don't see why it is better than what PsaltDS did unless you can explain the problem.

#include <ButtonConstants.au3>
#include <EditConstants.au3>
#include <GUIConstantsEx.au3>
#include <StaticConstants.au3>
#include <WindowsConstants.au3>
#include <WinAPI.au3> ; used for Lo/Hi word
Opt("TrayIconDebug",1)
Opt("TrayIconHide",0)
dim $Input[2],$Updown[1]

$Form1_1 = GUICreate("ReDate", 161, 208, 192, 114, -1,  $WS_EX_ACCEPTFILES)
$Label1 = GUICtrlCreateLabel("&Years", 16, 8, 37, 17)
$Input[0] = GUICtrlCreateInput("2000", 143, 8, 1, 21, BitOR($ES_NUMBER, $ES_RIGHT))
$Updown[0] = GUICtrlCreateUpdown($Input[0])
$input[1] = GUICtrlCreateInput("2000",72,8,56,21)
GUISetState(@SW_SHOW)

GUIRegisterMsg($WM_COMMAND, "WM_COMMAND")
Do
Until GUIGetMsg() = $GUI_EVENT_CLOSE
GUIDelete()

Func WM_COMMAND($hWnd, $iMsg, $iwParam, $ilParam)
    #forceref $hWnd, $iMsg
    Local $hWndFrom, $iIDFrom, $iCode, $hWndEdit
    If Not IsHWnd($Input[0]) Then $hWndAnno = GUICtrlGetHandle($Input[0])
    $hWndFrom = $ilParam
    $iIDFrom = _WinAPI_LoWord($iwParam)
    $iCode = _WinAPI_HiWord($iwParam)
    Switch $hWndFrom
        Case $GUI_EVENT_CLOSE
            Exit
        Case $hWndAnno, $Input[0]
            if $iCode=$EN_CHANGE Then
                $sRead = StringReplace(GUICtrlRead($Input[0]),',','')
                $sRead = StringReplace($sRead,'.','')
                GUICtrlSetData($Input[1], $sRead)
            EndIf
    EndSwitch
EndFunc

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.

Share this post


Link to post
Share on other sites

Ty, now it is ok! :D

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