03090301.xhp (226a8927) 03090301.xhp (90189a2d)
1<?xml version="1.0" encoding="UTF-8"?>
2
3
4<!--***********************************************************
5 *
6 * Licensed to the Apache Software Foundation (ASF) under one
7 * or more contributor license agreements. See the NOTICE file
8 * distributed with this work for additional information

--- 49 unchanged lines hidden (view full) ---

58<paragraph role="paragraph" id="par_id3147318" xml-lang="en-US" l10n="U" oldref="16">The <emph>GoSub</emph> statement calls a local subroutine indicated by a label from within a subroutine or a function. The name of the label must end with a colon (":").</paragraph>
59<paragraph role="warning" id="par_id3153190" xml-lang="en-US" l10n="U" oldref="17">If the program encounters a Return statement not preceded by <emph>GoSub</emph>, $[officename] Basic returns an error message. Use <emph>Exit Sub</emph> or <emph>Exit Function</emph> to ensure that the program leaves a Sub or Function before reaching the next Return statement.</paragraph>
60<paragraph role="paragraph" id="par_id3145799" xml-lang="en-US" l10n="U" oldref="19">The following example demonstrates the use of <emph>GoSub</emph> and <emph>Return</emph>. By executing a program section twice, the program calculates the square root of two numbers that are entered by the user.</paragraph>
61<paragraph role="heading" id="hd_id3156284" xml-lang="en-US" level="2" l10n="U" oldref="20">Example:</paragraph>
62<paragraph role="paragraph" id="par_id3151073" xml-lang="en-US" l10n="U" oldref="21">Sub ExampleGoSub</paragraph>
63<paragraph role="paragraph" id="par_id3154097" xml-lang="en-US" l10n="U" oldref="22">dim iInputa as Single</paragraph>
64<paragraph role="paragraph" id="par_id3150715" xml-lang="en-US" l10n="U" oldref="23">dim iInputb as Single</paragraph>
65<paragraph role="paragraph" id="par_id3153416" xml-lang="en-US" l10n="U" oldref="24">dim iInputc as Single</paragraph>
1<?xml version="1.0" encoding="UTF-8"?>
2
3
4<!--***********************************************************
5 *
6 * Licensed to the Apache Software Foundation (ASF) under one
7 * or more contributor license agreements. See the NOTICE file
8 * distributed with this work for additional information

--- 49 unchanged lines hidden (view full) ---

58<paragraph role="paragraph" id="par_id3147318" xml-lang="en-US" l10n="U" oldref="16">The <emph>GoSub</emph> statement calls a local subroutine indicated by a label from within a subroutine or a function. The name of the label must end with a colon (":").</paragraph>
59<paragraph role="warning" id="par_id3153190" xml-lang="en-US" l10n="U" oldref="17">If the program encounters a Return statement not preceded by <emph>GoSub</emph>, $[officename] Basic returns an error message. Use <emph>Exit Sub</emph> or <emph>Exit Function</emph> to ensure that the program leaves a Sub or Function before reaching the next Return statement.</paragraph>
60<paragraph role="paragraph" id="par_id3145799" xml-lang="en-US" l10n="U" oldref="19">The following example demonstrates the use of <emph>GoSub</emph> and <emph>Return</emph>. By executing a program section twice, the program calculates the square root of two numbers that are entered by the user.</paragraph>
61<paragraph role="heading" id="hd_id3156284" xml-lang="en-US" level="2" l10n="U" oldref="20">Example:</paragraph>
62<paragraph role="paragraph" id="par_id3151073" xml-lang="en-US" l10n="U" oldref="21">Sub ExampleGoSub</paragraph>
63<paragraph role="paragraph" id="par_id3154097" xml-lang="en-US" l10n="U" oldref="22">dim iInputa as Single</paragraph>
64<paragraph role="paragraph" id="par_id3150715" xml-lang="en-US" l10n="U" oldref="23">dim iInputb as Single</paragraph>
65<paragraph role="paragraph" id="par_id3153416" xml-lang="en-US" l10n="U" oldref="24">dim iInputc as Single</paragraph>
66<paragraph role="paragraph" id="par_id3146970" xml-lang="en-US" l10n="U" oldref="25">iInputa = Int(InputBox$ "Enter the first number: ","NumberInput"))</paragraph>
67<paragraph role="paragraph" id="par_id3150329" xml-lang="en-US" l10n="U" oldref="26">iInputb = Int(InputBox$ "Enter the second number: ","NumberInput"))</paragraph>
66<paragraph role="paragraph" id="par_id3146970" xml-lang="en-US" l10n="U" oldref="25">iInputa = Int(InputBox$ ("Enter the first number: ","NumberInput"))</paragraph>
67<paragraph role="paragraph" id="par_id3150329" xml-lang="en-US" l10n="U" oldref="26">iInputb = Int(InputBox$ ("Enter the second number: ","NumberInput"))</paragraph>
68<paragraph role="paragraph" id="par_id3156277" xml-lang="en-US" l10n="U" oldref="27">iInputc=iInputa</paragraph>
69<paragraph role="paragraph" id="par_id3150321" xml-lang="en-US" l10n="U" oldref="28">GoSub SquareRoot</paragraph>
70<paragraph role="paragraph" id="par_id3154756" xml-lang="en-US" l10n="U" oldref="29">Print "The square root of";iInputa;" is";iInputc</paragraph>
71<paragraph role="paragraph" id="par_id3155764" xml-lang="en-US" l10n="U" oldref="30">iInputc=iInputb</paragraph>
72<paragraph role="paragraph" id="par_id3152960" xml-lang="en-US" l10n="U" oldref="31">GoSub SquareRoot</paragraph>
73<paragraph role="paragraph" id="par_id3147340" xml-lang="en-US" l10n="U" oldref="32">Print "The square root of";iInputb;" is";iInputc</paragraph>
74<paragraph role="paragraph" id="par_id3166450" xml-lang="en-US" l10n="U" oldref="33">Exit Sub</paragraph>
75<paragraph role="paragraph" id="par_id3155176" xml-lang="en-US" l10n="U" oldref="34">SquareRoot:</paragraph>
76<paragraph role="paragraph" id="par_id3149257" xml-lang="en-US" l10n="U" oldref="35">iInputc=sqr(iInputc)</paragraph>
77<paragraph role="paragraph" id="par_id3146316" xml-lang="en-US" l10n="U" oldref="36">Return</paragraph>
78<paragraph role="paragraph" id="par_id3154703" xml-lang="en-US" l10n="U" oldref="37">End Sub</paragraph>
79</body>
80</helpdocument>
68<paragraph role="paragraph" id="par_id3156277" xml-lang="en-US" l10n="U" oldref="27">iInputc=iInputa</paragraph>
69<paragraph role="paragraph" id="par_id3150321" xml-lang="en-US" l10n="U" oldref="28">GoSub SquareRoot</paragraph>
70<paragraph role="paragraph" id="par_id3154756" xml-lang="en-US" l10n="U" oldref="29">Print "The square root of";iInputa;" is";iInputc</paragraph>
71<paragraph role="paragraph" id="par_id3155764" xml-lang="en-US" l10n="U" oldref="30">iInputc=iInputb</paragraph>
72<paragraph role="paragraph" id="par_id3152960" xml-lang="en-US" l10n="U" oldref="31">GoSub SquareRoot</paragraph>
73<paragraph role="paragraph" id="par_id3147340" xml-lang="en-US" l10n="U" oldref="32">Print "The square root of";iInputb;" is";iInputc</paragraph>
74<paragraph role="paragraph" id="par_id3166450" xml-lang="en-US" l10n="U" oldref="33">Exit Sub</paragraph>
75<paragraph role="paragraph" id="par_id3155176" xml-lang="en-US" l10n="U" oldref="34">SquareRoot:</paragraph>
76<paragraph role="paragraph" id="par_id3149257" xml-lang="en-US" l10n="U" oldref="35">iInputc=sqr(iInputc)</paragraph>
77<paragraph role="paragraph" id="par_id3146316" xml-lang="en-US" l10n="U" oldref="36">Return</paragraph>
78<paragraph role="paragraph" id="par_id3154703" xml-lang="en-US" l10n="U" oldref="37">End Sub</paragraph>
79</body>
80</helpdocument>