From ef7a4ac4e88c6142ed29acc15a6d28ec85e8b9ce Mon Sep 17 00:00:00 2001 From: Rafael Lima Date: Tue, 30 Mar 2021 14:20:52 +0200 Subject: tdf#106944 Fix Basic examples using the Open statement This patch also fixes some legacy issues: - Use of tags instead of text "Example", "Sintax", etc... - Create tags for functions - Add relevant Related Topics section Change-Id: I85c5508c9940a1b72c82c99c39387b95a3c6edea Reviewed-on: https://gerrit.libreoffice.org/c/help/+/113352 Tested-by: Jenkins Reviewed-by: Olivier Hallot --- source/text/sbasic/shared/03010103.xhp | 2 +- source/text/sbasic/shared/03020101.xhp | 4 ++ source/text/sbasic/shared/03020102.xhp | 43 +++++----------- source/text/sbasic/shared/03020103.xhp | 84 ++++++++++++++++++++++--------- source/text/sbasic/shared/03020104.xhp | 13 +++-- source/text/sbasic/shared/03020201.xhp | 92 +++++++++++++++++++++++----------- source/text/sbasic/shared/03020202.xhp | 20 ++++---- source/text/sbasic/shared/03020203.xhp | 5 ++ source/text/sbasic/shared/03020205.xhp | 52 +++++++++++++------ source/text/sbasic/shared/03020301.xhp | 41 +++++---------- source/text/sbasic/shared/03020303.xhp | 44 +++++----------- source/text/sbasic/shared/03020405.xhp | 28 +++++++---- source/text/sbasic/shared/03020410.xhp | 17 ++++--- source/text/sbasic/shared/03050500.xhp | 25 ++++----- 14 files changed, 260 insertions(+), 210 deletions(-) (limited to 'source/text') diff --git a/source/text/sbasic/shared/03010103.xhp b/source/text/sbasic/shared/03010103.xhp index f1f0c287a4..c60a4925ff 100644 --- a/source/text/sbasic/shared/03010103.xhp +++ b/source/text/sbasic/shared/03010103.xhp @@ -66,7 +66,7 @@ Print "ABC" Print "ABC","123" i = FreeFile() - Open "C:\Temp.txt" For Output As i + Open "C:\Users\ThisUser\Temp.txt" For Output As i Print #i, "ABC" Close #i End Sub diff --git a/source/text/sbasic/shared/03020101.xhp b/source/text/sbasic/shared/03020101.xhp index 79247f40ca..78cb1907fa 100644 --- a/source/text/sbasic/shared/03020101.xhp +++ b/source/text/sbasic/shared/03020101.xhp @@ -52,5 +52,9 @@ +
+ + +
\ No newline at end of file diff --git a/source/text/sbasic/shared/03020102.xhp b/source/text/sbasic/shared/03020102.xhp index 66160f95e1..d906b63195 100644 --- a/source/text/sbasic/shared/03020102.xhp +++ b/source/text/sbasic/shared/03020102.xhp @@ -34,50 +34,31 @@ -FreeFile Function +FreeFile Function Returns the next available file number for opening a file. Use this function to open a file using a file number that is not already in use by a currently open file. -Syntax: + FreeFile -Return value: + Integer -Parameters: + This function can only be used immediately in front of an Open statement. FreeFile returns the next available file number, but does not reserve it. -Example: - -Sub ExampleWorkWithAFile -Dim iNumber As Integer -Dim sLine As String -Dim aFile As String -Dim sMsg As String - aFile = "c:\data.txt" - sMsg = "" - iNumber = Freefile - Open aFile For Output As #iNumber - Print #iNumber, "First line of text" - Print #iNumber, "Another line of text" - Close #iNumber - iNumber = Freefile - Open aFile For Input As #iNumber - While Not eof(#iNumber) - Line Input #iNumber, sLine - If sLine <>"" Then - sMsg = sMsg & sLine & chr(13) - End If - Wend - Close #iNumber - MsgBox sMsg -End Sub - - + + +
+ + + +
+ \ No newline at end of file diff --git a/source/text/sbasic/shared/03020103.xhp b/source/text/sbasic/shared/03020103.xhp index bb605bc896..ddf55d217a 100644 --- a/source/text/sbasic/shared/03020103.xhp +++ b/source/text/sbasic/shared/03020103.xhp @@ -62,31 +62,67 @@
- -Sub ExampleWorkWithAFile -Dim iNumber As Integer -Dim sLine As String -Dim aFile As String -Dim sMsg As String - aFile = "c:\data.txt" - iNumber = Freefile - Open aFile For Output As #iNumber - Print #iNumber, "This is a line of text" - Print #iNumber, "This is another line of text" - Close #iNumber - iNumber = Freefile - Open aFile For Input As iNumber - While Not eof(iNumber) - Line Input #iNumber, sLine - If sLine <>"" Then - sMsg = sMsg & sLine & chr(13) - End If - Wend - Close #iNumber - MsgBox sMsg -End Sub + + + + Sub ExampleWorkWithAFile + Dim iNumber As Integer + Dim sLine As String + Dim aFile As String + Dim sMsg As String + aFile = "C:\Users\ThisUser\data.txt" + iNumber = Freefile + Open aFile For Output As #iNumber + Print #iNumber, "This is a line of text" + Print #iNumber, "This is another line of text" + Close #iNumber + iNumber = Freefile + Open aFile For Input As iNumber + While Not eof(iNumber) + Line Input #iNumber, sLine + If sLine <>"" Then + sMsg = sMsg & sLine & chr(13) + End If + Wend + Close #iNumber + MsgBox sMsg + End Sub + + + + Sub ExampleWorkWithAFile + Dim iNumber As Integer + Dim sLine As String + Dim aFile As String + Dim sMsg As String + aFile = "~/data.txt" + iNumber = Freefile + Open aFile For Output As #iNumber + Print #iNumber, "This is a line of text" + Print #iNumber, "This is another line of text" + Close #iNumber + iNumber = Freefile + Open aFile For Input As iNumber + While Not eof(iNumber) + Line Input #iNumber, sLine + If sLine <>"" Then + sMsg = sMsg & sLine & chr(13) + End If + Wend + Close #iNumber + MsgBox sMsg + End Sub + + + +
+If the Open statement tries to open a file to which the current user does not have read/write permissions, an I/O error will be raised. +
+ + + +
- \ No newline at end of file diff --git a/source/text/sbasic/shared/03020104.xhp b/source/text/sbasic/shared/03020104.xhp index 45b65045f7..9d09da144c 100644 --- a/source/text/sbasic/shared/03020104.xhp +++ b/source/text/sbasic/shared/03020104.xhp @@ -48,11 +48,11 @@ Sub ExampleReset On Error GoTo ErrorHandler -Dim iNumber As Integer -Dim iCount As Integer -Dim sLine As String -Dim aFile As String - aFile = "c:\data.txt" + Dim iNumber As Integer + Dim iCount As Integer + Dim sLine As String + Dim aFile As String + aFile = "C:\Users\ThisUser\data.txt" iNumber = Freefile Open aFile For Output As #iNumber Print #iNumber, "This is a new line of text" @@ -69,7 +69,7 @@ Exit Sub ErrorHandler: Reset - MsgBox "All files will be closed",0,"Error" + MsgBox "All files will be closed", 0, "Error" End Sub @@ -77,6 +77,5 @@ - \ No newline at end of file diff --git a/source/text/sbasic/shared/03020201.xhp b/source/text/sbasic/shared/03020201.xhp index b2885659d2..300451363d 100644 --- a/source/text/sbasic/shared/03020201.xhp +++ b/source/text/sbasic/shared/03020201.xhp @@ -50,37 +50,70 @@ recordNum: For files opened in Random mode, recordNum is the number of the record that you want to read. For files opened in Binary mode, filePos is the byte position in the file where the reading starts. If recordNum and filePos are omitted, the current position or the current data record of the file is used. - variable: Name of the variable to be read. With the exception of object variables, you can use any variable type. +variable: Name of the variable to be read. With the exception of object variables, you can use any variable type. -
- -Sub ExampleRandomAccess - Dim iNumber As Integer - Dim sText As Variant ' Must be a variant - Dim aFile As String - aFile = "c:\data.txt" - iNumber = Freefile - Open aFile For Random As #iNumber Len=32 - Seek #iNumber,1 ' Position at beginning - Put #iNumber,, "This is the first line of text" ' Fill line with text - Put #iNumber,, "This is the second line of text" - Put #iNumber,, "This is the third line of text" - Seek #iNumber,2 - Get #iNumber,,sText - Print sText - Close #iNumber - iNumber = Freefile - Open aFile For Random As #iNumber Len=32 - Get #iNumber,2,sText - Put #iNumber,,"This is a new text" - Get #iNumber,1,sText - Get #iNumber,2,sText - Put #iNumber,20,"This is the text in record 20" - Print Lof(#iNumber) - Close #iNumber -End Sub - +
+ + + + Sub ExampleRandomAccess + Dim iNumber As Integer + Dim sText As Variant ' Must be a variant + Dim aFile As String + aFile = "C:\Users\ThisUser\data.txt" + iNumber = Freefile + Open aFile For Random As #iNumber Len=32 + Seek #iNumber,1 ' Position at beginning + Put #iNumber, , "This is the first line of text" ' Fill line with text + Put #iNumber, , "This is the second line of text" + Put #iNumber, , "This is the third line of text" + Seek #iNumber,2 + Get #iNumber, , sText + Print sText + Close #iNumber + iNumber = Freefile + Open aFile For Random As #iNumber Len=32 + Get #iNumber, 2, sText + Put #iNumber, , "This is a new text" + Get #iNumber, 1, sText + Get #iNumber, 2, sText + Put #iNumber, 20, "This is the text in record 20" + Print Lof(#iNumber) + Close #iNumber + End Sub + + + + + Sub ExampleRandomAccess + Dim iNumber As Integer + Dim sText As Variant ' Must be a variant + Dim aFile As String + aFile = "~/data.txt" + iNumber = Freefile + Open aFile For Random As #iNumber Len=32 + Seek #iNumber,1 ' Position at beginning + Put #iNumber, , "This is the first line of text" ' Fill line with text + Put #iNumber, , "This is the second line of text" + Put #iNumber, , "This is the third line of text" + Seek #iNumber,2 + Get #iNumber, , sText + Print sText + Close #iNumber + iNumber = Freefile + Open aFile For Random As #iNumber Len=32 + Get #iNumber, 2, sText + Put #iNumber, , "This is a new text" + Get #iNumber, 1, sText + Get #iNumber, 2, sText + Put #iNumber, 20, "This is the text in record 20" + Print Lof(#iNumber) + Close #iNumber + End Sub + + +
@@ -88,6 +121,5 @@
- \ No newline at end of file diff --git a/source/text/sbasic/shared/03020202.xhp b/source/text/sbasic/shared/03020202.xhp index 17e20c0fb8..63adaa36d3 100644 --- a/source/text/sbasic/shared/03020202.xhp +++ b/source/text/sbasic/shared/03020202.xhp @@ -32,7 +32,7 @@ Input statement -Input# Statement +Input# Statement Reads data from an open sequential file.
@@ -55,12 +55,10 @@ Sub ExampleWorkWithAFile -Dim iCount As Integer, sFileName As String -Dim sName As String, sValue As Integer - - sFileName = "C:\data.txt" + Dim iCount As Integer, sFileName As String + Dim sName As String, sValue As Integer + sFileName = "C:\Users\ThisUser\data.txt" iCount = Freefile - ' Write data ( which we will read later with Input ) to file Open sFileName For Output As iCount sName = "Hamburg" : sValue = 200 @@ -70,9 +68,8 @@ sName = "Miami" : sValue = 459 Write #iCount, sName, sValue Close #iCount - - iCount = Freefile ' Read data file using Input + iCount = Freefile Open sFileName For Input As iCount Input #iCount, sName, sValue MsgBox sName & " " & sValue @@ -83,6 +80,11 @@ Close #iCount End Sub - +
+ + + + +
\ No newline at end of file diff --git a/source/text/sbasic/shared/03020203.xhp b/source/text/sbasic/shared/03020203.xhp index 79143d2a0f..1171862686 100644 --- a/source/text/sbasic/shared/03020203.xhp +++ b/source/text/sbasic/shared/03020203.xhp @@ -52,5 +52,10 @@ +
+ + + +
\ No newline at end of file diff --git a/source/text/sbasic/shared/03020205.xhp b/source/text/sbasic/shared/03020205.xhp index 608395b6ba..f971953973 100644 --- a/source/text/sbasic/shared/03020205.xhp +++ b/source/text/sbasic/shared/03020205.xhp @@ -56,21 +56,42 @@ Numbers with decimal delimiters are converted according to the locale settings. - -Sub ExampleWrite - Dim iCount As Integer - Dim sValue As String - iCount = Freefile - Open "C:\data.txt" For Output As iCount - sValue = "Hamburg" - Write #iCount,sValue,200 - sValue = "New York" - Write #iCount,sValue,300 - sValue = "Miami" - Write #iCount,sValue,450 - Close #iCount -End Sub - + + + + Sub ExampleWrite + Dim iCount As Integer + Dim sValue As String + iCount = Freefile + Open "C:\Users\ThisUser\data.txt" For Output As iCount + sValue = "Hamburg" + Write #iCount,sValue,200 + sValue = "New York" + Write #iCount,sValue,300 + sValue = "Miami" + Write #iCount,sValue,450 + Close #iCount + End Sub + + + + + Sub ExampleWrite + Dim iCount As Integer + Dim sValue As String + iCount = Freefile + Open "~/data.txt" For Output As iCount + sValue = "Hamburg" + Write #iCount,sValue,200 + sValue = "New York" + Write #iCount,sValue,300 + sValue = "Miami" + Write #iCount,sValue,450 + Close #iCount + End Sub + + +
@@ -78,6 +99,5 @@
- \ No newline at end of file diff --git a/source/text/sbasic/shared/03020301.xhp b/source/text/sbasic/shared/03020301.xhp index b9c84f4568..2c681a0aa5 100644 --- a/source/text/sbasic/shared/03020301.xhp +++ b/source/text/sbasic/shared/03020301.xhp @@ -38,46 +38,29 @@ Determines if the file pointer has reached the end of a file. -Syntax: + Eof (intexpression As Integer) -Return value: + Bool -Parameters: + Intexpression: Any integer expression that evaluates to the number of an open file. Use EOF to avoid errors when you attempt to get input past the end of a file. When you use the Input or Get statement to read from a file, the file pointer is advanced by the number of bytes read. When the end of a file is reached, EOF returns the value "True" (-1). -Example: - -Sub ExampleWorkWithAFile -Dim iNumber As Integer -Dim sLine As String -Dim aFile As String -Dim sMsg As String - aFile = "c:\data.txt" - iNumber = Freefile - Open aFile For Output As #iNumber - Print #iNumber, "First line of text" - Print #iNumber, "Another line of text" - Close #iNumber - iNumber = Freefile - Open aFile For Input As iNumber - While Not eof(iNumber) - Line Input #iNumber, sLine - If sLine <>"" Then - sMsg = sMsg & sLine & chr(13) - End If - Wend - Close #iNumber - MsgBox sMsg -End Sub - - + + +
+ + + + +
+ \ No newline at end of file diff --git a/source/text/sbasic/shared/03020303.xhp b/source/text/sbasic/shared/03020303.xhp index a003877244..9ff89b5c44 100644 --- a/source/text/sbasic/shared/03020303.xhp +++ b/source/text/sbasic/shared/03020303.xhp @@ -36,46 +36,28 @@ Lof Function Returns the size of an open file in bytes. -Syntax: + Lof (FileNumber) -Return value: + Long -Parameters: + FileNumber: Any numeric expression that contains the file number that is specified in the Open statement. To obtain the length of a file that is not open, use the FileLen function. -Example: - -Sub ExampleRandomAccess -Dim iNumber As Integer -Dim sText As Variant REM must be a Variant -Dim aFile As String - aFile = "c:\data.txt" - iNumber = Freefile - Open aFile For Random As #iNumber Len=32 - Seek #iNumber,1 REM Position at start - Put #iNumber,, "This is the first line of text" REM Fill with text - Put #iNumber,, "This is the second line of text" - Put #iNumber,, "This is the third line of text" - Seek #iNumber,2 - Get #iNumber,,sText - Print sText - Close #iNumber - iNumber = Freefile - Open aFile For Random As #iNumber Len=32 - Get #iNumber,2,sText - Put #iNumber,,"This is a new line of text" - Get #iNumber,1,sText - Get #iNumber,2,sText - Put #iNumber,20,"This is the text in record 20" - Print Lof(#iNumber) - Close #iNumber -End Sub - + + + + +
+ + + + +
diff --git a/source/text/sbasic/shared/03020405.xhp b/source/text/sbasic/shared/03020405.xhp index 09b49a3fa2..d19d305467 100644 --- a/source/text/sbasic/shared/03020405.xhp +++ b/source/text/sbasic/shared/03020405.xhp @@ -40,15 +40,15 @@ If you use a 32-Bit operating system, you cannot use the FileAttr-Function to determine the file access number. See also: Open -Syntax: + FileAttr (FileNumber As Integer, Attribute As Integer) -Return value: + Integer -Parameters: + FileNumber: The number of the file that was opened with the Open statement. Attribute: Integer expression that indicates the type of file information that you want to return. The following values are possible: 1: The FileAttr-Function indicates the access mode of the file. @@ -63,21 +63,27 @@ -Example: + Sub ExampleFileAttr -Dim iNumber As Integer -Dim sLine As String -Dim aFile As String - aFile = "c:\data.txt" + Dim iNumber As Integer + Dim sLine As String + Dim aFile As String + aFile = "C:\Users\ThisUser\data.txt" iNumber = Freefile Open aFile For Output As #iNumber Print #iNumber, "This is a line of text" - MsgBox FileAttr(#iNumber, 1 ),0,"Access mode" - MsgBox FileAttr(#iNumber, 2 ),0,"File attribute" + MsgBox FileAttr(#iNumber, 1), 0, "Access mode" + MsgBox FileAttr(#iNumber, 2), 0, "File attribute" Close #iNumber End Sub - +
+ + + + +
+ \ No newline at end of file diff --git a/source/text/sbasic/shared/03020410.xhp b/source/text/sbasic/shared/03020410.xhp index bba94acb7f..0c2214b170 100644 --- a/source/text/sbasic/shared/03020410.xhp +++ b/source/text/sbasic/shared/03020410.xhp @@ -38,23 +38,26 @@ Deletes a file from a disk. -Syntax: + Kill File As String -Parameters: + File: Any string expression that contains an unambiguous file specification. You can also use URL notation. -Example: + -Sub ExampleKill - Kill "C:\datafile.dat" ' File must be created in advance -End Sub +Sub ExampleKill + Kill "C:\Users\ThisUser\datafile.dat" ' File must be created in advance +End Sub - +
+ +
+ \ No newline at end of file diff --git a/source/text/sbasic/shared/03050500.xhp b/source/text/sbasic/shared/03050500.xhp index 7e0e1e11a3..3d1e71c390 100644 --- a/source/text/sbasic/shared/03050500.xhp +++ b/source/text/sbasic/shared/03050500.xhp @@ -26,20 +26,16 @@ - -
Resume Next parameter On Error GoTo ... Resume statement - - On Error GoTo ... Resume Statement Enables an error-handling routine after an error occurs, or resumes program execution.
-Syntax: + On Error Statement diagram @@ -47,22 +43,22 @@ On [Local] Error {GoTo Labelname | GoTo 0 | Resume Next} -Parameters: + GoTo Labelname: If an error occurs, enables the error-handling routine that starts at the line "Labelname". Resume Next: If an error occurs, program execution continues with the statement that follows the statement in which the error occurred. GoTo 0: Disables the error handler in the current procedure. Local: "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. The On Error GoTo statement is used to react to errors that occur in a macro.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. -Example: + Sub ExampleReset On Error GoTo ErrorHandler -Dim iNumber As Integer -Dim iCount As Integer -Dim sLine As String -Dim aFile As String - aFile = "c:\data.txt" + Dim iNumber As Integer + Dim iCount As Integer + Dim sLine As String + Dim aFile As String + aFile = "C:\Users\ThisUser\data.txt" iNumber = Freefile Open aFile For Output As #iNumber Print #iNumber, "This is a line of text" @@ -79,11 +75,12 @@ Exit Sub ErrorHandler: Reset - MsgBox "All files will be closed",0,"Error" + MsgBox "All files will be closed", 0, "Error" End Sub
+
- \ No newline at end of file + -- cgit