PowerBuilder Manual Book Part 4
PowerBuilder Curriculum Part 4
5. String
(1), Fill
Function:
Creates a String Of the specified Length filled With the specified String.
Syntax:
Fill ( chars, n )
parameter:
chars: String Type, specify the String used For repeated padding
n: Long Type, specifying the Length Of the String returned By This Function
Return Value:
Return Value: String.
When the Function executes successfully, it returns a String Of n characters, which Is filled With the strings In the parameter chars repeatedly.
If the Number Of characters In the parameter chars Is more than n, Then use the First n characters Of the chars String To Fill the String returned By the Function;
If the Number Of characters In the parameter chars Is less than n, Then use the chars String To Fill it repeatedly Until the Length Of the returned String reaches n.
If the Value Of Any parameter Is Null, the Fill() Function returns Null
(2), Left
Function:
Gets the specified Number Of characters From the Left Of the String.
Syntax:
Left ( String, n )
parameter:
String: String Type, specify the String To extract the substring
n: Long Type, specifies the Length Of the substring
Return Value:
the Return Value Is String.
When the Function executes successfully, it returns n characters To the Left Of the String String, And returns an empty String ("") When an Error occurs.
If the Value Of Any parameter Is Null, the Left() Function returns Null.
If the Value Of n Is greater than the Length Of the String String, Then the Left () Function returns the entire String String, but does Not add Other characters.
(3), Left Trim
Function:
Returns the specified String With Left spaces removed.
Syntax:
LeftTrim ( String )
parameter:
String: String Type, specify the String To Delete the Left Space
Return Value:
Return Value: String.
When the Function executes successfully, it Returns a String With the spaces at the Left Of the String removed, And When an Error occurs, it Returns an empty String ("").
If the Value Of Any parameter Is Null, the LeftTrim() Function Returns Null.
(4), Len
Function:
Get the Length Of the String.
Syntax:
Len (String)
parameter:
String: String Type variable
Return Value:
Return Value: Long.
the Function returns the Length Of the String when the Function executes successfully, And returns -1 when an Error occurs.
If the Value Of Any parameter Is Null, the Len() Function returns Null.
(5), Lower
Function:
Convert uppercase letters In a String To lowercase.
Syntax:
Lower ( String )
parameter:
String: The String To Convert uppercase letters To lowercase letters
Return Value:
Return Value: String.
When The Function executes successfully, it returns a String after converting uppercase letters To lowercase letters, And returns an empty String ("") When an Error occurs.
If The Value Of The String parameter Is Null, The Lower() Function returns Null.
(6), Match
Function:
Determines whether a String contains characters Of the specified pattern
Syntax:
Match (String, textpattern)
parameter:
String: String Type, specifies the String To Check whether it matches the specified pattern
textpattern: String Type, specifies the Text matching pattern
Return Value:
Return Value Boolean: If the String String matches the pattern textpattern, the Function returns True, otherwise it returns False.
If the specified matching pattern Is invalid Or either Of the above two parameters has Not been assigned a Value, Then the Match() Function returns False.
If the Value Of Any parameter Is Null, the Match() Function returns Null.
usage
The writing method Of The textpattern parameter Is very similar To a regular expression, And it consists Of metacharacters And ordinary characters.
Each metacharacter has a different matching meaning, And a normal Character matches itself.
The following are The metacharacters used In matching patterns And their meanings:
^ indicates The beginning Of a String, For example, ^asd means a String beginning With asd, The String asdfgh matches The pattern ^asd, And The String basdfg does Not Match The pattern ^asd.
$ indicates The End Of The String, For example, red $ means that All strings ending With red Match The pattern, And redo does Not Match The pattern red $.
. matches Any single Character, For example, ^&&$ matches Any String Of six characters.
[] matches The characters listed In The brackets, For example, ^[ABC]$ matches a String consisting Of one Character whose Value can only be a Or B Or C.
Together With The square brackets, specify a range Of matching characters, For example, ^[A-Z]$ matches only those strings consisting Of an uppercase letter. The ^ Character can also be used In The square brackets, which means To Match Any Character that Is Not In The specified range, For example, [^0-9] matches Any Character except numbers.
, +, ? These symbols follow a Character To indicate The Number Of times The Character can appear. an asterisk () means that it can appear 0 times Or Any Number Of times; a plus Sign (+) means multiple occurrences, but at least one occurrence; a question mark (?) means zero Or one occurrence. For example, a matches 0 Or more A (no a, a, AA, AAA, AAAA, **);
a+ matches 1 Or more A (a, AA, AAA, AAAA, **);
a? matches The empty String Or 1 a.
\ Slash () Is an escape Character, which removes The special meaning Of special characters, For example, The pattern \$ matches The Character $, And The pattern \ matches The Character .
(7), Mid
Function:
Take a substring Of a String.
Syntax:
Mid ( String, Start {, Length } )
parameter:
String: String Type, specifies the String From which To extract the substring
Start: Long Type, specifies the Position Of the First Character Of the substring In the String String, the First Position Is 1
Length: Long Type, optional, specifies the Length Of the substring
Return Value:
Return Value: String
When the Function Is executed successfully, it returns the substring starting From the Start Position And Having a Length Of Length In the String String.
If the Value Of the Start parameter Is greater than the Number Of characters In String, the Mid() Function returns an empty String.
If the Length parameter Is omitted Or the Value Of the Length parameter Is greater than the Length Of the remaining characters In the String starting From Start, the Mid() Function returns All the remaining characters.
If the Value Of Any parameter Is Null, the Mid() Function returns Null.
(8), Pos
Function:
Finds the Start Of a String contained within another String.
Syntax:
Pos ( string1, string2 {, Start } )
parameter:
string1: String Type, specify the String From which To Find the substring string2
string2: String Type, specify the String To be searched In string1
Start: Long Type, optional, specify the Number Of characters From string1 To Start searching.
the Default Value Is 1
Return Value:
Return Value: Long.
When the Function executes successfully, it returns the starting Position Where string2 appears For the First Time In string1 after the Start Position.
If string2 Is Not found In string1 according To the specified requirements, Or the Value Of Start exceeds the Length Of string1, Then the Pos() Function returns 0.
If the Value Of Any parameter Is Null, the Pos() Function returns Null.
Usage the Pos() Function Is case-sensitive In String lookups, therefore, "aa" does Not Match "AA".
(9), Replace
Function:
Replaces a specified Number Of strings In one String With another String.
Syntax:
Replace ( string1, Start, n, string2 )
parameter:
string1: String Type, specify the String To Replace part Of the content With string2
Start: Long Type, specify the Character Position To Start replacing the String, the Position Of the First Character In the String Is 1
n: Long Type, specifies how many characters To Replace
string2: String Type, specify which String Is used To Replace some characters Of string1
Return Value:
Return Value: String.
the replaced String Is returned when the Function executes successfully, And an empty String ("") Is returned when an Error occurs.
If the Value Of Any parameter Is Null, the Replace() Function returns Null.
usage:
If the Position specified By the Start parameter exceeds the Length Of string1, the Replace() Function will Return the String formed By splicing string2 To the End Of string1.
If the Value Of n Is 0, Then the Replace() Function returns the String formed By inserting string2 Into the specified Position Of string1.
(10), Right
Function:
Get the specified Number Of characters From the Right End Of the String.
Syntax:
Right ( String, n )
parameter:
String: String Type, specify the String To extract the substring
n: Long Type, specifies the Length Of the substring
Return Value:
Return Value: String.
When the Function executes successfully, it returns n characters To the Right Of the String String, And returns an empty String ("") When an Error occurs.
If the Value Of Any parameter Is Null, the Right() Function returns Null.
If the Value Of n Is greater than the Length Of the String String, Then the Right () Function returns the entire String String, but does Not add Other characters.
(11), Right Trim
Function:
Remove trailing spaces From a String
Syntax:
RightTrim ( String )
parameter:
String: String Type, specify the String To Delete the Right Space
Return Value:
Return Value: String.
When the Function executes successfully, it returns a String With the spaces at the Right Of the String removed, And When an Error occurs, it returns an empty String ("").
If
(12), Space
Function:
Generates a String consisting Of spaces With the specified Number Of characters
Syntax:
Space ( n )
parameter:
n: Long Type, specifies the Number Of spaces To be filled, that Is, the Length Of the returned String after filling
Return Value:
Return Value: String.
When the Function executes successfully, it returns a String consisting Of n spaces, And When an Error occurs, it returns an empty String.
If the Value Of the parameter n Is Null, the Space() Function returns Null
(13), Trim
Function:
Remove leading And trailing spaces From a String.
Syntax:
Trim ( String )
parameter:
String: String Type, specify the String To Delete the leading And trailing spaces
Return Value:
Return Value: String.
When the Function executes successfully, it returns a String With the spaces at the beginning And End Of the String removed, And returns an empty String ("") When an Error occurs.
If the Value Of Any parameter Is Null, the Trim() Function returns Null.
(14), Upper
Function:
Convert lowercase letters In a String To uppercase.
Syntax:
Upper( String )
parameter:
String: The String To Convert lowercase letters To uppercase letters
Return Value:
Return Value: String.
When The Function executes successfully, it returns The String converted From lowercase letters To uppercase letters, And returns an empty String ("") When an Error occurs.
If The Value Of The String parameter Is Null, The Upper() Function returns Null.
6. System and environment
(1), Clipboard
Function:
Extract Or Replace the Text content Of the Windows System Clipboard.
Syntax:
Clipboard ( { String } )
parameter:
String: String Type, optional, specifies the Text To be copied To the System Clipboard.
This Text will Replace the current contents Of the Clipboard, If Any
Return Value:
Return Value: String.
When the Function Is executed successfully, If the Clipboard contains Text Data, the Function returns the current content Of the Clipboard;
If the Clipboard contains non-text Data (such as a bitmap) Or contains no Data, the Function returns an empty String ("").
If the Value Of the String parameter Is Null, the Clipboard() Function returns Null.
Usage Regardless Of whether the String parameter Is specified, Clipboard() will Return the current contents Of the Clipboard.
When the String parameter Is specified, the original content Of the Clipboard Is replaced By the Value Of the String parameter;
When the String parameter Is omitted, only the content Of the Clipboard Is obtained.
(2), CommandParm
Function:
Get the command parameters specified when the Application was Run.
Syntax:
CommandParm( )
Return Value:
Return Value: String.
when the Function executes successfully, it returns the command Line parameters when the Application Is Running. when the Function executes incorrectly Or there are no command Line parameters, the Function returns an empty String ("").
usage:
command Line arguments are Any arguments that follow the Application Name when the Application starts
For example, enter the following command In the Run window:
MyAppl C:\EMPLOYEE\EMPLIST.TXT
Then the command Line parameters obtained By Using the CommandParm() Function In the MyAppl Application are:
C:\EMPLOYEE\EMPLIST.TXT
when an Application's command line contains several parameters, the CommandParm() function returns all parameters as a string. The parameters can be separated using the string manipulation functions.
it Is Not necessary To Execute the CommandParm() Function In the Open Event Of the Application Object.
At This point, the Argument parameter Of the Open Event contains the command Line parameters.
(3), DoScript
Function:
Execute the AppleScript program segment, this function is only valid on the Macintosh platform.
Syntax:
DoScript ( script, result )
parameter:
script: string type, specify the program segment to be run (script)
result: string type, the result information Or error information returned By the AppleScript program segment
return value:
Return value: Integer.
Returns the result code returned By AppleScript.
If the value of any parameter is Null, the DoScript() function returns Null.
(4), GetApplication
Function:
Get the Handle Of the current Application Object, so you can query Or Set the properties Of the Application Object (usually used To Write common code).
Syntax:
GetApplication ( )
Return Value:
Return Value: Application.
Returns the Handle Of the current Application Object
(5), GetEnvironment
Function:
Get information related To the System, such as the operating System, processor, And screen display.
Syntax:
GetEnvironment( environmentinfo )
parameter:
environmentinfo: Environment Object Name, used To Save System Environment information
Return Value:
Return Value: Integer.
the Function returns 1 On success And -1 On Error.
If the Value Of the parameter environmentinfo Is Null, the GetEnvironment() Function returns Null.
Usage When developing a cross-platform project, Using the GetEnvironment() Function, the Application can obtain information such as the currently Running operating System, the Type Of CPU used, the version Of the operating System, the size Of the screen, And the Number Of colors
For the specific representation Of these information, please refer To the introduction Of the Environment Object (Environment Object) In This book.
(6), GetFocus
Function:
Determines which Control the current focus Is On.
Syntax:
GetFocus ( )
Return Value:
Return Value: GraphicObject.
When the Function executes successfully, it returns the reference Of the currently focused Control, And When an Error occurs, it returns an invalid reference.
Usage the Application uses the IsValid() Function To detect whether GetFocus() returns a valid Control reference.
At the same Time, use the TypeOf() Function To determine the Type Of the Control.
(7), Post
Function:
Add the specified Message To the Message queue Of a certain window. This window can be either a PowerBuilder Application window Or a window Of Other applications.
Syntax:
Post( Handle, messageno, word, Long )
parameter:
Handle: Long Type, the System Handle Of the specified window, And the Message will be mailed To the window
messageno: UnsignedInteger Type, specify the Message Number To be mailed
word: Long Type, specifying the parameter Value Of the word Class mailed together With the Message. If the Message specified By the messageno parameter does Not use This parameter, Then
Then Set the Value Of This parameter To 0
Long: Long Type Or String, specifies the Long Type parameter Value Or String To be mailed together With the Message
Return Value:
Return Value: Boolean.
If the Value Of Any parameter Is Null, the Post() Function returns Null.
usage:
the Post() Function Is used To Send a Message Of a non-PowerBuilder predefined Event To the window. This window can be a PowerBuilder Application window Or a window Of Other applications.
the Post() Function puts the sent Message at the End Of the Message queue Of the specified window, And Then returns To the Application program. It does Not wait For the execution Of the corresponding Event handler.
This Is different From the Send() Function. the Send() Function directly triggers the corresponding Event Of the specified window, And returns To the calling Application after executing the Event handler.
Therefore, we say that the Post() Function uses an asynchronous method, And the Send() Function uses a synchronous method.
the parameter Handle Of the Post() Function specifies the window Handle To receive the Message. For the PowerBuilder window, use the Handle() Function To get the Handle.
For the windows Of Other applications, you can Call the System API Function To Find the window And get the Handle Of the corresponding window.
If the Application Is To Post PowerBuilder-defined events (including predefined events And user-defined events), Then Using the PostEvent() Function Is simple And convenient.
When the Application specifies a String In the Long parameter Position, the Post() Function copies a Copy Of the String, And Then transfers the Address Of the Copy To the specified window.
(8), ProfileInt
Function:
Reads Integer setting Values From an initialization file (.ini).
Syntax:
ProfileInt ( Filename, section, Key, Default )
parameter:
Filename: String Type, specifies the Name Of the initialization file, which can include a path. When the path Is omitted, the Function searches For the specified file according To the standard path Of the operating System
section: String Type, specify the section Where the Value To be obtained Is located (section)
Key: String Type, specify the Name Of the Value To be obtained, Not case-sensitive
Default: Integer Type, When the specified file, section Name, Or project Name does Not exist Or cannot be converted To an Integer, the Function returns the Value specified By This parameter Value
Return Value:
Return Value: Integer.
When the Function Is executed successfully, If there Is no Error In the specified file, section Name, And project Name, the Function returns the Value Of the corresponding Item;
If the specified file, section Name, And project Name Do Not exist Or cannot be converted Into integers, the Function returns returns the Default Value specified By the Default parameter. If an Error occurs, the Function returns -1. If the Value Of Any parameter Is Null, the ProfileInt() Function returns Null.
(9), ProfileString
Function:
Read String Type setting Value From initialization file (.ini)
Syntax:
ProfileString ( Filename, section, Key, Default )
parameter:
Filename: String Type, specifies the Name Of the initialization file, which can include a path. When the path Is omitted, the Function searches For the specified file according To the standard path Of the operating System
section: String Type, specify the section Where the Value To be obtained Is located (section)
Key: String Type, specify the Name Of the Value To be obtained, Not case-sensitive
Default: String Type, When the specified file, section Name, project Name does Not exist, the Function returns the Value specified By This parameter
Return Value:
the Return Value Is String.
When the Function Is successfully executed, If there Is no Error In the specified file, section Name, And project Name, the Function returns the Value Of the corresponding Item;
If the specified file, section Name, And project Name Do Not exist, the Function returns the Default Value specified By the Default parameter. Provincial Value.
If an Error occurs, the Function returns an empty String. If the Value Of Any parameter Is Null, the ProfileString() Function returns Null.
(10), Restart
Function:
Stops the execution Of All program segments, closes All windows, commits the Transaction, disconnects From the Database, And restarts the Application
Syntax:
Restart()
Return Value:
the Return Value Is Integer.
the Function returns 1 On success And -1 On Error.
(11), Run
Function:
Run the specified Application
Syntax:
Run ( String {, WindowState } )
parameter:
String: String Type, specify the Name Of the Application To Run, which can include the path And corresponding parameters, just Like In the command Line as typed
WindowState: WindowState Enumeration Type, optional, specifies the window State when the program Is Running.
Valid Values are: Maximized! - Maximized window;
Minimized! - Minimized window;
Normal! - Default, Normal window
Return Value:
the Return Value Is Integer.
the Function returns 1 On success And -1 On Error.
If the Value Of Any parameter Is Null, the Run() Function returns Null.
Usage Using the Run() Function, an Application can Start Any program In the operating System.
when the parameter To Start the Application program Is specified In the Run() parameter, the meaning, Format, Number, etc. Of the parameter are determined By the specific Application program. If the file Name Is specified In the String parameter Of the Run() Function but no extension Is given, PowerBuilder considers the file extension To be .EXE.
To Run an Application With an extension Other than .EXE (such as .BAT, .COM, Or .PIF), the file extension must be specified as an Argument To the Run() Function.
(12), Send
Function:
Send the specified Message To the window And immediately Execute the corresponding Event handler
Syntax:
Send( Handle, messageno, word, Long )
parameter:
Handle: Long Type, the System Handle Of the specified window, To which a Message will be sent
messageno: UnsignedInteger Type, specifies the Message Number To be sent
word: Long Type, specifying the parameter Value Of the word Class sent With the Message. If the Message specified By the messageno parameter does Not use This parameter, Then
Then Set the Value Of This parameter To 0
Long: Long Type Or String, specifies the Long Type parameter Value Or String sent With the Message
Return Value:
Return Value: Long.
When the Function executes successfully, it returns the Return Value Of the Windows System Call SendMessage(), And returns -1 When an Error occurs.
If the Value Of Any parameter Is Null, the Send() Function returns Null.
usage
the Send() Function Is used To Send messages Of non-PowerBuilder predefined events To the window. This window can be the window Of PowerBuilder Application Or the window Of Other applications.
the Send() Function directly triggers the corresponding Event Of the specified window, And returns To the calling Application after executing the Event handler. This Is different From the Post() Function. the Post() Function puts the sent Message at the End Of the Message queue Of the specified window, And Then Back In the Application, it does Not wait For the execution Of the Event handler For the corresponding Event.
Therefore, we say that the Post() Function uses an asynchronous method, And the Send() Function uses a synchronous method.
the parameter Handle Of the Send() Function specifies the window Handle To receive the Message. For the PowerBuilder window, the Handle can be obtained By Using the Handle() Function.
For the Windows Of Other applications, you can Call the System API Function To Find the window And get the Handle Of the corresponding window.
In Fact, the Send() Function sends its parameters directly To the Windows System Call SendMessage().
Each Message Number can be found In the Windows.H file Of various C++ development tools.
If the Application program wants To Send PowerBuilder-defined events (including predefined events And user-defined events), Then Using the TriggerEvent() Function Is simple And convenient.
When the Application specifies a String In the Long parameter Position, the Send() Function copies a Copy Of the String, And Then transfers the Address Of the Copy To the specified window.
(13), SetProfileString
Function:
Sets the Value Of the specified Item In the initialization file
Syntax:
SetProfileString ( Filename, section, Key, Value )
parameter:
Filename: String Type, specifies the Name Of the initialization file, which can include a path. When the path Is omitted, the Function searches For the specified file according To the standard path Of the operating System
section: String Type, specify the section Where the Value To be Set Is located (section)
Key: String Type, specify the Name Of the Value To be Set, Not case-sensitive
Default: String Type, specify the Value Of the Item To be Set
Return Value:
Return Value: Integer.
the Function returns 1 When the Function executes successfully, And returns -1 When the specified file Is Not found Or the specified file cannot be accessed.
If the Value Of Any parameter Is Null, the SetProfileString() Function returns Null.
(14), ShowHelp
Function:
Displays the Application help, which operates Using the Microsoft Windows help System
Syntax:
ShowHelp ( helpfile, helpcommand {, typeid } )
parameter:
helpfile: String Type, specify the Name Of the help file
helpcommand: helpcommand Enumeration Type, specifying the Format For displaying help. Valid Values are: Index! - Displays the directory Subject, Do Not specify when Using This Value typeid parameter;
Keyword! - transfer To the topic identified By the specified Keyword;
topic! - Display help For the specified topic
typeid: optional, specify the help topic
Return Value:
Return Value: Integer.
the Function returns 1 On success And -1 On Error.
If the Value Of Any parameter Is Null, the ShowHelp() Function returns Null.
(15), SignalError
Function:
Trigger the SystemError Event Of the Application Object, usually used For code debugging.
Syntax:
SignalError ( { Number }, { Text } )
parameter:
Number: Integer Type, optional, its Value will be saved In the Number property Of the Error Object
Text: String Type, optional, its Value will be saved In the Text property Of the Error Object
Return Value:
.
Return Value: Integer.
the Function returns 1 On success And -1 On Error.
(16), Yield
Function:
Function transfers Control To Other graphical objects, including non-PowerBuilder objects. This Function detects the Message queue, And If there Is a Message, it will take out the Message. Use This Function To transfer Control To Other applications While performing lengthy operations.
Syntax:
Yield()
Return Value:
Return Value: Boolean.
If the Message was fetched From the Message queue, the Function returns True, otherwise it returns False.
usage
Under normal circumstances, a PowerBuilder Application does Not respond To user actions during the execution Of a piece Of code (such as a Function Or Event handler).
there Is nothing wrong With This approach For short-lived code segments
However, If the execution Of a certain code segment takes a Long Time And the Application wants To provide more Control To the user, it Is necessary To Insert the Yield() Function In This code To allow the user To perform Other operations, especially In the Loop Even more so In executed code.
After the Application program executes the Yield() Function, If it finds that there are messages In the Message queue, it will allow the Object To process these messages, And After processing, Continue the execution Of the code behind the Yield() Function.
Therefore, inserting the Yield() Function In the code will reduce the operating efficiency Of the Application
PowerBuilder Manual Book Part 5Â ClickHere
Good Luck!