summaryrefslogtreecommitdiffstats
path: root/source/text/sbasic/shared/03050500.xhp
blob: 3d1e71c390a9d10c14129a0bad0615d15128557c (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
<?xml version="1.0" encoding="UTF-8"?>
<helpdocument version="1.0">
<!--
 * This file is part of the LibreOffice project.
 *
 * This Source Code Form is subject to the terms of the Mozilla Public
 * License, v. 2.0. If a copy of the MPL was not distributed with this
 * file, You can obtain one at http://mozilla.org/MPL/2.0/.
 *
 * This file incorporates work covered by the following license notice:
 *
 *   Licensed to the Apache Software Foundation (ASF) under one or more
 *   contributor license agreements. See the NOTICE file distributed
 *   with this work for additional information regarding copyright
 *   ownership. The ASF licenses this file to you under the Apache
 *   License, Version 2.0 (the "License"); you may not use this file
 *   except in compliance with the License. You may obtain a copy of
 *   the License at http://www.apache.org/licenses/LICENSE-2.0 .
-->

<meta>
  <topic id="textsbasicshared03050500xml" indexer="include" status="PUBLISH">
    <title id="tit" xml-lang="en-US">On Error GoTo ... Resume Statement</title>
    <filename>/text/sbasic/shared/03050500.xhp</filename>
  </topic>
</meta>

<body>
<section id="onerrorgotoresume">
<bookmark xml-lang="en-US" branch="index" id="bm_id3146795">
  <bookmark_value>Resume Next parameter</bookmark_value>
  <bookmark_value>On Error GoTo ... Resume statement</bookmark_value>
</bookmark>
<paragraph id="hd_id3146795" role="heading" level="1" xml-lang="en-US"><link href="text/sbasic/shared/03050500.xhp" name="On Error GoTo ... Resume Statement">On Error GoTo ... Resume Statement</link></paragraph>
<paragraph id="par_id3150358" role="paragraph" xml-lang="en-US">Enables an error-handling routine after an error occurs, or resumes program execution.</paragraph>
</section>

<embed href="text/sbasic/shared/00000003.xhp#functsyntax"/>
<paragraph role="paragraph" id="par_id491585753339474">
  <image src="media/helpimg/sbasic/On-Error_statement.svg" id="img_id4156296484514"><alt xml-lang="en-US" id="alt_id15152796484514">On Error Statement diagram</alt></image>
</paragraph>
<bascode>
<paragraph id="par_id3145173" role="bascode" xml-lang="en-US">On [Local] Error {GoTo Labelname | GoTo 0 | Resume Next}</paragraph>
</bascode>

<embed href="text/sbasic/shared/00000003.xhp#functparameters"/>
<paragraph id="par_id3150869" role="paragraph" xml-lang="en-US"><emph>GoTo Labelname:</emph> If an error occurs, enables the error-handling routine that starts at the line "Labelname".</paragraph>
<paragraph id="par_id3150439" role="paragraph" xml-lang="en-US"><emph>Resume Next:</emph> If an error occurs, program execution continues with the statement that follows the statement in which the error occurred.</paragraph>
<paragraph id="par_id3149482" role="paragraph" xml-lang="en-US"><emph>GoTo 0:</emph> Disables the error handler in the current procedure.</paragraph>
<paragraph id="par_id3149483" role="paragraph" xml-lang="en-US"><emph>Local:</emph> "On error" is global in scope, and remains active until canceled by another "On error" statement. "On Local error" is local to the routine which invokes it. Local error handling overrides any previous global setting. When the invoking routine exits, the local error handling is canceled automatically, and any previous global setting is restored.</paragraph>
<paragraph id="par_id3148619" role="paragraph" xml-lang="en-US">The On Error GoTo statement is used to react to errors that occur in a macro.<comment>see i112231: The statement must be inserted at the start of a procedure (in a local error-handling routine) or at the start of a module.</comment></paragraph>

<embed href="text/sbasic/shared/00000003.xhp#functexample"/>
<bascode>
<paragraph id="par_idm1341127952" role="bascode" localize="false" xml-lang="en-US">Sub ExampleReset</paragraph>
<paragraph id="par_idm1341126720" role="bascode" localize="false" xml-lang="en-US">On Error GoTo ErrorHandler</paragraph>
<paragraph id="par_idm1341125472" role="bascode" localize="false" xml-lang="en-US">    Dim iNumber As Integer</paragraph>
<paragraph id="par_idm1341124240" role="bascode" localize="false" xml-lang="en-US">    Dim iCount As Integer</paragraph>
<paragraph id="par_idm1341123008" role="bascode" localize="false" xml-lang="en-US">    Dim sLine As String</paragraph>
<paragraph id="par_idm1341121776" role="bascode" localize="false" xml-lang="en-US">    Dim aFile As String</paragraph>
<paragraph id="par_idm1341120544" role="bascode" localize="false" xml-lang="en-US">    aFile = "C:\Users\ThisUser\data.txt"</paragraph>
<paragraph id="par_idm1341119296" role="bascode" localize="false" xml-lang="en-US">    iNumber = Freefile</paragraph>
<paragraph id="par_idm1341118064" role="bascode" localize="false" xml-lang="en-US">    Open aFile For Output As #iNumber</paragraph>
<paragraph id="par_id3153876" role="bascode" xml-lang="en-US">    Print #iNumber, "This is a line of text"</paragraph>
<paragraph id="par_idm1341115072" role="bascode" localize="false" xml-lang="en-US">    Close #iNumber</paragraph>
<paragraph id="par_idm1341113840" role="bascode" localize="false" xml-lang="en-US">    iNumber = Freefile</paragraph>
<paragraph id="par_idm1341112608" role="bascode" localize="false" xml-lang="en-US">    Open aFile For Input As iNumber</paragraph>
<paragraph id="par_idm1341111360" role="bascode" localize="false" xml-lang="en-US">    For iCount = 1 To 5</paragraph>
<paragraph id="par_idm1341110128" role="bascode" localize="false" xml-lang="en-US">        Line Input #iNumber, sLine</paragraph>
<paragraph id="par_idm1341108880" role="bascode" localize="false" xml-lang="en-US">        If sLine &lt;&gt;"" Then</paragraph>
<paragraph id="par_idm1341107632" role="bascode" localize="false" xml-lang="en-US">            Rem</paragraph>
<paragraph id="par_idm1341106400" role="bascode" localize="false" xml-lang="en-US">        End If</paragraph>
<paragraph id="par_idm1341105168" role="bascode" localize="false" xml-lang="en-US">    Next iCount</paragraph>
<paragraph id="par_idm1341103936" role="bascode" localize="false" xml-lang="en-US">    Close #iNumber</paragraph>
<paragraph id="par_idm1341102704" role="bascode" localize="false" xml-lang="en-US">    Exit Sub</paragraph>
<paragraph id="par_idm1341101472" role="bascode" localize="false" xml-lang="en-US">ErrorHandler:</paragraph>
<paragraph id="par_idm1341100240" role="bascode" localize="false" xml-lang="en-US">    Reset</paragraph>
<paragraph id="par_id3146916" role="bascode" xml-lang="en-US">    MsgBox "All files will be closed",  0,  "Error"</paragraph>
<paragraph id="par_idm1341097264" role="bascode" localize="false" xml-lang="en-US">End Sub</paragraph>
</bascode>
<section id="relatedtopics">
  <embed href="text/sbasic/shared/03050000.xhp#ErrHandlingh1"/>
  <embed href="text/sbasic/shared/03020103.xhp#Open_h1"/>
</section>  
</body>
</helpdocument>