WriteLine.htm 2.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778
  1. <html>
  2. <head>
  3. <title>Blitz3D Docs</title>
  4. <link rel=stylesheet href=../css/commands.css type=text/css>
  5. </head>
  6. <body>
  7. <h1>WriteLine$ (filehandle/stream, string$)</h1>
  8. <h1>Parameters</h1>
  9. <table>
  10. <tr>
  11. <td>
  12. filehandle/stream = a valid variable set with the OpenFile, WriteFile command, or OpenTCPStream (v1.52+). The value returned is a text string. <br />
  13. string$ = valid string value.
  14. </td>
  15. </tr>
  16. </table>
  17. <h1>Description</h1>
  18. <table>
  19. <tr>
  20. <td>
  21. Once you've opened a disk file (or stream) for writing, use this command to right a whole line of text to the file. Each line of text is automatically terminated with an "end-of-line" mark, consisting of a Carriage Return character followed by a LineFeed character. (i.e. 0Dh, 0Ah ) This function can be used to make plain text files. <br />
  22. <br />
  23. Streams can only be used in Blitz Basic v1.52 or greater.
  24. </td>
  25. </tr>
  26. </table>
  27. <h1><a href=../2d_examples/WriteLine.bb>Example</a></h1>
  28. <table>
  29. <tr>
  30. <td>
  31. ; Reading and writing a file using ReadLine$ and WriteLine functions <br />
  32. <br />
  33. ; Initialise some variables for the example <br />
  34. String1$ = "Line 1 is short" <br />
  35. String2$ = "Line 2 is a longer line but they can be much longer" <br />
  36. String3$ = "Line 3 is made up " <br />
  37. String4$ = "of two parts joined together." <br />
  38. <br />
  39. ; Open a file to write to <br />
  40. fileout = WriteFile("mydata.txt") <br />
  41. <br />
  42. ; Write the information to the file <br />
  43. WriteLine( fileout, String1 ) <br />
  44. WriteLine( fileout, String2 ) <br />
  45. WriteLine( fileout, String3 + String4) <br />
  46. WriteLine( fileout, "Just to show you don't have to use variables" ) <br />
  47. <br />
  48. ; Close the file <br />
  49. CloseFile( fileout ) <br />
  50. <br />
  51. ; Open the file to Read <br />
  52. filein = ReadFile("mydata.txt") <br />
  53. <br />
  54. Read1$ = ReadLine( filein ) <br />
  55. Read2$ = ReadLine$( filein ) <br />
  56. Read3$ = ReadLine$( filein ) <br />
  57. Read4$ = ReadLine$( filein ) <br />
  58. <br />
  59. ; Close the file once reading is finished <br />
  60. CloseFile( filein ) <br />
  61. <br />
  62. Print "Lines of text read from file - mydata.txt " <br />
  63. Print <br />
  64. Print Read1 <br />
  65. Print Read2 <br />
  66. Print Read3 <br />
  67. Print Read4 <br />
  68. <br />
  69. WaitKey() <br />
  70. </td>
  71. </tr>
  72. </table>
  73. <br>
  74. <a target=_top href=../index.htm>Index</a><br>
  75. <br>
  76. Click <a href=http://www.blitzbasic.co.nz/b3ddocs/command.php?name=WriteLine&ref=comments target=_blank>here</a> to view the latest version of this page online</body>
  77. </html>