Ir al contenido

Gestión de errores en el VBA Compiler

Pueden producirse errores en tiempo de ejecución cuando se ejecuta su código VBA compilado. Mientras que el VBA estándar utiliza la instrucción On Error para la gestión de errores, el VBA compiler de XLS Padlock utiliza un bloque Try...Except.

Cuando se produce un error dentro del bloque Try (o en cualquier procedimiento que este llame), el compilador saltará inmediatamente al bloque Except para su gestión.

Try
' ... Code to execute ...
Except
' ... Code to run if an exception occurs ...
End
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 select
end if