summaryrefslogtreecommitdiffstats
path: root/helpcontent2/source/text/sbasic/shared/03090303.xhp
blob: cad7a574fb523a3a290d1a8e9c92e370fcd559c2 (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
<?xml version="1.0" encoding="UTF-8"?>
<!--
 * 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 .
-->
<helpdocument version="1.0">

<meta>
  <topic id="textsbasicshared03090303xml" indexer="include" status="PUBLISH">
    <title id="tit" xml-lang="en-US">On...GoSub Statement; On...GoTo Statement</title>
    <filename>/text/sbasic/shared/03090303.xhp</filename>
  </topic>
</meta>

<body>

<section id="ongosub">
<bookmark xml-lang="en-US" branch="index" id="bm_id3153897">
  <bookmark_value>On...GoSub statement</bookmark_value>
  <bookmark_value>On...GoTo statement</bookmark_value>
  <bookmark_value>label; in On...GoSub statement</bookmark_value>
  <bookmark_value>label; in On...GoTo statement</bookmark_value>
</bookmark>


<h1 id="hd_id3153897" xml-lang="en-US"><variable id="OnGoSubGoToh1"><link href="text/sbasic/shared/03090303.xhp" name="On...GoSub Statement; On...GoTo Statement">On...GoSub Statement; On...GoTo Statement</link></variable></h1>
<paragraph id="par_id3150359" role="paragraph" xml-lang="en-US">Branches to one of several specified lines in the program code, depending on the value of a numeric expression.</paragraph>
</section>

<embed href="text/sbasic/shared/00000003.xhp#functsyntax"/>
<paragraph role="image" id="par_id841588605629842"><image src="media/helpimg/sbasic/On-GoSub-GoTo_statement.svg" id="img_id931588605629842"><alt id="alt_id931588605629842">On GoSub/GoTo syntax</alt></image></paragraph>
<bascode>
<paragraph id="par_id3154366" role="bascode" xml-lang="en-US">On expression GoSub Label1[, Label2[, Label3[,...]]]</paragraph>
<paragraph id="par_id3150769" role="bascode" xml-lang="en-US">On expression GoTo Label1[, Label2[, Label3[,...]]]</paragraph>
</bascode>

<embed href="text/sbasic/shared/00000003.xhp#functparameters"/>
<paragraph id="par_id3148673" role="paragraph" xml-lang="en-US"> <emph>expression:</emph> Any numeric expression between 0 and 255 that determines which of the lines the program branches to. If <emph>expression</emph> is 0, the statement is not executed. If <emph>expression</emph> is greater  than 0, the program jumps to the label that has a position number that corresponds to the expression (1 = First label; 2 = Second label)</paragraph>
<paragraph id="par_id3153194" role="paragraph" xml-lang="en-US"> <emph>label:</emph> Target line according to<emph> GoTo </emph>or <emph>GoSub</emph> structure.</paragraph>
<paragraph id="par_id3156442" role="note" xml-lang="en-US">The <emph>GoTo</emph> or <emph>GoSub </emph>conventions are valid.</paragraph>

<embed href="text/sbasic/shared/00000003.xhp#functexample"/>
<bascode>
<paragraph id="par_idm1341610144" role="bascode" localize="false" xml-lang="en-US">Sub ExampleOnGosub</paragraph>
<paragraph id="par_idm1341608912" role="bascode" localize="false" xml-lang="en-US">Dim iVar As Integer</paragraph>
<paragraph id="par_idm1341607680" role="bascode" localize="false" xml-lang="en-US">Dim sVar As String</paragraph>
<paragraph id="par_idm1341606448" role="bascode" localize="false" xml-lang="en-US">    iVar = 2</paragraph>
<paragraph id="par_idm1341605216" role="bascode" localize="false" xml-lang="en-US">    sVar =""</paragraph>
<paragraph id="par_idm1341603984" role="bascode" localize="false" xml-lang="en-US">    On iVar GoSub Sub1, Sub2</paragraph>
<paragraph id="par_idm1341602736" role="bascode" localize="false" xml-lang="en-US">    On iVar GoTo Line1, Line2</paragraph>
<paragraph id="par_idm1341601488" role="bascode" localize="false" xml-lang="en-US">    Exit Sub</paragraph>
<paragraph id="par_idm1341600256" role="bascode" localize="false" xml-lang="en-US">Sub1:</paragraph>
<paragraph id="par_id3153948" role="bascode" xml-lang="en-US">    sVar =sVar &amp; " From Sub 1 to" : Return</paragraph>
<paragraph id="par_idm1341597216" role="bascode" localize="false" xml-lang="en-US">Sub2:</paragraph>
<paragraph id="par_id3153708" role="bascode" xml-lang="en-US">    sVar =sVar &amp; " From Sub 2 to" : Return</paragraph>
<paragraph id="par_idm1341594128" role="bascode" localize="false" xml-lang="en-US">Line1:</paragraph>
<paragraph id="par_id3150321" role="bascode" xml-lang="en-US">    sVar =sVar &amp; " Label 1" : GoTo Ende</paragraph>
<paragraph id="par_idm1341591088" role="bascode" localize="false" xml-lang="en-US">Line2:</paragraph>
<paragraph id="par_id3155764" role="bascode" xml-lang="en-US">    sVar =sVar &amp; " Label 2"</paragraph>
<paragraph id="par_idm1341588128" role="bascode" localize="false" xml-lang="en-US">Ende:</paragraph>
<paragraph id="par_idm1341586896" role="bascode" localize="false" xml-lang="en-US">    MsgBox sVar,0,"On...GoSub"</paragraph>
<paragraph id="par_idm1341585648" role="bascode" localize="false" xml-lang="en-US">End Sub</paragraph>
</bascode>
  
<section id="relatedtopics">
  <embed href="text/sbasic/shared/03090301.xhp#GoSubh1"/>
  <embed href="text/sbasic/shared/03090302.xhp#GoToh1"/>
</section>
  
</body>
</helpdocument>