summaryrefslogtreecommitdiffstats
path: root/source/text/sbasic/shared/03020201.xhp
blob: eb46b84dd86d0c39275b1de0019fea8a4a7faab1 (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"?>
<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="textsbasicshared03020201xml" indexer="include" status="PUBLISH">
    <title id="tit" xml-lang="en-US">Get Statement</title>
    <filename>/text/sbasic/shared/03020201.xhp</filename>
  </topic>
</meta>

<body>


<section id="get">
<bookmark xml-lang="en-US" branch="index" id="bm_id3154927">
  <bookmark_value>Get statement</bookmark_value>
</bookmark>


<paragraph id="hd_id3154927" role="heading" level="1" xml-lang="en-US"><link href="text/sbasic/shared/03020201.xhp">Get Statement</link></paragraph>
<paragraph id="par_id3145069" role="paragraph" xml-lang="en-US">Reads a record from a relative file, or a sequence of bytes from a binary file, into a variable.</paragraph>
</section>
<paragraph id="par_id3154346" role="paragraph" xml-lang="en-US">See also: <link href="text/sbasic/shared/03020204.xhp" name="PUT"><item type="literal">PUT</item></link> Statement</paragraph>

<paragraph id="hd_id3150358" role="heading" level="2" xml-lang="en-US">Syntax:</paragraph>
<bascode>
<paragraph id="par_id3150792" role="bascode" xml-lang="en-US">Get [#] FileNumber As Integer, [Position], Variable</paragraph>
</bascode>

<paragraph id="hd_id3154138" role="heading" level="2" xml-lang="en-US">Parameters:</paragraph>
<paragraph id="par_id3150448" role="paragraph" xml-lang="en-US"> <emph>FileNumber:</emph> Any integer expression that determines the file number.</paragraph>
<paragraph id="par_id3154684" role="paragraph" xml-lang="en-US"> <emph>Position:</emph> For files opened in Random mode, <emph>Position</emph> is the number of the record that you want to read.</paragraph>
<paragraph id="par_id3153768" role="paragraph" xml-lang="en-US">For files opened in Binary mode, <emph>Position</emph> is the byte position in the file where the reading starts.</paragraph>
<paragraph id="par_id3147319" role="paragraph" xml-lang="en-US">If <emph>Position</emph> is omitted, the current position or the current data record of the file is used.</paragraph>
<paragraph id="par_id3149484" role="paragraph" xml-lang="en-US">Variable: Name of the variable to be read. With the exception of object variables, you can use any variable type.</paragraph>

<paragraph id="hd_id3153144" role="heading" level="2" xml-lang="en-US">Example:</paragraph>
<bascode>
<paragraph id="par_idm1340774864" role="bascode" localize="false" xml-lang="en-US">Sub ExampleRandomAccess</paragraph>
<paragraph id="par_idm1340773632" role="bascode" localize="false" xml-lang="en-US">Dim iNumber As Integer</paragraph>
<paragraph id="par_id3155307" role="bascode" xml-lang="en-US">Dim sText As Variant ' Must be a variant</paragraph>
<paragraph id="par_idm1340770608" role="bascode" localize="false" xml-lang="en-US">Dim aFile As String</paragraph>
<paragraph id="par_idm1340769376" role="bascode" localize="false" xml-lang="en-US">    aFile = "c:\data.txt"</paragraph>
<paragraph id="par_idm1340768128" role="bascode" localize="false" xml-lang="en-US">    iNumber = Freefile</paragraph>
<paragraph id="par_idm1340766896" role="bascode" localize="false" xml-lang="en-US">    Open aFile For Random As #iNumber Len=32</paragraph>
<paragraph id="par_id3149411" role="bascode" xml-lang="en-US">    Seek #iNumber,1 ' Position at beginning</paragraph>
<paragraph id="par_id3153158" role="bascode" xml-lang="en-US">    Put #iNumber,, "This is the first line of text" ' Fill line with text</paragraph>
<paragraph id="par_id3148457" role="bascode" xml-lang="en-US">    Put #iNumber,, "This is the second line of text"</paragraph>
<paragraph id="par_id3150715" role="bascode" xml-lang="en-US">    Put #iNumber,, "This is the third line of text"</paragraph>
<paragraph id="par_idm1340758576" role="bascode" localize="false" xml-lang="en-US">    Seek #iNumber,2</paragraph>
<paragraph id="par_idm1340757344" role="bascode" localize="false" xml-lang="en-US">    Get #iNumber,,sText</paragraph>
<paragraph id="par_idm1340756112" role="bascode" localize="false" xml-lang="en-US">    Print sText</paragraph>
<paragraph id="par_idm1340754880" role="bascode" localize="false" xml-lang="en-US">    Close #iNumber</paragraph>
<paragraph id="par_idm1340753648" role="bascode" localize="false" xml-lang="en-US">    iNumber = Freefile</paragraph>
<paragraph id="par_idm1340752416" role="bascode" localize="false" xml-lang="en-US">    Open aFile For Random As #iNumber Len=32</paragraph>
<paragraph id="par_idm1340751152" role="bascode" localize="false" xml-lang="en-US">    Get #iNumber,2,sText</paragraph>
<paragraph id="par_id3155938" role="bascode" xml-lang="en-US">    Put #iNumber,,"This is a new text"</paragraph>
<paragraph id="par_idm1340748176" role="bascode" localize="false" xml-lang="en-US">    Get #iNumber,1,sText</paragraph>
<paragraph id="par_idm1340746928" role="bascode" localize="false" xml-lang="en-US">    Get #iNumber,2,sText</paragraph>
<paragraph id="par_id3146916" role="bascode" xml-lang="en-US">    Put #iNumber,20,"This is the text in record 20"</paragraph>
<paragraph id="par_idm1340743936" role="bascode" localize="false" xml-lang="en-US">    Print Lof(#iNumber)</paragraph>
<paragraph id="par_idm1340742704" role="bascode" localize="false" xml-lang="en-US">    Close #iNumber</paragraph>
<paragraph id="par_idm1340741472" role="bascode" localize="false" xml-lang="en-US">End Sub</paragraph>
</bascode>
</body>

</helpdocument>