LibreOffice 7.1 laguntza
Erabili VBAren Err objektua exekuzio-garaiko erroreak sortzeko edo maneiatzeko.
Err VBAn integratutako objektu globala da, honakoak egitea ahalbidetzen duena:
aurredefinitutako Basic erroreak sortzea
erabiltzaileak definitutako salbuespenak sortzea
errorearen jatorria den errutinari izena ematea
errorea eta balizko konponbideak deskribatzea
VBAren Err objektuak honako propietateak eta metodoak ditu:
Err.Description As String
The Description propietateak errorearen izaera erakusten du. Description propietateak errorearen zergatia izan daitezkeen arrazoien xehetasunak ematen ditu. Posible bada, auzia konpontzeko eta berriro gertatu ez dadin egin behar diren balizko urratsak ematen ditu. Basic aliasa aurredefinituta LibreOffice erroreetarako Error funtzioa da.
Err.Number As Long
Erroreari lotutako errore-kodea. Err objektuaren propietate lehenetsia Number da. LibreOffice Basic aliasa Err funtzioa da.
Err.Source As String
Source propietateak errora sortu duen errutinaren izena adierazten du. Source erabiltzaileak definitutako erroreetarako aukera bat da.
Err.Clear()
Resets description, Erl, number and source properties of current error. The LibreOffice Basic alias is the Resume statement.
Err.Raise(Number As Long, Optional source As String, Optional description As String)
Throws user-defined errors or predefined errors. The LibreOffice Basic alias is the Error statement.
Number: Sortuko den errorearen kodea, erabiltzaileak definitutakoa edo aurredefinitutakoa.
0 eta 2000 zenbakien arteko errore-kodeak LibreOffice Basic berarentzat erreserbatuta daude. Erabiltzaileak definitutako erroreek balio handiagoa eduki behar dute LibreOffice Basic lengoaiaren etorkizuneko garapenekin gatazkarik ez izateko.
Source: Errorea sortu duen errutinaren izena. Gomendagarria da "myLibrary.myModule.myProc" formako izena erabiltzea.
Description: A description of the problem leading to stop the running process, accompanied with the various reasons that may cause it. A detailed list of the possible course of actions that may help solve the problem is recommended.
Option VBASupport 1
Sub ThrowErrors
Dim aDesc As String : aDesc = Space(80)
On Local Error GoTo AlertAndExecNext
Err.Raise(91, "ThrowErrors", Error(91))
Err.Raise 2020, Description:="This is an intended user-defined error …"
Err.Raise(4096, "Standard.Module1.ThrowErrors", aDesc)
Exit Sub
AlertAndExecNext:
errTitle = "Error "& Err &" at line "& Erl &" in "& Err.Source
MsgBox Err.Description, MB_ICONEXCLAMATION, errTitle
Resume Next
End Sub
A short ClassModule, that wraps VBA Err object, can distribute Err properties and methods for standard LibreOffice Basic modules.
Option ClassModule
Option VBASupport 1
Public Property Get Description As String
Description = Err.Description
End Property
Public Property Get Number As Long
Number = Err.Number
End Property
Public Property Get Source As String
Source = Err.Source
End Property
Public Sub Clear
Err.Clear
End Sub
Public Sub Raise( number As Long, Optional Source As String, Optional Description As String)
Err.Raise number, Source, Description
End Sub
Function Exc As Object
Exc = New Exception
End Function
Sub aRoutine
try:
On Local Error GoTo catch:
Exc.Raise(4096, "myLib.myModule.aRoutine", _
"Any multi-line description for this user-defined exception")
' zure kodea hemen doa …
finally:
Exit Sub
catch:
errTitle = "Error "& Exc.Number &" at line "& Erl &" in "& Exc.Source
MsgBox Exc.Description, MB_ICONSTOP, errTitle
Resume finally
End Sub
The Error statement or an Exception-like class module can be used interchangeably, while the latter adds extra features.