Jump to content

Suspend script execution in an If...Else...EndIf statement?


Recommended Posts

Local $bOk
            $sAddCodiceProdotto = GUICtrlRead($input_Codice)
            $bOk = ControllaInserimento($sAddCodiceProdotto)
            If($bOk = False) Then
                MsgBox($MB_ICONERROR, "Errore!", "Inserisci un 'Codice Prodotto' per continuare.", 3)
                GUICtrlSetState($input_Codice, $GUI_FOCUS)
            Else
                _Excel_RangeWrite($oWorkbook, $oWorkbook.ActiveSheet, $sAddCodiceProdotto, "A" & $iIndiceRigaVuota)                ; Codice Prodotto
            EndIf
            $sAddMarcaProdotto = GUICtrlRead($input_Marca)
            If($sAddMarcaProdotto = "") Then
                MsgBox($MB_ICONERROR, "Errore!", "Inserisci una 'Marca Prodotto' per continuare.", 3)
                GUICtrlSetState($input_Marca, $GUI_FOCUS)
            Else
                _Excel_RangeWrite($oWorkbook, $oWorkbook.ActiveSheet, $sAddMarcaProdotto, "B" & $iIndiceRigaVuota)                 ; Marca
            EndIf
            $sAddQuantitaProdotto = GUICtrlRead($input_Quantita)
            If($sAddQuantitaProdotto = "") Then
                MsgBox($MB_ICONERROR, "Errore!", "Inserisci una 'Quantità Prodotto' per continuare.", 3)
                GUICtrlSetState($input_Quantita, $GUI_FOCUS)
            Else
                _Excel_RangeWrite($oWorkbook, $oWorkbook.ActiveSheet, $sAddQuantitaProdotto, "C" & $iIndiceRigaVuota)              ; Quantità
            EndIf

It goes straight, without blocking in the function... 
The code shows all MsgBoxes, even if I did as you guys said...
 

Click here to see my signature:

Spoiler

ALWAYS GOOD TO READ:

 

Link to comment
Share on other sites

It doesn't work, FUCK!

$sAddCodiceProdotto = GUICtrlRead($input_Codice) ; Codice Prodotto
            ControllaInserimento($sAddCodiceProdotto, $oWorkbook, "A", $iIndiceRigaVuota)
            $sAddMarcaProdotto = GUICtrlRead($input_Marca) ; Marca
            ControllaInserimento($sAddMarcaProdotto, $oWorkbook, "B", $iIndiceRigaVuota)
            $sAddQuantitaProdotto = GUICtrlRead($input_Quantita) ; Quantità
            ControllaInserimento($sAddQuantitaProdotto, $oWorkbook, "C", $iIndiceRigaVuota)
            $sAddScaffaleProdotto = GUICtrlRead($input_Scaffale) ; Scaffale
            _Excel_RangeWrite($oWorkbook, $oWorkbook.ActiveSheet, $sAddScaffaleProdotto, "D" & $iIndiceRigaVuota)
            $sAddDescrizioneProdotto = GUICtrlRead($edit_Descrizione) ; Descrizione
            ControllaInserimento($sAddDescrizioneProdotto, $oWorkbook, "E", $iIndiceRigaVuota)
            $sAddCostoProdotto = GUICtrlRead($input_Costo) ; Costo
            _Excel_RangeWrite($oWorkbook, $oWorkbook.ActiveSheet, $sAddCostoProdotto, "F" & $iIndiceRigaVuota)
            $sAddNote = GUICtrlRead($edit_Note) ; Note
            _Excel_RangeWrite($oWorkbook, $oWorkbook.ActiveSheet, $sAddNote, "G" & $iIndiceRigaVuota)
            $sAddInfo = GUICtrlRead($edit_Info) ; Info
            _Excel_RangeWrite($oWorkbook, $oWorkbook.ActiveSheet, $sDataOraModifica, "H" & $iIndiceRigaVuota)
            ; Riepilogo prodotto aggiunto
            MsgBox($MB_ICONINFORMATION, "Prodotto Aggiunto!", "Riepilogo prodotto aggiunto:" & @CRLF & @CRLF & _
                                                              "Codice Prodotto: " & $sAddCodiceProdotto & @CRLF & _
                                                              "Marca: " & $sAddMarcaProdotto & @CRLF & _
                                                              "Quantità: " & $sAddQuantitaProdotto & @CRLF & _
                                                              "Scaffale: " & $sAddScaffaleProdotto & @CRLF & _
                                                              "Descrizione: " & $sAddDescrizioneProdotto & @CRLF & _
                                                              "Costo: " & $sAddCostoProdotto & @CRLF & _
                                                              "Note: " & $sAddNote & @CRLF & _
                                                              "Info: " & $sAddInfo & @CRLF)
Func ControllaInserimento($sStringaDaAggiungere, $oCartellaDiLavoro, $iIndiceColonnaDoveScrivere, $iIndiceRigaDoveScrivere)
    If($sStringaDaAggiungere = "") Then
        MsgBox($MB_ICONERROR, "Errore!", "Inserisci un 'Codice Prodotto' per continuare.", 3)
        GUICtrlSetState($input_Codice, $GUI_FOCUS)
        Return
    EndIf
    _Excel_RangeWrite($oCartellaDiLavoro, $oCartellaDiLavoro.ActiveSheet, $sStringaDaAggiungere, $iIndiceColonnaDoveScrivere & $iIndiceRigaDoveScrivere)
EndFunc

It goes straingt...
I'm tired!

Edited by FrancescoDiMuro

Click here to see my signature:

Spoiler

ALWAYS GOOD TO READ:

 

Link to comment
Share on other sites

Try something like the following

Global $edit_Descrizione, $edit_Info, $edit_Note, $input_Codice, $input_Costo, $input_Marca, $input_Quantita, $input_Scaffale

;~ Gui code here
;~ Add the following to your GUI Button
ControllaInserimento($input_Codice, $oWorkbook, "A", $iIndiceRigaVuota)
ControllaInserimento($input_Marca, $oWorkbook, "B", $iIndiceRigaVuota)
ControllaInserimento($input_Quantita, $oWorkbook, "C", $iIndiceRigaVuota)
ControllaInserimento($input_Scaffale, $oWorkbook, "D", $iIndiceRigaVuota)
ControllaInserimento($edit_Descrizione, $oWorkbook, "E", $iIndiceRigaVuota)
ControllaInserimento($input_Costo, $oWorkbook, "F", $iIndiceRigaVuota)
ControllaInserimento($edit_Note, $oWorkbook, "G", $iIndiceRigaVuota)
ControllaInserimento($edit_Info, $oWorkbook, "H", $iIndiceRigaVuota)

;~ Parameter 1 = Name of the edit Control you wish to read
;~ Parameter 2 = Workbook name, if you only use 1 workbook you can remove this and just use $oWorkbook
;~ Parameter 3 = Excel Column String
;~ Parameter 4 = Excel Column Index
Func ControllaInserimento($hedit_Control, $oCartellaDiLavoro, $iIndiceColonnaDoveScrivere, $iIndiceRigaDoveScrivere)
    If GUICtrlRead($hedit_Control) = "" Then
        MsgBox($MB_ICONERROR, "Errore!", "Inserisci un 'Codice Prodotto' per continuare.", 3)
        GUICtrlSetState($hedit_Control, $GUI_FOCUS)
        Return
    EndIf
    _Excel_RangeWrite($oCartellaDiLavoro, $oCartellaDiLavoro.ActiveSheet, GUICtrlRead($hedit_Control), $iIndiceColonnaDoveScrivere & $iIndiceRigaDoveScrivere)
ConsoleWrite('Excel Range Write Return:' & @error & @CRLF)
EndFunc

 

Edited by Subz
Link to comment
Share on other sites

33 minutes ago, Subz said:

Try something like the following

Global $edit_Descrizione, $edit_Info, $edit_Note, $input_Codice, $input_Costo, $input_Marca, $input_Quantita, $input_Scaffale

;~ Gui code here

ControllaInserimento($input_Codice, $oWorkbook, "A", $iIndiceRigaVuota)
ControllaInserimento($input_Marca, $oWorkbook, "B", $iIndiceRigaVuota)
ControllaInserimento($input_Quantita, $oWorkbook, "C", $iIndiceRigaVuota)
ControllaInserimento($input_Scaffale, $oWorkbook, "D", $iIndiceRigaVuota)
ControllaInserimento($edit_Descrizione, $oWorkbook, "E", $iIndiceRigaVuota)
ControllaInserimento($input_Costo, $oWorkbook, "F", $iIndiceRigaVuota)
ControllaInserimento($edit_Note, $oWorkbook, "G", $iIndiceRigaVuota)
ControllaInserimento($edit_Info, $oWorkbook, "H", $iIndiceRigaVuota)

;~ Parameter 1 = Name of the edit Control you wish to read
;~ Parameter 2 = Workbook name, if you only use 1 workbook you can remove this and just use $oWorkbook
;~ Parameter 3 = Excel Column String
;~ Parameter 4 = Excel Column Index
Func ControllaInserimento($hedit_Control, $oCartellaDiLavoro, $iIndiceColonnaDoveScrivere, $iIndiceRigaDoveScrivere)
    If GUICtrlRead($hedit_Control) = "" Then
        MsgBox($MB_ICONERROR, "Errore!", "Inserisci un 'Codice Prodotto' per continuare.", 3)
        GUICtrlSetState($hedit_Control, $GUI_FOCUS)
        Return
    EndIf
    _Excel_RangeWrite($oCartellaDiLavoro, $oCartellaDiLavoro.ActiveSheet, GUICtrlRead($hedit_Control), $iIndiceColonnaDoveScrivere & $iIndiceRigaDoveScrivere)
EndFunc

 

So, the control should be done for each data I have to write? And why? :/
I did something like in the post #24, but doesn't work...

Click here to see my signature:

Spoiler

ALWAYS GOOD TO READ:

 

Link to comment
Share on other sites

48 minutes ago, Subz said:

Try something like the following

Global $edit_Descrizione, $edit_Info, $edit_Note, $input_Codice, $input_Costo, $input_Marca, $input_Quantita, $input_Scaffale

;~ Gui code here
;~ Add the following to your GUI Button
ControllaInserimento($input_Codice, $oWorkbook, "A", $iIndiceRigaVuota)
ControllaInserimento($input_Marca, $oWorkbook, "B", $iIndiceRigaVuota)
ControllaInserimento($input_Quantita, $oWorkbook, "C", $iIndiceRigaVuota) ; >>>>>> Even If I don't care to check this field, I have to check it?
ControllaInserimento($input_Scaffale, $oWorkbook, "D", $iIndiceRigaVuota) ; >>>>>> ... And this too... ?
ControllaInserimento($edit_Descrizione, $oWorkbook, "E", $iIndiceRigaVuota)
ControllaInserimento($input_Costo, $oWorkbook, "F", $iIndiceRigaVuota)
ControllaInserimento($edit_Note, $oWorkbook, "G", $iIndiceRigaVuota)
ControllaInserimento($edit_Info, $oWorkbook, "H", $iIndiceRigaVuota)

;~ Parameter 1 = Name of the edit Control you wish to read
;~ Parameter 2 = Workbook name, if you only use 1 workbook you can remove this and just use $oWorkbook
;~ Parameter 3 = Excel Column String
;~ Parameter 4 = Excel Column Index
Func ControllaInserimento($hedit_Control, $oCartellaDiLavoro, $iIndiceColonnaDoveScrivere, $iIndiceRigaDoveScrivere)
    If GUICtrlRead($hedit_Control) = "" Then
        MsgBox($MB_ICONERROR, "Errore!", "Inserisci un 'Codice Prodotto' per continuare.", 3)
        GUICtrlSetState($hedit_Control, $GUI_FOCUS)
        Return
    EndIf
    _Excel_RangeWrite($oCartellaDiLavoro, $oCartellaDiLavoro.ActiveSheet, GUICtrlRead($hedit_Control), $iIndiceColonnaDoveScrivere & $iIndiceRigaDoveScrivere)
ConsoleWrite('Excel Range Write Return:' & @error & @CRLF)
EndFunc

 

Look at the comments...

Click here to see my signature:

Spoiler

ALWAYS GOOD TO READ:

 

Link to comment
Share on other sites

2 minutes ago, Subz said:

Well no you don't have to add those, if you don't want, I was just replicating your code in Post#24

Can you please post your complete code, so I can try it and see where am I wrong, because I'm going crazy... Thanks :) 

Click here to see my signature:

Spoiler

ALWAYS GOOD TO READ:

 

Link to comment
Share on other sites

#include <Excel.au3>
#include <GUIConstantsEx.au3>

Opt('ExpandVarStrings', 1)

Global $edit_Descrizione, $edit_Info, $edit_Note, $input_Codice, $input_Costo, $input_Marca, $input_Quantita, $input_Scaffale
Global $oExcel = _Excel_Open()
Global $oWorkbook = _Excel_BookNew($oExcel)

Example()

Func Example()
    ; Create a GUI with various controls.
    Local $iIndiceRigaVuota = 1
    Local $hGUI = GUICreate('Example', 300, 285)
    $input_Codice = GUICtrlCreateInput('Codice', 5, 10, 290, 20)
    $input_Marca = GUICtrlCreateInput('Marca', 5, 40, 290, 20)
    $input_Quantita = GUICtrlCreateInput('Quantita', 5, 70, 290, 20)
    $input_Scaffale = GUICtrlCreateInput('Scaffale', 5, 100, 290, 20)
    $edit_Descrizione = GUICtrlCreateInput('Descrizone', 5, 130, 290, 20)
    $input_Costo = GUICtrlCreateInput('Costo', 5, 160, 290, 20)
    $edit_Note = GUICtrlCreateInput('Note', 5, 190, 290, 20)
    $edit_Info = GUICtrlCreateInput('Info', 5, 220, 290, 20)
    Local $idOK = GUICtrlCreateButton('Insert', 190, 250, 100, 25)

    ; Display the GUI.
    GUISetState(@SW_SHOW, $hGUI)

    ; Loop until the user exits.
    While 1
        Switch GUIGetMsg()
            Case $GUI_EVENT_CLOSE
                ExitLoop
            Case $idOK
;~ Uncomment these lines if you want to check all of the inputs before submitting anything
;~              If GUICtrlRead($input_Codice) = '' Then
;~                  GUICtrlSetState($input_Codice, $GUI_FOCUS)
;~                  ContinueLoop
;~              EndIf
;~              If GUICtrlRead($input_Marca) = '' Then
;~                  GUICtrlSetState($input_Marca, $GUI_FOCUS)
;~                  ContinueLoop
;~              EndIf
;~              If GUICtrlRead($input_Codice) = '' Then
;~                  GUICtrlSetState($input_Codice, $GUI_FOCUS)
;~                  ContinueLoop
;~              EndIf
;~              If GUICtrlRead($input_Quantita) = '' Then
;~                  GUICtrlSetState($input_Quantita, $GUI_FOCUS)
;~                  ContinueLoop
;~              EndIf
;~              If GUICtrlRead($input_Scaffale) = '' Then
;~                  GUICtrlSetState($input_Scaffale, $GUI_FOCUS)
;~                  ContinueLoop
;~              EndIf
;~              If GUICtrlRead($edit_Descrizione) = '' Then
;~                  GUICtrlSetState($edit_Descrizione, $GUI_FOCUS)
;~                  ContinueLoop
;~              EndIf
;~              If GUICtrlRead($input_Costo) = '' Then
;~                  GUICtrlSetState($input_Costo, $GUI_FOCUS)
;~                  ContinueLoop
;~              EndIf
;~              If GUICtrlRead($edit_Note) = '' Then
;~                  GUICtrlSetState($edit_Note, $GUI_FOCUS)
;~                  ContinueLoop
;~              EndIf
;~              If GUICtrlRead($edit_Info) = '' Then
;~                  GUICtrlSetState($edit_Info, $GUI_FOCUS)
;~                  ContinueLoop
;~              EndIf
                ControllaInserimento($input_Codice, $oWorkbook, "A", $iIndiceRigaVuota)
                ControllaInserimento($input_Marca, $oWorkbook, "B", $iIndiceRigaVuota)
                ControllaInserimento($input_Quantita, $oWorkbook, "C", $iIndiceRigaVuota)
                ControllaInserimento($input_Scaffale, $oWorkbook, "D", $iIndiceRigaVuota)
                ControllaInserimento($edit_Descrizione, $oWorkbook, "E", $iIndiceRigaVuota)
                ControllaInserimento($input_Costo, $oWorkbook, "F", $iIndiceRigaVuota)
                ControllaInserimento($edit_Note, $oWorkbook, "G", $iIndiceRigaVuota)
                ControllaInserimento($edit_Info, $oWorkbook, "H", $iIndiceRigaVuota)
        EndSwitch
    WEnd

    ; Delete the previous GUI and all controls.
    GUIDelete($hGUI)
EndFunc   ;==>Example

;~ Parameter 1 = Name of the edit Control you wish to read
;~ Parameter 2 = Workbook name, if you only use 1 workbook you can remove this and just use $oWorkbook
;~ Parameter 3 = Excel Column String
;~ Parameter 4 = Excel Column Index
Func ControllaInserimento($hedit_Control, $oCartellaDiLavoro, $iIndiceColonnaDoveScrivere, $iIndiceRigaDoveScrivere)
    If GUICtrlRead($hedit_Control) = "" Then
        MsgBox($MB_ICONERROR, "Errore!", "Inserisci un 'Codice Prodotto' per continuare.", 3)
        Return
    EndIf
    _Excel_RangeWrite($oCartellaDiLavoro, $oCartellaDiLavoro.ActiveSheet, GUICtrlRead($hedit_Control), $iIndiceColonnaDoveScrivere & $iIndiceRigaDoveScrivere)
EndFunc

 

Link to comment
Share on other sites

2 minutes ago, Subz said:
#include <Excel.au3>
#include <GUIConstantsEx.au3>

Opt('ExpandVarStrings', 1)

Global $edit_Descrizione, $edit_Info, $edit_Note, $input_Codice, $input_Costo, $input_Marca, $input_Quantita, $input_Scaffale
Global $oExcel = _Excel_Open()
Global $oWorkbook = _Excel_BookNew($oExcel)

Example()

Func Example()
    ; Create a GUI with various controls.
    Local $iIndiceRigaVuota = 1
    Local $hGUI = GUICreate('Example', 300, 285)
    $input_Codice = GUICtrlCreateInput('Codice', 5, 10, 290, 20)
    $input_Marca = GUICtrlCreateInput('Marca', 5, 40, 290, 20)
    $input_Quantita = GUICtrlCreateInput('Quantita', 5, 70, 290, 20)
    $input_Scaffale = GUICtrlCreateInput('Scaffale', 5, 100, 290, 20)
    $edit_Descrizione = GUICtrlCreateInput('Descrizone', 5, 130, 290, 20)
    $input_Costo = GUICtrlCreateInput('Costo', 5, 160, 290, 20)
    $edit_Note = GUICtrlCreateInput('Note', 5, 190, 290, 20)
    $edit_Info = GUICtrlCreateInput('Info', 5, 220, 290, 20)
    Local $idOK = GUICtrlCreateButton('Insert', 190, 250, 100, 25)

    ; Display the GUI.
    GUISetState(@SW_SHOW, $hGUI)

    ; Loop until the user exits.
    While 1
        Switch GUIGetMsg()
            Case $GUI_EVENT_CLOSE
                ExitLoop
            Case $idOK
;~ Uncomment these lines if you want to check all of the inputs before submitting anything
;~              If GUICtrlRead($input_Codice) = '' Then
;~                  GUICtrlSetState($input_Codice, $GUI_FOCUS)
;~                  ContinueLoop
;~              EndIf
;~              If GUICtrlRead($input_Marca) = '' Then
;~                  GUICtrlSetState($input_Marca, $GUI_FOCUS)
;~                  ContinueLoop
;~              EndIf
;~              If GUICtrlRead($input_Codice) = '' Then
;~                  GUICtrlSetState($input_Codice, $GUI_FOCUS)
;~                  ContinueLoop
;~              EndIf
;~              If GUICtrlRead($input_Quantita) = '' Then
;~                  GUICtrlSetState($input_Quantita, $GUI_FOCUS)
;~                  ContinueLoop
;~              EndIf
;~              If GUICtrlRead($input_Scaffale) = '' Then
;~                  GUICtrlSetState($input_Scaffale, $GUI_FOCUS)
;~                  ContinueLoop
;~              EndIf
;~              If GUICtrlRead($edit_Descrizione) = '' Then
;~                  GUICtrlSetState($edit_Descrizione, $GUI_FOCUS)
;~                  ContinueLoop
;~              EndIf
;~              If GUICtrlRead($input_Costo) = '' Then
;~                  GUICtrlSetState($input_Costo, $GUI_FOCUS)
;~                  ContinueLoop
;~              EndIf
;~              If GUICtrlRead($edit_Note) = '' Then
;~                  GUICtrlSetState($edit_Note, $GUI_FOCUS)
;~                  ContinueLoop
;~              EndIf
;~              If GUICtrlRead($edit_Info) = '' Then
;~                  GUICtrlSetState($edit_Info, $GUI_FOCUS)
;~                  ContinueLoop
;~              EndIf
                ControllaInserimento($input_Codice, $oWorkbook, "A", $iIndiceRigaVuota)
                ControllaInserimento($input_Marca, $oWorkbook, "B", $iIndiceRigaVuota)
                ControllaInserimento($input_Quantita, $oWorkbook, "C", $iIndiceRigaVuota)
                ControllaInserimento($input_Scaffale, $oWorkbook, "D", $iIndiceRigaVuota)
                ControllaInserimento($edit_Descrizione, $oWorkbook, "E", $iIndiceRigaVuota)
                ControllaInserimento($input_Costo, $oWorkbook, "F", $iIndiceRigaVuota)
                ControllaInserimento($edit_Note, $oWorkbook, "G", $iIndiceRigaVuota)
                ControllaInserimento($edit_Info, $oWorkbook, "H", $iIndiceRigaVuota)
        EndSwitch
    WEnd

    ; Delete the previous GUI and all controls.
    GUIDelete($hGUI)
EndFunc   ;==>Example

;~ Parameter 1 = Name of the edit Control you wish to read
;~ Parameter 2 = Workbook name, if you only use 1 workbook you can remove this and just use $oWorkbook
;~ Parameter 3 = Excel Column String
;~ Parameter 4 = Excel Column Index
Func ControllaInserimento($hedit_Control, $oCartellaDiLavoro, $iIndiceColonnaDoveScrivere, $iIndiceRigaDoveScrivere)
    If GUICtrlRead($hedit_Control) = "" Then
        MsgBox($MB_ICONERROR, "Errore!", "Inserisci un 'Codice Prodotto' per continuare.", 3)
        Return
    EndIf
    _Excel_RangeWrite($oCartellaDiLavoro, $oCartellaDiLavoro.ActiveSheet, GUICtrlRead($hedit_Control), $iIndiceColonnaDoveScrivere & $iIndiceRigaDoveScrivere)
EndFunc

 

It doesn't f*cking work dude... :/
Maybe, my expected result wasn't so clear as it is...
If the user doesn't insert a field, the script SHOULD NOT continue...
Try to delete the first field, ok?
Now click on Insert, ok?
What happen? Other fields are written, and I don't want it!
Is it clearer now?

Click here to see my signature:

Spoiler

ALWAYS GOOD TO READ:

 

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