<html>
<head>
<base href="https://bugs.documentfoundation.org/">
</head>
<body><table border="1" cellspacing="0" cellpadding="8">
<tr>
<th>Bug ID</th>
<td><a class="bz_bug_link
bz_status_UNCONFIRMED "
title="UNCONFIRMED - Better example macro"
href="https://bugs.documentfoundation.org/show_bug.cgi?id=143211">143211</a>
</td>
</tr>
<tr>
<th>Summary</th>
<td>Better example macro
</td>
</tr>
<tr>
<th>Product</th>
<td>LibreOffice
</td>
</tr>
<tr>
<th>Version</th>
<td>unspecified
</td>
</tr>
<tr>
<th>Hardware</th>
<td>All
</td>
</tr>
<tr>
<th>OS</th>
<td>All
</td>
</tr>
<tr>
<th>Status</th>
<td>UNCONFIRMED
</td>
</tr>
<tr>
<th>Severity</th>
<td>normal
</td>
</tr>
<tr>
<th>Priority</th>
<td>medium
</td>
</tr>
<tr>
<th>Component</th>
<td>Documentation
</td>
</tr>
<tr>
<th>Assignee</th>
<td>libreoffice-bugs@lists.freedesktop.org
</td>
</tr>
<tr>
<th>Reporter</th>
<td>villeroy@t-online.de
</td>
</tr>
<tr>
<th>CC</th>
<td>olivier.hallot@libreoffice.org
</td>
</tr></table>
<p>
<div>
<pre><a href="https://help.libreoffice.org/7.1/en-US/text/scalc/01/12120300.html?System=WIN&DbPAR=CALC&HID=modules/scalc/ui/erroralerttabpage/ErrorAlertTabPage#bm_id3156024">https://help.libreoffice.org/7.1/en-US/text/scalc/01/12120300.html?System=WIN&DbPAR=CALC&HID=modules/scalc/ui/erroralerttabpage/ErrorAlertTabPage#bm_id3156024</a>
There are 3 levels of validation errors in Calc:
1) Stop (error box, reject entry)
2) Warn (warning box with No as default button)
3) Info (question box with Yes as default button)
In addition you can define a macro to handle failed validations. The documented
StarBasic definition
Function ExampleValidity(CellValue as String, TableCell as String)
has 2 flaws:
1) CellValue should be named CellFormula because the passed string is a formula
expression as entered into the formula bar (property "FormulaLocal").
2) The macro is declared as a function without a return value. In fact, the
entry is rejected when the macro function returns False and accepted in case of
True.
A better example macro looks like this:
Function ExampleValidity(CellFormula as String, TableCell as String)
Dim msg as string
Dim iAnswer as integer
Dim MB_FLAGS as integer
msg = "Invalid value: " & "'" & CellFormula & "'"
msg = msg & " in table: " & "'" & TableCell & "'"
msg = msg & Chr(10) & "Accept anyway?"
MB_FLAGS = MB_YESNO + MB_ICONEXCLAMATION + MB_DEFBUTTON2
iAnswer = MsgBox (msg , MB_FLAGS, "Error message")
ExampleValidity = (iAnswer = IDYES)
End Function</pre>
</div>
</p>
<hr>
<span>You are receiving this mail because:</span>
<ul>
<li>You are the assignee for the bug.</li>
</ul>
</body>
</html>