Professional Documents
Culture Documents
29 Wlanguage Code Samples
29 Wlanguage Code Samples
(5GL)
This page presents WLanguage code samples.
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"
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
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 21: Reading a text file line by line
// 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!"
// 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