Showing posts with label powerscript. Show all posts
Showing posts with label powerscript. Show all posts

Maximum characters to be used while naming a powerbuilder object

While naming an object in Powerbuilder, the maximum length is 40. Which means if I name datawindow object as d_composite_reporting_yearly_sales_figures, this is invalid and will throw error during runtime. Counting the underscores and characters in the name, they are 42.

For demonstration, lets create a datawindow and name it as d_composite_reporting_yearly_sales_figures. The datawindow will be saved with name and display in the treeview.





Now right click on the object and Select Export.



Observe the name has been trimmed.If datawindow is used in powerscript, check the dataobject name in debug mode.

The 40 character length applies to all objects like window, user objects, structures etc.



Play Windows Error sound in Powerbuilder application

To implement windows sound in a Powerbuilder application, we have to refer winmm.dll in PB application. Below is a test script for it.

//Declare as Global External Function
Function Boolean sndPlaySound(ref String lpszSound , Long fuSound )&
                                                Library "Winmm.dll" alias for "sndPlaySoundW"


//Write the script where we need to play sound
string ls_path1
ls_path1= "C:\Windows\Media\tada.wav"

Constant Long SND_SYNC = 0

sndPlaySound(ls_path2 , SND_SYNC)

Modify DataSource at runtime

I have a situation where I need to filter the data retrieved based on retrieval argument and then display all rows available in the database. To retrieve all rows, I have to remove the where clause in the datasource of the datawindow. This is how I got through the situation

string ls_sql, ls_dw_syntax, ls_find
String  ls_replace, ERRORS, presentation_str, dwsyntax_str//Create datawindow
string rc, mod_string//To modify the sql
long ll_pos

ls_dw_syntax = dw_1.Describe("Datawindow.Table.Select")//Get the sql from datasource
ls_find = "WHERE"//Find the position of where keyword in sql
ll_pos = POS(ls_dw_syntax, ls_find)
IF ll_pos    > 0 THEN
    ls_replace    =     Replace ( ls_dw_syntax, ll_pos, 999, "" )//remove string from Where
END IF

//Create datawindow without where clause
presentation_str      = "style(type=grid)"
dwsyntax_str         = SQLCA.SyntaxFromSQL(ls_replace, presentation_str, ERRORS)
IF Len(ERRORS) > 0 THEN
    MessageBox("Caution", "SyntaxFromSQL caused these errors: " + ERRORS)
   RETURN
END IF
dw_1.Create( dwsyntax_str, ERRORS)
IF Len(ERRORS) > 0 THEN//Test if creation of datawindow is successful
   MessageBox("Caution", "Create cause these errors: " + ERRORS)
   RETURN
END IF

dw_1.settrans( SQLCA)
dw_1.Retrieve( )

Copying data between datawindow controls


The task we need to do is to copy data from datawindow 1 to datawindow 2. This can be achieved by object property. But if there are many columns in a row, using object property for that would be time consuming and tedious task.

To accomplish the task with ease, no matter how many columns we have, there is a dedicated datawindow control function name RowsCopy().

In the button clicked event, type the syntax:
dw_1.RowsCopy(dw_1.GetRow(), &
dw_1.RowCount(), Primary!, dw_2, 1, Primary!)

Thats it. Now fill up the data in datawindow 1 and once you are done, click on the button-copy from dw_1 to dw_2.  

PS-: To learn more about RowsCopy() function, goto powerbuilder help.