Gestire gli errori nel VBA Compiler
Durante l’esecuzione del codice VBA compilato possono verificarsi errori di runtime. Mentre il VBA standard utilizza l’istruzione On Error per la gestione degli errori, il VBA Compiler di XLS Padlock utilizza un blocco Try...Except.
Quando si verifica un errore all’interno del blocco Try (o in qualsiasi procedura da esso richiamata), il compilatore passa immediatamente al blocco Except per gestirlo.
Sintassi
Section titled “Sintassi”Try ' ... Code to execute ...Except ' ... Code to run if an exception occurs ...EndEsempio di codice
Section titled “Esempio di codice”NumberStr = ""if InputQuery("Input", "Type an integer from 1 to 7", NumberStr) then try Number = StrToFloat(NumberStr) except raise("Not a valid number") end
select case Number case 1 ShowMessage("One") case 1 + 1 ShowMessage("Two") case 4.5 / 1.5 ShowMessage("Three") case 2 * 2 ShowMessage("Four") case Length("xxxxx") ShowMessage("Five") case 3 + 3, 3 + 4 ShowMessage("Six or Seven") case else ShowMessage("You did not type an integer from 1 to 7") end selectend if