mirror of
https://github.com/LCTT/TranslateProject.git
synced 2024-12-26 21:30:55 +08:00
[手动选题][tech]: 20221221.1 ⭐️ Debugging LibreOffice Basic Macro using Breakpoint and Watch.md
This commit is contained in:
parent
d16e5e2c3c
commit
2c316b7ee7
@ -0,0 +1,118 @@
|
||||
[#]: subject: "Debugging LibreOffice Basic Macro using Breakpoint and Watch"
|
||||
[#]: via: "https://www.debugpoint.com/debugging-libreoffice-macro-basic-using-breakpoint-and-watch/"
|
||||
[#]: author: "Arindam https://www.debugpoint.com/author/admin1/"
|
||||
[#]: collector: "lkxed"
|
||||
[#]: translator: " "
|
||||
[#]: reviewer: " "
|
||||
[#]: publisher: " "
|
||||
[#]: url: " "
|
||||
|
||||
Debugging LibreOffice Basic Macro using Breakpoint and Watch
|
||||
======
|
||||
|
||||
**A simple guide for you to learn how to debug LibreOffice basic macro using breakpoint and watch.**
|
||||
|
||||
While writing complex macros to automate various tasks in LibreOffice, you definitely encounter errors. Some run-time errors are self-explanatory. But some of them are very generic. To debug those, you need to carefully put breakpoints and step through the code to see where the problem is in your code.
|
||||
|
||||
Hence this tutorial. These techniques apply to all the macros written in Calc, Writer or Impress. And should be applied to OpenOffice macros as well.
|
||||
|
||||
### Debug a LibreOffice Macro written in Basic
|
||||
|
||||
It’s easier to demonstrate this concept using an example.
|
||||
|
||||
#### Define
|
||||
|
||||
Let’s define three variables which we would use for our exercise.
|
||||
|
||||
```
|
||||
dim i, j, cnt
|
||||
```
|
||||
|
||||
Define a `for` loop, which would execute from 1 to 10. Inside the loop, increment two variables as below. This is just for just this demo; however, you can put any logic you want.
|
||||
|
||||
```
|
||||
for cnt = 1 to 10
|
||||
i = i + 1
|
||||
j = i + 1
|
||||
next cnt
|
||||
```
|
||||
|
||||
#### Adding Breakpoint
|
||||
|
||||
Now, we want to put two breakpoints in the statement `"for cnt = 1 to 10"` and `"j = i + 1"`. When you put a breakpoint inside your program, it runs in debug mode and holds the execution at the breakpoint.
|
||||
|
||||
To put a breakpoint in a LibreOffice Basic macro, put the cursor in the statement. And then, press `F9` or press the below button from the toolbar.
|
||||
|
||||
![Breakpoint toolbar button in LibreOffice Macro editor][1]
|
||||
|
||||
Once you do that, you will see a red circle on the left side of the statement, which means a breakpoint has been added _to that statement_. See the below image. In addition, you can add multiple breakpoints as per your needs.
|
||||
|
||||
![After adding breakpoints][2]
|
||||
|
||||
If you want to remove a breakpoint from a statement, press `F9` again in the statement, OR you can `double-click` the red circle.
|
||||
|
||||
#### Adding Watch
|
||||
|
||||
Now, we would add a ‘watch’ to the variable `"cnt"`.
|
||||
|
||||
When the program executes in debug mode, the watch helps monitor a variable’s value between program steps. To add a watch on `"cnt"`variable, select the variable and press `F7` or click the glass icon in the toolbar.
|
||||
|
||||
![Watch button in the toolbar in LibreOffice Macro editor][3]
|
||||
|
||||
Once you do that, you will see the variable added to the watch list at the bottom of the editor.
|
||||
|
||||
![Watch section appears at the bottom of the editor][4]
|
||||
|
||||
#### Execute by Step
|
||||
|
||||
We are all set with tools.
|
||||
|
||||
Run the program by pressing `F5`. As we already added breakpoints, you would see the execution halts at the first breakpoint with a little **yellow arrow**.
|
||||
|
||||
![Execution halts at the breakpoint][5]
|
||||
|
||||
Now you have two options.
|
||||
|
||||
Press `F5` again to continue the execution of the program, and it will halt again at the next breakpoint.Press `F8` (step execution), which would execute step by step, and you can see the ‘watched’ variable `'cnt'` value is changing as below.
|
||||
|
||||
Lets press `F8`. You can see the yellow arrow comes to the next statement, and the compiler waits. Now the fun part, if you take a closer look at the watch window, you can see the `'cnt'`variable’s value is 1.
|
||||
|
||||
![Variable contents during execution][6]
|
||||
|
||||
So this way, you can debug, add breakpoints and add watch any LibreOffice or OpenOffice macro using its editor.
|
||||
|
||||
Furthermore, you can add many watch variables as you want and debug your program for successful execution.
|
||||
|
||||
### Closing Notes
|
||||
|
||||
Although the above example is specific to LibreOffice macros, the same concept applies to programming and debugging in general. I hope this article helps you to understand the basics of debugging, step execution and watch in programming and macros in LibreOffice.
|
||||
|
||||
### Looking for Something Else?
|
||||
|
||||
If you are looking for something else in LibreOffice macro tutorials Or wants to learn more about it, please follow the below link for the complete Macro Tutorials Index:
|
||||
|
||||
[Macro Tutorial Index][7]
|
||||
|
||||
[Next:How to Save and Open Tabs from Last Session in Web Browser][8]
|
||||
|
||||
--------------------------------------------------------------------------------
|
||||
|
||||
via: https://www.debugpoint.com/debugging-libreoffice-macro-basic-using-breakpoint-and-watch/
|
||||
|
||||
作者:[Arindam][a]
|
||||
选题:[lkxed][b]
|
||||
译者:[译者ID](https://github.com/译者ID)
|
||||
校对:[校对者ID](https://github.com/校对者ID)
|
||||
|
||||
本文由 [LCTT](https://github.com/LCTT/TranslateProject) 原创编译,[Linux中国](https://linux.cn/) 荣誉推出
|
||||
|
||||
[a]: https://www.debugpoint.com/author/admin1/
|
||||
[b]: https://github.com/lkxed
|
||||
[1]: https://www.debugpoint.com/wp-content/uploads/2014/09/LibreOffice_Debug_watch_BreakPoint_1.png
|
||||
[2]: https://www.debugpoint.com/wp-content/uploads/2014/09/LibreOffice_Debug_watch_BreakPoint_2.png
|
||||
[3]: https://www.debugpoint.com/wp-content/uploads/2014/09/LibreOffice_Debug_watch_BreakPoint_3.png
|
||||
[4]: https://www.debugpoint.com/wp-content/uploads/2014/09/LibreOffice_Debug_watch_BreakPoint_4.png
|
||||
[5]: https://www.debugpoint.com/wp-content/uploads/2014/09/LibreOffice_Debug_watch_BreakPoint_5.png
|
||||
[6]: https://www.debugpoint.com/wp-content/uploads/2014/09/LibreOffice_Debug_watch_BreakPoint_6.png
|
||||
[7]: http://www.debugpoint.com/libreoffice-basic-macro-tutorial-index/
|
||||
[8]: https://www.debugpoint.com/open-tabs-last-session-browser/
|
Loading…
Reference in New Issue
Block a user