PC SOFT

ONLINE HELP
FOR WINDEV, WEBDEV AND WINDEV MOBILE

Home | Sign in | English US
  • Method 1: Using the fWriteLine function
  • Code samples
  • Method 2: Using the fSaveText function
  • Principle
  • Code samples
WINDEV
WindowsLinuxUniversal Windows 10 AppJavaReports and QueriesUser code (UMC)
WEBDEV
WindowsLinuxPHPWEBDEV - Browser code
WINDEV Mobile
AndroidAndroid Widget iPhone/iPadApple WatchUniversal Windows 10 AppWindows Mobile
Others
Stored procedures
Method 1: Using the fWriteLine function
To write a line into a text or CSV file:
  1. Open the file (or create it) with fOpen.
  2. Write the line with fWriteLine. fWriteLine automatically adds a CR character at the end of line.
  3. Close the file with fClose.

Code samples

  • Writing a line:
    // Write a simple string
    nFileNum is int
    sLineToWrite is string

    nFileNum = fOpen("MyFile.txt", foCreate)
    IF nFileNum <> -1 THEN
    sLineToWrite = "Hello, today is " + DateToString(Today(), "DDDD DD MMMM YYYY")

    // Write the line
    fWriteLine(nFileNum, sLineToWrite)

    fClose(nFileNum)
    END
  • Converting a data file into TXT (export)
    <code WL>
    nFileNum is int
    sLineToWrite is string

    nFileNum = fOpen ("ExportProducts.txt", foCreate)
    IF nFileNum <> -1 THEN
    FOR EACH Product
    // The line is made of:
    // - the product reference
    // - the product caption
    // - the product price
    sLineToWrite = Product.Reference + TAB + Product.ProdCap + TAB +
    NumToString(Product.Price, "10,2fS")

    // Write the line
    fWriteLine(nFileNum, sLineToWrite)
    END
    fClose(nFileNum)
    END
Method 2: Using the fSaveText function

Principle

To write (create) a text or CSV file in a single operation:
  1. Declare a string variable.
  2. Write and store all the file lines in memory in this variable.
  3. Save the content of this variable in a file with fSaveText.

Code samples

// Convert a data file into TXT (export)
sLineToWrite is string
sFileContent is string

FOR EACH Product
// The line is made of:
// - the product reference
// - the product caption
// - the product price
sLineToWrite = Product.Reference + TAB + Product.ProdCap + TAB +
NumToString(Product.Price, "10,2fS")

// Write the line in memory
sFileContent += sLineToWrite + CR
END
fSaveText ("ExportProducts.txt", sFileContent)
Minimum required version
  • Version 9
This page is also available for…
Comments
Click [Add] to post a comment