Integrated software for developing cross-platform applications    Integrated software for developing cross-platform applications
WINDEV, WEBDEV and WINDEV Mobile
The WINDEV, WEBDEV and WINDEV Mobile environments are compatible and share project elements. It has never been easier to build multi-target applications.
WLanguage functions (3480)
 

Both static typing and dynamic typing are proposed in WLanguage.
It includes a flexible system for type management that allows for fast development by using the dynamic typing while taking advantage of static typing.
Its virtual machine includes a system for automatic memory management.
Advanced types of data are available as well as high-precision numerics (38 significant digits).
It supports several programming paradigms: object-oriented, procedural and imperative programming.
 

29 WLANGUAGE CODE SAMPLES (5GL)

This page presents WLanguage code samples.

This is what L5G code looks like!
(and don't forget that there is nothing to code for several functions, all you have to do is click the choices proposed by the IDE ; these examples present the language only).


 
 
Example 1: Scanning a document

// Saves the document found in the scanner in the "MyPhoto.JPEG" file
// The document will be saved in black and white
IF TwainToBMP("C:\Temp\MyPhoto.BMP", False, TwainBlackWhite) = True THEN
Info("The document was saved")
ELSE
Error("The document was not scanned")
END


Example 2: Reading a registry key


// Reads the "Language" value in the "HKEY_LOCAL_MACHINE\SOFTWARE\App" key
// ResExecute is a boolean used to find out whether the value was read
ResRead = RegistryQueryValue("HKEY_LOCAL_MACHINE\SOFTWARE\App", "Language", ResExecute)

IF ResExecute = True THEN
Info("The value was read and it is set to: " + ResRead)
END


Example 3: Selecting a color


Value is int 
SelectionResult is boolean

Value =  RGB(10, 17, 69)
Info("Initial color: " + Value)
SelectionResult = SelectColor(Value, scInit)
Info("Final color: " + Value)


Example 4: Calculating the number of days between 2 dates


// Displays the number of days passed since 01/01/1998
Info(NumToString(DateDifference("19980101", DateSys())) + "days spent")


Example 5: Extracting part of a file path


sFilePath is string
sResFileName is string

sFilePath = "C:\MyDirectories\File.psw"

// Retrieve the name of the file
sResFileName = fExtractPath(sFilePath, fFileName)
// sResFileName corresponds to "File"


Example 6: Transforms a number into a character string corresponding to the number "written in words"

Info(NumberInWords(83.335))
// Displays "eighty three point thirty four"

Info(NumberInWords(1.10, "Euro(s)"))
// Displays "one Euro ten"

Info(NumberInWords(1.01, "Euro(s)", "cent(s)"))
// Displays "one Euro and one cent"


Example 7: Sending an email

IF EmailStartSession(USER, PASSWORD, "pop3.gmail.com", ...
"smtp.gmail.com") = True THEN
UserName = USER
ELSE
  UserName = ""
  Error("Unable to establish the connection")
END

// Initializes the email components
// The sender
Email.Sender = "<user@pcsoft.fr>"
// The recipient
Email.Recipient[1] = RECIPIENT
// The number of recipients
Email.NbRecipient = 1
// The subject
Email.Subject = SUBJECT
// The message body
Email.Message = TEXT
// The number of attachments
Email.NbAttach = 0

// Sends the email
IF EmailSendMessage(UserName) = False THEN
Error()
END


Example 8: Adding an icon in the systray

// Add the "C:\Icons\Icon.ICO" icon into the taskbar
ResAddIcon = SysIconAdd("C:\Icons\Icon.ICO", "", "Sales 2013")


Example 9: Saving a screen shot

// Saves in memory the image found in "IMG_ImageDrawing"
ResSave = dSaveImageJPEG(IMG_ImageDrawing, inMemory)


Example 10: Example for declaring variables


// Declaration of variables

Value
is int
SelectionResult is boolean
Price is real
i,j,k are int


Example 11: Code/Interface interaction

// Runs the click code on a button
ExecuteProcess(BTN_Save, trtClick)


Example 12: Managing threads by programming

// Run a thread while passing parameters
sDate is string 
sDate = DateSys()
// Run the thread
ThreadExecute("THREADNAME", threadNormal, "pExecQry", sDate)

// Details of the "pExecQry" procedure 
// This procedure expects a date in parameter of a query
PROCEDURE pExecQry(sDate)
IF HExecuteQuery(Del_Date, hQueryDefault, sDate) = False THEN
Error(HErrorInfo())
ELSE
HReadFirst(Del_Date)
END


Example 13: Print preview

// No button in the preview
iParameterPreview(iButtonNone)
iPreview()
iPrintReport(RPT_MyReport)


Example 14: Printing in HTML

// Print a report based on a query without parameter in an HTML file
// Generate a unique file name
MyReportFile is string = fWebDir() + "\" + "ReportQuery_" + DateSys() + TimeSys() + ".htm"
// Configure the destination of the print
iDestination(iHTML, MyReportFile)
// Print the RPT_QueryReport report
iPrintReport(RPT_QueryReport)
// Extract the name and extension of the generated file
NameGeneratedFile is string = fExtractPath(MyReportFile, fFileName + fExtension)
// Send the file to the browser
PageDisplay(NameGeneratedFile)


Example 15: Generating a PDF file

// Generate a unique PDF file name
AFile is string  
AFile = fWebDir() + "\" + DateSys() + TimeSys() + ".pdf" 
// Configure the destination of the print 
iDestination(iPDF, AFile) 
// Print the RPT_InvoicePDF report
iPrintReport(RPT_InvoicePDF) 
// Send the file to the browser 
FileDisplay(AFile, "application/pdf") 
// Delete the file 
fDelete(AFile)



Example 16: Protecting a PDF file


// In this example, the password is "password"
iParameterPDF("opening", "password", iProtectionPrinting + iProtectionSelection)

// Create the PDF file
iPreview(iPDF, "MyPDF.PDF")

// Code for print
iCreateFont(1, 16, iBold, iRoman)
iPrintWord("First line of my PDF" + CR + "Second line of my PDF" + ...
CR + "Last line of my PDF")

// End of print and close the created PDF file
iEndPrinting()

// Display the PDF
ShellExecute(iLastFile())


Example 17: Selecting a PCL printer (mobile)

// PCL printer to use
iDestination(iPCL, "\\MyNetwork\MyPrinter")


Example 18: Print in PCL format (mobile)

iDestination(iPCL, "\MyDocuments\MyFile.PCL")


Example 19: Dialing a phone number

IF tapiDial(EDT_PhoneNumber, "LineStatus")=True THEN 
Info("Click OK to hang up") 
tapiHangUp() 
END

PROCEDURE TestLineStatus(ValueLineStatus is int) 
SWITCH ValueLineStatus 
CASE tapiLineBusy: Message("The line is busy") 
CASE tapiLineConnected: Message("OK, connected")
CASE tapiLineDialing: Message("Dialing in progress") 
CASE tapiLineDialTone: Message("Dial tone")
CASE tapiLineDisconnected: Message("The correspondent has hung up")
CASE tapiLineProceeding: Message("Searching for your correspondent")
CASE tapiLineRingBack: Message("Ringing")
END


Example 20: Financial calculations

// Interest rate for a loan of 25000 Euros. Six payments
// of 5000 Euros are required to pay off the loan.
ResInterestRate = FinInterestRate(6, -5000, 25000)


Example 21: Reading a text file line by line

// Exit according to an IF condition
LOOP
        // Read a line in the text file
        ALine = fReadLine(FileNum)
        IF ALine = EOT THEN BREAK
        ProcessLine(ALine)
END


Example 22: Exit according to a WHILE condition

MyList = INIRead("Examples", "", "", INIFile)
Keyword = ExtractString(MyList, nb, CR)
WHILE Keyword <> ""
        nb = nb + 1
        ExplName = INIRead("Projects installed", Keyword, "", INIFile)
        Keyword = ExtractString(MyList, nb + 1, CR)
END


Example 23: Exit according to an iteration


// Exit according to an iteration
LOOP (10)
        // Read a line in the text file
        ALine = fReadLine(FileNum)
        ProcessLine(ALine)
END


Example 24: Export to Excel

sFile is string
// Asks for the name of the file
sFile = fSelect("", "", "Choose the export file", ...
"Excel files (*.xls) *.xls", "xls", fselCreate + fselExist)
// If the name was not specified, cancels the export
// Otherwise, exports the content of TABLE_TABLE1
IF sFile <> "" THEN TableToWord(TABLE_TABLE1, sFile, taNoTitle)



Example 25: Export to XML


sFile is string
// Name of the file
sFile = fSelect("", "", "Choose the export file", ...
"XML files (*.XML) *.xml", "xml", fselCreate + fselExist)
// The export is canceled if no name was specified
// Otherwise, export the content of TABLE_TABLE1
IF sFile <> "" THEN TableToXML(TABLE_TABLE1, sFile, taNoTitle)


Example 26: Extracting part of a file path

sFile is string
// Asks for the name of the file
sFile = fSelect("", "", "Choose the export file", ...
"Word files (*.rtf) *.rtf", "rtf", fselCreate + fselExist)
// If the name was not specified, cancels the export
// Otherwise, exports the content of TABLE_TABLE1
IF sFile <> "" THEN TableToWord(TABLE_TABLE1, sFile, taNoTitle)


Example 27: Sending an SMS

// Initialize the SMS structure for a standard number 
SMS.Number = "0610203040" 
SMS.Message = "I am sending SMSs with WINDEV Mobile!" 

// Send the SMS 
ResSend is boolean = SMSSend() 

// Error occurred? 
IF ResSend = False THEN 
Error(ErrorInfo(errMessage)) 
END


Example 28: Sending a fax

ConnectID is int
ConnectID = FaxConnect()
IF ConnectID = 0 THEN 
Error("The connection to the fax server failed." + ...
 "Check whether it has been started", ...
ErrorInfo(errSystemMessage))
ELSE
 ListAdd(LIST_FaxSend, FaxOutbox(ConnectID))
END
...
// Click code of the list box
IF FaxStatus(LIST_FaxSend..DisplayedValue) = FaxStatusHandled THEN
 FaxRestart(LIST_FaxSend..DisplayedValue) 
END

...
FaxDisconnect(ConnectID)


Example 29: Acquisition on the serial port
(this code is generated by a wizard, you don't even have to type it!)


Result1 = sOpen(1, 2000, 2000) // Open COM1
IF Result1 = True THEN
// Configure Com1: Rate 9600, even parity, 
// 8 data bits, 1 stop bit
sParameter(1, 9600, 1, 8, 0) // Configure COM1 
// Rest of process...
sClose(1) // Close COM1
ELSE
Error("Error while opening COM1")
END