FrancescoDiMuro

The script confuse the GUIs...

33 posts in this topic

#1 ·  Posted (edited)

Good morning guys! How are you? Hope you're all fine :) I'm here to expose an issue that occurred already too many times... I'm talking about GUI's confusion... A big confusion could be the title of this topic, so, I'll try to explain in my best way...
I have a GUI ( that we'll call main GUI ), that, on the "event" button click, open a different GUI, based on the button that have been clicked. The "software" I'm developing is to manage the society warehouse, so, it has every function that a software that manages a warehouse should have ( watching stocks, add products, withdraw products, create DDT and so on... ). The issue that occurs sometimes, is: "When I click on the button "Add Product", the script does something like that:

  • Step 1: wait for the barcode of the product, in order to go to the Step 2;
  • Step 2: look for the barcode scanned in the database ( an Excel file );
  • Step 2.1: if the barcode has been found, simply prompt an InputBox to insert the quantity of the prodcut that has to be inserted;
  • Else: Step 2.2: if the barcode hasn't been found in the database, open a GUI which allows the user to insert the product in the database.

The button "Withdraw Product" does the same thing, less the "adding new product" function.
So, the issue is: "When I click on AddProduct, sometimes the script opens the WithdrawProduct GUI, and vice versa..."
Since I'm using this function to run one of the function I have ( AddProduct = AggiungiProdotto(), WithdrawProduct = PrelevaProdotto() ), I don't know if the issue is because of this...
I don't know how to fix this issue...
I can't post the whole code because of society copyright, so, don't ask me to post the code I'm using. I'll just post the code of what I've described above.

My_WM_COMMAND:
 

Func My_WM_COMMAND($hwnd, $msg, $wparam, $lparam)
    If _WinAPI_LoWord($wparam) = $input_CodiceProdottoPrelievo And _WinAPI_HiWord($wparam) = $EN_UPDATE And Sleep(250) And GUICtrlRead($input_CodiceProdottoPrelievo) <> "" Then
        PrelevaProdotto()
        GUICtrlSetState($input_CodiceProdottoPrelievo, $GUI_FOCUS)
    ElseIf _WinAPI_LoWord($wparam) = $input_CodiceProdottoAggiunta And _WinAPI_HiWord($wparam) = $EN_UPDATE And Sleep(250) And GUICtrlRead($input_CodiceProdottoAggiunta) <> "" Then
        AggiungiProdotto()
    EndIf
    Return $GUI_RUNDEFMSG
EndFunc ; >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>> My_WM_COMMAND_PrelevaProdotto($hwnd, $msg, $wparam, $lparam)

GUIPrelevaProdotto:
 

Func GUIPrelevaProdotto()
    #Region ### START Koda GUI section ### Form=C:\Users\Portatile-60\Documents\Documenti Lavoro\AutoIt\Gestione Magazzino\form_PrelevaProdotto.kxf
    $form_PrelevaProdotto = GUICreate("Preleva Prodotto...", 334, 108, @DesktopWidth/2 - 167, @DesktopHeight/2 - 161) ; 192, 124
    $input_CodiceProdottoPrelievo = GUICtrlCreateInput("", 16, 80, 305, 21)
    $input_MagazzinoSelezionato = GUICtrlCreateInput("", 240, 16, 81, 21)
    GUICtrlSetData($input_MagazzinoSelezionato, $sFlagMagazzino)
    GUICtrlSetColor($input_MagazzinoSelezionato, $COLOR_GREEN)
    $label_Titolo = GUICtrlCreateLabel("Preleva Prodotto", 12, 10, 218, 33)
    GUICtrlSetFont(-1, 18, 800, 0, "Arial")
    $button_MagazzinoRockwell = GUICtrlCreateButton("Magazzino Rockwell", 25, 48, 139, 25)
    GUICtrlSetFont(-1, 10, 800, 0, "Arial")
    $button_MagazzinoSiemens = GUICtrlCreateButton("Magazzino Siemens", 169, 48, 139, 25)
    GUICtrlSetFont(-1, 10, 800, 0, "Arial")
    GUISetState(@SW_SHOW, $form_PrelevaProdotto)
    #EndRegion ### END Koda GUI section ###
EndFunc ; >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>> GUIPrelevaProdotto()

GUIAggiungiProdotto:
 

Func GUIAggiungiProdotto()
    #Region ### START Koda GUI section ### Form=C:\Users\maybe\Documents\AutoIt\Gestione Magazzino\form_AggiungiProdotto.kxf
    $form_AggiungiProdotto = GUICreate("Aggiungi Prodotto...", 334, 108, @DesktopWidth/2 - 167, @DesktopHeight/2 - 161) ; 418, 283
    $input_CodiceProdottoAggiunta = GUICtrlCreateInput("", 16, 80, 305, 21)
    $input_MagazzinoSelezionato = GUICtrlCreateInput("", 240, 16, 81, 21)
    GUICtrlSetData($input_MagazzinoSelezionato, $sFlagMagazzino)
    GUICtrlSetColor($input_MagazzinoSelezionato, $COLOR_GREEN)
    $label_Titolo = GUICtrlCreateLabel("Aggiungi Prodotto", 12, 10, 218, 33)
    GUICtrlSetFont(-1, 18, 800, 0, "Arial")
    $button_MagazzinoRockwell = GUICtrlCreateButton("Magazzino Rockwell", 25, 48, 139, 25)
    GUICtrlSetFont(-1, 10, 800, 0, "Arial")
    $button_MagazzinoSiemens = GUICtrlCreateButton("Magazzino Siemens", 169, 48, 139, 25)
    GUICtrlSetFont(-1, 10, 800, 0, "Arial")
    GUISetState(@SW_SHOW, $form_AggiungiProdotto)
    #EndRegion ### END Koda GUI section ###
EndFunc ; >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>> GUIAggiungiProdotto()

I promise that, to everyone who will help me, will receive a "Honorable Mention" in my software, and surely a donation for this fantastic communtiy! 
Thanks guys for your help! :)
Have a good day!
Francesco 

EDIT: to proof what I'm saying, look at that:
Errore.PNG

I clicked the Add Product button, but, when I scan the code, it runs the PrelevaProdotto function...
I think that the problem is in the My_WM_COMMAND function, but I don't know where I am wrong! Can you please help me? Thanks :) 

Edited by FrancescoDiMuro

Click here to see my signature:

Spoiler

I will always thank you for the time you spent for me.
I'm here to ask, and from your response, I'd like to learn.
By my knowledge, I can help someone else, and "that someone" could help in turn another, and so on.

Share this post


Link to post
Share on other sites



FrancescoDiMuro,

You say you have 2 buttons in your GUI - yet you are calling the functions from within a Windows handler. Why are you not calling  the functions directly from the respective buttonpress events?

Added to this, you have two Sleep(250) calls in your handler. I regard 500ms as the absolute maximum that you should remain in a handler, so having those 2 calls already puts you at the limit, regardless of what other code runs. In my opinion, you are asking for trouble and it will come back and bite you one day.

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
1 minute ago, Melba23 said:

FrancescoDiMuro,

You say you have 2 buttons in your GUI - yet you are calling the functions from within a Windows handler. Why are you not calling  the functions directly from the respective buttonpress events?

Added to this, you have two Sleep(250) calls in your handler. I regard 500ms as the absolute maximum that you should remain in a handler, so having those 2 calls already puts you at the limit, regardless of what other code runs. In my opinion, you are asking for trouble and it will come back and bite you one day.

M23

Hey Melba, good morning. 
First, thanks for your reply.
Second, I'll ask to your questions... 

  1. Why are you not calling  the functions directly from the respective buttonpress events?
    Because I want the function call when the code is scanned, and I have to do ( do you know another way ) with $EN_UPDATE event;
  2. Added to this, you have two Sleep(250) calls in your handler.
    I had to add these Sleep(250) because, when I scan the code, the $EN_UPDATE is too fast, and read ONLY the first character of the barcode.

So, any suggestion? :) 


Click here to see my signature:

Spoiler

I will always thank you for the time you spent for me.
I'm here to ask, and from your response, I'd like to learn.
By my knowledge, I can help someone else, and "that someone" could help in turn another, and so on.

Share this post


Link to post
Share on other sites

FrancescoDiMuro,

Firstly, I have already asked you to stop using the "Quote" button when replying - your threads become so cluttered with quotes it is often difficult to follow them. Quoting should only be used when absolutely necessary to clarify your post.

Now, what error-checking have you done to see why the wrong GUI appears? You have 2 sets of conditions which you check - one of the conditions might well be wrongly showing as correct. An obvious case is the condition that the relevant input is not empty - i.e. GUICtrlRead($input_CodiceProdottoPrelievo) <> "" - but do you clear the input in question after each use? If not, then the condition might well be true even when it should not be and the wrong function fired as a result.

I am not saying that this is the solution to your problem, but it is the sort of thing that you need to check - particularly as you will not let us see the full code (which we probably could not run anyway). You need to do a lot of error-checking on your code to determine why the wrong If statement decides to fire - there is very little anyone else can do to help.

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

#5 ·  Posted (edited)

@Melba23
After each use of the AggiungiProdotto or PrelevaProdotto, when I have done what I had to do, I simply do this:

For PrelevaProdotto:

 

Case $form_PrelevaProdotto
                Switch $aMsg[0]
                    Case $GUI_EVENT_CLOSE
                        GUICtrlSetData($input_CodiceProdottoPrelievo, "")
                        GUIDelete($form_PrelevaProdotto)
                        $sStatoDDT = "FINE"

For AggiungiProdotto:
 

Case $form_AggiungiProdotto
                Switch $aMsg[0]
                    Case $GUI_EVENT_CLOSE
                        GUICtrlSetData($input_CodiceProdottoAggiunta, "")
                        GUIDelete($form_AggiungiProdotto)

Am I still wrong? That's not enough?
Thanks :) 

Edited by FrancescoDiMuro

Click here to see my signature:

Spoiler

I will always thank you for the time you spent for me.
I'm here to ask, and from your response, I'd like to learn.
By my knowledge, I can help someone else, and "that someone" could help in turn another, and so on.

Share this post


Link to post
Share on other sites

FrancescoDiMuro,

Quote

Am I still wrong? That's not enough?

That would seem to be sufficient to make my guess invalid. But have you actually checked what the various conditions are returning within the handler so you can be sure?

Anyway, I am not prepared to spend any more time guessing at what might be wrong with a script I cannot examine in detail and doubtless could not run even if I could - good luck.

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

I've provided you of everything you need to have to say: "Maybe it's this, maybe not".
But ok. Thanks...  


Click here to see my signature:

Spoiler

I will always thank you for the time you spent for me.
I'm here to ask, and from your response, I'd like to learn.
By my knowledge, I can help someone else, and "that someone" could help in turn another, and so on.

Share this post


Link to post
Share on other sites

FrancescoDiMuro,

Quote

I've provided you of everything you need to have to say: "Maybe it's this, maybe not".

You are joking, right? Two functions and a handler do not offer a great deal of scope for suggesting where an error might lie.

And have you actually done any debugging yet within the handler along the lines I suggested above?

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

#9 ·  Posted (edited)

I don't know HOW TO DEBUG THOSE THINGS. In this forum, unfortunately, there is a lot of knowledge, but, it's not explained in the best way! For newcomers as I am, you, Professors, Scientists, and so on, should do a DETAILED GUIDE on all those things. In the AutoIt Help file, as you often quote, there's no explanation about those things... What's a debug? How can the user do it? What's better in what situation? I explained AT ALL what I'd like to develop, but you keep asking to me something that I don't know, and YES, I provided you about what do you need. 

Legend about this post:
[?] : What is this? Where can I found some DETAILED documentation?
[!] : This thing exists in the AutoIt Guide, but could be documented better!

My_WM_COMMAND:

Func My_WM_COMMAND($hwnd, $msg, $wparam, $lparam)
     If _WinAPI_LoWord($wparam) = $input_CodiceProdottoPrelievo And _WinAPI_HiWord($wparam) = $EN_UPDATE And Sleep(150) And GUICtrlRead($input_CodiceProdottoPrelievo) <> "" Then
        PrelevaProdotto()
        GUICtrlSetState($input_CodiceProdottoPrelievo, $GUI_FOCUS)
    ElseIf _WinAPI_LoWord($wparam) = $input_CodiceProdottoAggiunta And _WinAPI_HiWord($wparam) = $EN_UPDATE And Sleep(150) And GUICtrlRead($input_CodiceProdottoAggiunta) <> "" Then
        AggiungiProdotto()
    EndIf
    Return $GUI_RUNDEFMSG
EndFunc ; >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>> My_WM_COMMAND_PrelevaProdotto($hwnd, $msg, $wparam, $lparam)

This is the function that "captures" the event $EN_CHANGE. [!][?]: About $EN_CHANGE, I didn't find anything in the AutoIt documentation.
Have I to check this instead of what is posted above?

If _WinAPI_LoWord($wparam) = GUICtrlGetHande($input_CodiceProdottoPrelievo) And _WinAPI_HiWord($wparam) = $EN_UPDATE And Sleep(150) And GUICtrlRead($input_CodiceProdottoPrelievo) <> "" Then ; GUICtrlGetHandle() instead of the GUICtrlCreateInput ID?
...
EndIf

What do you mean when you say...

Quote

Added to this, you have two Sleep(250) calls in your handler. I regard 500ms as the absolute maximum that you should remain in a handler, so having those 2 calls already puts you at the limit, regardless of what other code runs. In my opinion, you are asking for trouble and it will come back and bite you one day.


... more than a sarcastic response?
I've added THESE Sleep(250), because I've already told you that, If I remove them, the script doesn't allow my barcode scanner, as EVERY input ( Ctrl + V too ), to "type" more than 1 character. So, I CAN'T DO what I NEED TO DO.
Teach a NOOB as I am those things! I've always said: "I would like to learn all these things", when someone gives me an answer to something that I couldn't understand...
As the proverb: "Give a man a fish, and he'll eat for a day; teach him how to fish, and he will eat for a lifetime".
Telling me "Have you done a debug, I don't waste my time on code that I can't see, I bla bla bla", you're not helping me, you're just leaving me alone with something that I don't know and I'll never know until someone ( like you or like someone that knows a lot about these things ) teach me!
Give me some references! I'll try to understand them, for sure! 
But just telling what to do instead of telling what to do and how to do it, it's not helping at all.

What do you need? The whole code? Declarations?
Here you are the declarations:

In the "main":

GUIRegisterMsg($WM_NOTIFY, "My_WM_NOTIFY")
GUIRegisterMsg($WM_COMMAND, "My_WM_COMMAND")

 

Global $input_CodiceProdottoPrelievo, $input_CodiceProdottoAggiunta

What do you need again? Tell me! I'll provide you, but I CAN'T, because there are a lot of jackals who want MY CODE, and I don't want to share with them! I'm in a company, so I CAN'T post my code, because what I've done for the company, is of MY COMPANY, and not of everyone.
Sorry for the rash, but I've always hate people who just tell: "You could do in this way, but I don't ask to you if you don't post your code...", without giving to you any f*cking reference to look at... If you wanna help me, I'm here... Otherwise, don't ask.

EDIT: I noted that the issue occurs when I press button_AggiungiProdotto, I close the GUI, I press button_PrelevaProdotto, I close the GUI, and I press again button_AggiungiProdotto. What does happen? :/ 

Edited by FrancescoDiMuro
Further information...

Click here to see my signature:

Spoiler

I will always thank you for the time you spent for me.
I'm here to ask, and from your response, I'd like to learn.
By my knowledge, I can help someone else, and "that someone" could help in turn another, and so on.

Share this post


Link to post
Share on other sites

#10 ·  Posted

FrancescoDiMuro,

Quote

I don't know HOW TO DEBUG THOSE THINGS

The why did you not ask?

Quote

What do you mean when you say...... more than a sarcastic response?

It was a genuine remark pointing out that, as you should return from a Windows handler "as soon as possible" (as explained in the help file), adding Sleep commands was ill-advised at best and catastrophic at worst. No sarcasm, just an honest response to the little code you posted - and I greatly resent the implication that it was anything more.

Quote

I'll provide you, but I CAN'T, because there are a lot of jackals who want MY CODE, and I don't want to share with them! I'm in a company, so I CAN'T post my code, because what I've done for the company, is of MY COMPANY, and not of everyone.

I quite understand your position, but you fail to appreciate the corollary - we cannot offer sensible help on code we cannot see. So many times I have seen that an error creeps in far from where you expect it to be - so without the whole code to crawl through it become impossible to suggest what is causing an intermittent error such as the one you are experiencing.

So wind your neck hard back in and we might well talk shortly about how you might do some debugging of your own script instead of expecting someone else to magically understand the code you  have written but no-one else is allowed to see.

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

#11 ·  Posted

I'm here...


Click here to see my signature:

Spoiler

I will always thank you for the time you spent for me.
I'm here to ask, and from your response, I'd like to learn.
By my knowledge, I can help someone else, and "that someone" could help in turn another, and so on.

Share this post


Link to post
Share on other sites

#12 ·  Posted

FrancescoDiMuro,

Right, let us talk about how you can do some debugging. I am assuming you are running the script from SciTE - if not then you will have to write to some form of log file but the principles are the same.

If you change your handler to this, you should see the lines appear in the SciTE console each time it is actioned and you can tell whether the correct conditions were actually met:

Func My_WM_COMMAND($hwnd, $msg, $wparam, $lparam)
    
    ; Try a single Sleep here - that will still give you the delay but not overstrech the handler time
    Sleep(250)
    
    ; Now we need to check what each of the required conditions returns so that we can check if there is a problem and where it lies
    
    ; The common condition is EN_UPDATE so let us use that as a filter
    If _WinAPI_HiWord($wparam) = $EN_UPDATE Then
        ; Now we will not get the information for every WM_COMMAND call - only the EN_UPDATE ones
        
        ; First check the control that fired the message
        If _WinAPI_LoWord($wparam) = $input_CodiceProdottoPrelievo Then
            ConsoleWrite("Prelievo: ")
        ElseIf
            ConsoleWrite("Aggiunta: ")
        EndIf
        
        ; Then let us check the various conditions:
        If _WinAPI_LoWord($wparam) = $input_CodiceProdottoPrelievo And GUICtrlRead($input_CodiceProdottoPrelievo) <> "" Then
        
            ; This will give us the content of the relevant input
            ConsoleWrite("Input content: " & GUICtrlRead($input_CodiceProdottoPrelievo) & @CRLF)
            PrelevaProdotto()
            GUICtrlSetState($input_CodiceProdottoPrelievo, $GUI_FOCUS)
        
        ElseIf _WinAPI_LoWord($wparam) = $input_CodiceProdottoAggiunta And GUICtrlRead($input_CodiceProdottoAggiunta) <> "" Then
        
            ; And the same here
            ConsoleWrite(@TAB & GUICtrlRead($input_CodiceProdottoAggiunta) & @CRLF)
            AggiungiProdotto()
        EndIf
        
    EndIf
    
    Return $GUI_RUNDEFMSG
EndFunc   ;==>My_WM_COMMAND

At least we will then know whether it is the handler which is misbehaving.

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

#13 ·  Posted (edited)

Here you are:
 

>"C:\Program Files (x86)\AutoIt3\SciTE\..\AutoIt3.exe" "C:\Program Files (x86)\AutoIt3\SciTE\AutoIt3Wrapper\AutoIt3Wrapper.au3" /run /prod /ErrorStdOut /in "C:\Users\Portatile-60\Documents\Documenti Lavoro\AutoIt\Gestione Magazzino\Gestione_Magazzino_SYS.au3" /UserParams    
+>16:41:40 Starting AutoIt3Wrapper v.16.612.1119.0 SciTE v.3.6.6.0   Keyboard:00000410  OS:WIN_10/  CPU:X64 OS:X64  Environment(Language:0410)  CodePage:0  utf8.auto.check:4
+>         SciTEDir => C:\Program Files (x86)\AutoIt3\SciTE   UserDir => C:\Users\Portatile-60\AppData\Local\AutoIt v3\SciTE\AutoIt3Wrapper   SCITE_USERHOME => C:\Users\Portatile-60\AppData\Local\AutoIt v3\SciTE 
>Running AU3Check (3.3.14.2)  from:C:\Program Files (x86)\AutoIt3  input:C:\Users\Portatile-60\Documents\Documenti Lavoro\AutoIt\Gestione Magazzino\Gestione_Magazzino_SYS.au3
+>16:41:40 AU3Check ended.rc:0
>Running:(3.3.14.2):C:\Program Files (x86)\AutoIt3\autoit3.exe "C:\Users\Portatile-60\Documents\Documenti Lavoro\AutoIt\Gestione Magazzino\Gestione_Magazzino_SYS.au3"    
--> Press Ctrl+Alt+Break to Restart or Ctrl+Break to Stop
Aggiunta: Aggiunta: Aggiunta:   1P6ES7315'2EH14'0AB0
Aggiunta: Aggiunta: Prelievo: Input content: 1P6ES7315'2EH14'0AB0
Prelievo: Aggiunta: Prelievo: Input content: 1P6ES7315'2EH14'0AB0

I did the following "steps":

  1. F5 ( run the code );
  2. Pressed button AddProduct;
  3. Scanned the code;
  4. Exit the AddProduct GUI;
  5. Pressed button WithdrawProduct;
  6. Scanned the code;
  7. Exit the WithdrawProduct GUI;
  8. Step 2;
  9. Step 3;
  10. Error :D 

By the way, at line 15 there is an error: Else instead of ElseIf...

Edited by FrancescoDiMuro

Click here to see my signature:

Spoiler

I will always thank you for the time you spent for me.
I'm here to ask, and from your response, I'd like to learn.
By my knowledge, I can help someone else, and "that someone" could help in turn another, and so on.

Share this post


Link to post
Share on other sites

#14 ·  Posted

FrancescoDiMuro,

That appears to show that the handler worked correctly 3 times:

- These lines are my interpretation of what is going on
- Pressed button AddProduct
Aggiunta:
Aggiunta: 
- Scanned the code
Aggiunta: Input content: 1P6ES7315'2EH14'0AB0
- And the AddProduct function is fired
- Exit the AddProduct GUI
- Pressed button WithdrawProduct
Aggiunta: 
Aggiunta: 
- Scanned the code
Prelievo: Input content: 1P6ES7315'2EH14'0AB0
- And the WithdrawProduct function is fired
- Exit the WithdrawProduct GUI
- Pressed button AddProduct again
Prelievo: 
Aggiunta: 
- Scanned the code again
Prelievo: Input content: 1P6ES7315'2EH14'0AB0
- But the WithdrawProduct function is fired when it should not have been

So it would seem that the final incorrect GUI is indeed being initiated by the handler, but that the triggering message is being received from the other, incorrect input. I think that the problem comes because you are not telling the handler which of the inputs to check - you can see that there are several EN_UPDATE calls where the relevant input is empty before the one which actually fires the relevant function.

I think you would be better placed to set a Global variable to the required input ControlID when you press the Add/Withdraw button - then you can check that only the correct input can activate its function. Something along these lines:

; Create a Global variable to hold the input ControlID
Global $cAddWithdraw_Input_CID = 9999 ; This is just a place holder value
;


; Now when you action the buttons I suggest something like this (I am assuming MessageLoop mode but converting to OnEvent is not difficult)
    Case $cAddProduct_Button
        $cAddWithdraw_Input_CID = $input_CodiceProdottoAggiunta ; The correct input ControlID is set in the Global variable
        ; other code
    Case $cWithdrawProduct_Button
        $cAddWithdraw_Input_CID = $input_CodiceProdottoPrelievo
        ; other code
;


; Now your handler will look like this:
Func My_WM_COMMAND($hwnd, $msg, $wparam, $lparam)
    
    ; Try a single Sleep here - that will still give you the delay but not overstrech the handler time
    Sleep(250)
    
    ; The common condition is EN_UPDATE so let us use that as a filter
    If _WinAPI_HiWord($wparam) = $EN_UPDATE Then
                
        ; Next check that the expected input control fired the message so that we will only ever action the correct function
        If _WinAPI_LoWord($wparam) = $cAddWithdraw_Input_CID Then
            
            ; We are now sure that the correct input sent the message, so check if that input has some content
            If GUICtrlRead($cAddWithdraw_Input_CID) <> "" Then
                
                ; If it has content, then fire the correct function depending on the Global variable ControlID
                If $cAddWithdraw_Input_CID = $input_CodiceProdottoPrelievo Then
                    PrelevaProdotto()
                    GUICtrlSetState($input_CodiceProdottoPrelievo, $GUI_FOCUS)
                ElseIf $cAddWithdraw_Input_CID = $input_CodiceProdottoAggiunta Then
                    AggiungiProdotto()
                    GUICtrlSetState($input_CodiceProdottoAggiunta, $GUI_FOCUS)
                EndIf
            EndIf
        EndIf
    EndIf
    
    Return $GUI_RUNDEFMSG
EndFunc   ;==>My_WM_COMMAND

Try that and see if it behaves better.

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

#15 ·  Posted

Just an observation - when you clear your input area you are also driving EN_UPDATE...


Forum Rules         Procedure for posting code

"I like pigs.  Dogs look up to us.  Cats look down on us.  Pigs treat us as equals."

- Sir Winston Churchill

Share this post


Link to post
Share on other sites

#16 ·  Posted

3 hours ago, kylomas said:

Just an observation - when you clear your input area you are also driving EN_UPDATE...

Good morning kylomas... What do you mean with "driving EN_UPDATE"? Thanks :) 


Click here to see my signature:

Spoiler

I will always thank you for the time you spent for me.
I'm here to ask, and from your response, I'd like to learn.
By my knowledge, I can help someone else, and "that someone" could help in turn another, and so on.

Share this post


Link to post
Share on other sites

#17 ·  Posted (edited)

@Melba23
Good Morning and thanks :) I'll test it out right now and I'll update you :) Thanks! 

EDIT: The code you posted doesn't allow the user anymore to scan the code... When I do the scan, it remains there, without doing anything...

Here is the code I changed:

 

Global $control_Button_Pressed = 9999
Case $button_PrelevaProdotto
        $control_Button_Pressed = $input_CodiceProdottoPrelievo
        GUIPrelevaProdotto() ; Here I create the GUI of PrelevaProdotto
Case $button_AggiungiProdotto
        $control_Button_Pressed = $input_CodiceProdottoAggiunta
        GUIAggiungiProdotto() ; Here I create the GUI of AggiungiProdotto
Func My_WM_COMMAND($hwnd, $msg, $wparam, $lparam)
    Sleep(250)
    If _WinAPI_HiWord($wparam) = $EN_UPDATE Then
        If _WinAPI_LoWord($wparam) = $control_Button_Pressed Then
            If GUICtrlRead($control_Button_Pressed) <> "" Then
                If $control_Button_Pressed = $input_CodiceProdottoPrelievo Then
                    PrelevaProdotto()
                    GUICtrlSetState($input_CodiceProdottoPrelievo, $GUI_FOCUS)
                ElseIf $control_Button_Pressed = $input_CodiceProdottoAggiunta Then
                    AggiungiProdotto()
                    GUICtrlSetState($input_CodiceProdottoAggiunta, $GUI_FOCUS)
                EndIf
            EndIf
        EndIf
    EndIf
    Return $GUI_RUNDEFMSG
EndFunc ; >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>> My_WM_COMMAND_PrelevaProdotto($hwnd, $msg, $wparam, $lparam)

What could be wrong? :/ Thanks :) 

Edited by FrancescoDiMuro

Click here to see my signature:

Spoiler

I will always thank you for the time you spent for me.
I'm here to ask, and from your response, I'd like to learn.
By my knowledge, I can help someone else, and "that someone" could help in turn another, and so on.

Share this post


Link to post
Share on other sites

#18 ·  Posted

FrancescoDiMuro,

You are trying to assign the ControlID of the input before it is created - change the order of the lines:

Case $button_PrelevaProdotto
        GUIPrelevaProdotto() ; Here I create the GUI of PrelevaProdotto
        $control_Button_Pressed = $input_CodiceProdottoPrelievo
Case $button_AggiungiProdotto
        GUIAggiungiProdotto() ; Here I create the GUI of AggiungiProdotto
        $control_Button_Pressed = $input_CodiceProdottoAggiunta

See if that works.

M23

P.S. And I think it best that you reset the Global variable to a placesetter value when you delete the Add/Withdraw GUI to prevent any inadvertent firings.


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

#19 ·  Posted

@Melba23
Hey Melba, the error occurs anyway... :/ 


Click here to see my signature:

Spoiler

I will always thank you for the time you spent for me.
I'm here to ask, and from your response, I'd like to learn.
By my knowledge, I can help someone else, and "that someone" could help in turn another, and so on.

Share this post


Link to post
Share on other sites

#20 ·  Posted

FrancescoDiMuro,

Then I am out of ideas - sorry.

As I have explained above, trying to debug a script based on just a few snippets is not easy and I am not at all surprised that some minor untested tinkering with those snippets does not resolve the problem. I understand your reasons for not wanting to post your script, but you must understand the limitations that poses to anyone offering to help with the code.

Good luck in finding a solution.

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
Guest
This topic is now closed to further replies.