summaryrefslogtreecommitdiffstats
path: root/source/text/sbasic/shared/03020205.xhp
blob: f97195397399a0be9071ab17628caaf364b74b0d (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
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
<?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="textsbasicshared03020205xml" indexer="include" status="PUBLISH">
    <title id="tit" xml-lang="en-US">Write Statement</title>
    <filename>/text/sbasic/shared/03020205.xhp</filename>
  </topic>
</meta>

<body>

<section id="write">
<bookmark xml-lang="en-US" branch="index" id="bm_id3147229">
  <bookmark_value>Write statement</bookmark_value>
</bookmark>

<h1 id="hd_id3147229"><variable id="Write_h1"><link href="text/sbasic/shared/03020205.xhp" name="Write# Statement">Write# Statement</link></variable></h1>
<paragraph id="par_id3154685" role="paragraph" xml-lang="en-US">Writes data to a sequential text file with delimiting characters.</paragraph>
</section>

<tip id="par_id461596463969009">Use <link href="text/sbasic/shared/03010103.xhp">Print#</link> statement to print data to a sequential text file. Use <link href="text/sbasic/shared/03020201.xhp">Put#</link> statement to write data  to a binary or a random file.</tip>

<embed href="text/sbasic/shared/00000003.xhp#functsyntax"/>
<paragraph role="paragraph" id="par_id971587473488701">
  <image src="media/helpimg/sbasic/Write_statement.svg" id="img_id4156296484514"><alt xml-lang="en-US" id="alt_id15152796484514">Write Statement diagram</alt></image>
</paragraph>
<bascode>
<paragraph id="par_id3145785" role="bascode" localize="false">Write [#fileNum] {,|;} expression [, …]</paragraph>
</bascode>

<embed href="text/sbasic/shared/00000003.xhp#functparameters"/>
<paragraph id="par_id3153728" role="paragraph"> <emph>fileNum</emph>: Any numeric expression that contains the file number that was set by the Open statement for the respective file.</paragraph>
<paragraph id="par_id3146120" role="paragraph"> <emph>expression</emph> list: Variables or expressions that you want to enter in a file, separated by commas.</paragraph>
<paragraph id="par_id3150010" role="paragraph">If the expression list is omitted, the <emph>Write</emph> statement appends an empty line to the file.</paragraph>
<paragraph id="par_id3163713" role="paragraph">To add an expression list to a new or an existing file, the file must be opened in the <emph>Output</emph> or <emph>Append</emph> mode.</paragraph>
<paragraph id="par_id3147428" role="paragraph">Strings that you write are enclosed by quotation marks and separated by commas. You do not need to enter these delimiters in the expression list.</paragraph>
<paragraph id="par_id1002838" role="paragraph">Each <emph>Write</emph> statement outputs a line end symbol as last entry.</paragraph>
<paragraph id="par_id6618854" role="paragraph">Numbers with decimal delimiters are converted according to the locale settings.</paragraph>

<embed href="text/sbasic/shared/00000003.xhp#functexample"/>
<switch select="sys">
<case select="WIN">
  <bascode>
  <paragraph id="par_idm1340911536" role="bascode" localize="false">Sub ExampleWrite</paragraph>
  <paragraph id="par_idm1340910304" role="bascode" localize="false">    Dim iCount As Integer</paragraph>
  <paragraph id="par_idm1340909072" role="bascode" localize="false">    Dim sValue As String</paragraph>
  <paragraph id="par_idm1340907840" role="bascode" localize="false">    iCount = Freefile</paragraph>
  <paragraph id="par_idm1340906608" role="bascode" localize="false">    Open "C:\Users\ThisUser\data.txt" For Output As iCount</paragraph>
  <paragraph id="par_idm1340905344" role="bascode" localize="false">    sValue = "Hamburg"</paragraph>
  <paragraph id="par_idm1340904112" role="bascode" localize="false">    Write #iCount,sValue,200</paragraph>
  <paragraph id="par_idm1340902864" role="bascode" localize="false">    sValue = "New York"</paragraph>
  <paragraph id="par_idm1340901632" role="bascode" localize="false">    Write #iCount,sValue,300</paragraph>
  <paragraph id="par_idm1340900384" role="bascode" localize="false">    sValue = "Miami"</paragraph>
  <paragraph id="par_idm1340899152" role="bascode" localize="false">    Write #iCount,sValue,450</paragraph>
  <paragraph id="par_idm1340897904" role="bascode" localize="false">    Close #iCount</paragraph>
  <paragraph id="par_idm1340896672" role="bascode" localize="false">End Sub</paragraph>
  </bascode>
</case>
<default>
  <bascode>
  <paragraph id="par_idm1340912556" role="bascode" localize="false">Sub ExampleWrite</paragraph>
  <paragraph id="par_idm1340919854" role="bascode" localize="false">    Dim iCount As Integer</paragraph>
  <paragraph id="par_idm1340912572" role="bascode" localize="false">    Dim sValue As String</paragraph>
  <paragraph id="par_idm1340907125" role="bascode" localize="false">    iCount = Freefile</paragraph>
  <paragraph id="par_idm1340906804" role="bascode" localize="false">    Open "~/data.txt" For Output As iCount</paragraph>
  <paragraph id="par_idm1340905662" role="bascode" localize="false">    sValue = "Hamburg"</paragraph>
  <paragraph id="par_idm1340904147" role="bascode" localize="false">    Write #iCount,sValue,200</paragraph>
  <paragraph id="par_idm1340902258" role="bascode" localize="false">    sValue = "New York"</paragraph>
  <paragraph id="par_idm1340901147" role="bascode" localize="false">    Write #iCount,sValue,300</paragraph>
  <paragraph id="par_idm1340900203" role="bascode" localize="false">    sValue = "Miami"</paragraph>
  <paragraph id="par_idm1340899330" role="bascode" localize="false">    Write #iCount,sValue,450</paragraph>
  <paragraph id="par_idm1340897887" role="bascode" localize="false">    Close #iCount</paragraph>
  <paragraph id="par_idm1340896654" role="bascode" localize="false">End Sub</paragraph>
  </bascode>
</default>
</switch>

<section id="relatedtopics" >
   <embed href="text/sbasic/shared/03020103.xhp#Open_h1"/>
   <embed href="text/sbasic/shared/03010103.xhp#Print_h1"/>
   <embed href="text/sbasic/shared/03020204.xhp#Put_h1"/>
   <embed href="text/sbasic/shared/03020101.xhp#Close_h1"/>
</section>
</body>
</helpdocument>