Pages

Showing posts with label Tips. Show all posts
Showing posts with label Tips. Show all posts

Thursday, April 28, 2011

Create Object Programmatically with Powerbuilder - Part 1

In Powerbuilder, we can create an object programmatically, means that you can create whenever you need or conditionally.

In this first part, I trying to explain how to create "static" picture object when user clicking the button. Static mean that we only create the object, without script associated inside the object. The function that will be used it's called: openuserobject

For detail explanation of openuserobject function, please see the official help of Powerbuilder. 

First, create a button, and type this follow script inside Clicked event.
picture p_2  // declare the picture variable
p_2 = create picture  // create the picture object

p_2.x = 100  // x position of the object
p_2.y = 100  // y position of the object
p_2.height = 250 // height value of the object
p_2.width = 250 // with value of the object
p_2.picturename = "redalert.bmp" // name of the picture inc full path

parent.openuserobject( p_2, "p_2", 100, 100) // ok, let's create the object


»»  READMORE...

Wednesday, April 27, 2011

Click and Drag with Powerbuilder

This article will show you how to make an object to be click and drag capable in Powerbuilder. In this case, I'm using Powerbuilder 9.0 and Picture Object. In this version, I found DragAuto property in the list of the picture property, one that I can't found in version 6.5. I'm not sure, since when Sybase added this property.

The Drag Auto property determines whether PowerBuilder puts the control into drag mode automatically. If the property is enabled, when the user clicks the control and starts dragging it, PowerBuilder puts the control in drag mode. Clicking the control triggers a DragDrop event, not a Clicked event.

If Drag Auto is not enabled, then when the user clicks the control, PowerBuilder does not put the control in drag mode. You have to call the Drag function to put the control into drag mode.

In the Window, put 1 Picture object, and set the name of the file, and turn on the DragAuto option, in other tabs of property, and named it as p_1


Add the following script in p_1's clicked event
this.Drag(begin!)

At the p_1's dragleave event, put this following script:
this.x = parent.pointerx( ) - (this.width / 2)
this.y = parent.pointery( ) - (this.height / 2)
parent.setredraw(true)
this.setredraw(true)

And finally, at p_1's dragdrop event, add this following script:
parent.setredraw(true)
this.setredraw(true)
this.Drag(end!)
»»  READMORE...

Thursday, February 10, 2011

Printing shrink in IE7 and IE8

Some of my users facing the font shrink-ed when they tried to print the web page with Internet Explorer (IE) version 7 or 8.

To solve this case, if you are using version 8, make sure the option Shrink to Fit option in Page Setup menu, in your IE, is unchecked.

If you are using Internet Explorer version 7, you need to add the Registry Key by doing the steps below:
On the command prompt, type the following statement:

reg add "HKLM\SOFTWARE\Microsoft\Internet Explorer\MAIN\FeatureControl\FEATURE_STF_Scale_Min" /v iexplorer.exe /t REG_DWORD /d 100 /f

Click OK to confirm when warning window is showed.

Or, download this file, unzip the file, then run the file inside.
»»  READMORE...

Friday, January 7, 2011

AVG 2011 Offline Full Installation Download

As the default, when you want to download the AVG 2011 free version, you only download the basic installation file, then you must have the internet connection to continue to finish the installation.

Some times you have another computers (PC / Notebook), which have no internet connection. How to install the AVG 2011 antivirus to the offline computers ?

Just download the offline full installation file from http://free.avg.com/in-en/download.prd-afh, then install it into each offline computers. The installation is for Windows XP, Vista, and Windows 7, both for 32 or 64 bits. And also you can find the newest updates of AVG 2011 in the link.
»»  READMORE...

Friday, December 10, 2010

Set Local Computer Time with Powerbuilder

With External Function feature, we can set the Local Computer's time with Powerbuilder.

First, we need to declare the external function, called SetLocalTime from kernel32.dll

FUNCTION long SetLocalTime(ref str_SYSTEMTIME lpSystemTime ) LIBRARY "kernel32.dll" alias for "SetLocalTimeA"

To use the function, just pass a datetime variable when you call the function.

Example:

DataTime dtToday
dtToday = DateTime(Today(),Now())
SetLocalTime(dtToday)

»»  READMORE...

Wednesday, December 1, 2010

Integer versus Long Data Type in Powerbuilder

When you have an INTEGER column type in a table on your database, you must be aware to script in Powerscript.

The Integer data type in Powerbuilder just have the 16-bit signed characteristic, which mean only can store the integer number between -32768 to +32767. It's totally different with the Integer data type in your SQL database engine. I'm talking about Ms. SQL Server 2000/2005 in this case.

Make sure always using LONG data type in your variable, instead of INTEGER, to prevent the value outside -32768 or +32767.

For example, if the value of the column in your database is 34000, you'll get an error if you store the value into the integer variable on your script.
»»  READMORE...

Monday, November 1, 2010

Powerbuilder Window Function

On my last post about Powerbuilder function, I have mention that there are 2 types of function in Powerbuilder. Now, I will try to explain another function called Window Function.

The main different between Window Function and function, is Window Function must be declared in Window Object, and it should be related with windows object inside.

The way to declare the Window function is almost the same when you declare the function. But for the first step, you need to open your window first, where you want to put the window function inside. Click Declare at drop down menu, then select Windows Functions sub menu.



Specify the name of the function, the arguments, the return value and specify where the function can be used: Public (in any script in the application), Private (only in scripts for events in the object in which the function is defined), or Protected (only in scripts for the object in which the function is defined and its descendants).


Type the script, then save and name wf_datechecked. The script will compare the 2 variables (one is the argument, one is the today's date)

// sample window function, named wf_datechecked
// argument or parameter is dtDateTransaction
// will return TRUE if comparation between dtDateTransaction is smaller than dtToday
// will return FALSE if comparation between dtDateTransaction is bigger or equal than dtToday


DateTime dtToday

dtToday = DateTime(Today(),Now())

If dtDateTransaction >= dtToday THEN
   RETURN FALSE
ELSE
   RETURN TRUE
END IF


To call the function, type script below (on Clicked event of b_checked, for example)
Assumed that you have datawindow called dw_1, and has column inside name dateofbirth.

Boolean bValidDate

bValidDate = wf_datechecked(dw_1.GetItemDateTime(row,"dateofbirth"))

IF bValidDate THEN
   Messagebox("Information","The Date is valid")
ELSE
   Messagebox("Information!","The Date is invalid. You must input the date smaller than today")
END IF
»»  READMORE...

Thursday, October 28, 2010

Powerbuilder Function

In every modern programming languages, there is a feature call FUNCTION, as well as Powerbuilder.

FUNCTION is a collection of scripts or statment which it can be re-used. Normally, FUNCTION has a return value.

In Powerbuilder, there are 2 types of FUNCTION: Function and Window Function. The different is FUNCTION can be use anywhere in object that has capabilities to call function, but Window Function just can called in the window itself.

In this article, I will show you the steps how to declare the function in Powerbuilder. I'm using Powerbuilder version 6.5 and I'm sure it will be the same for all versions above

In the main toolbar, click Function painter.


Click New to create a new Function


Type the name of the function, in the example: f_yearafter
Also specify the type of return variable, in this example: date
Function can has many parameters. Parameters can used to passing some value(s) into function, so later can be used to process or calculate something in the script of function. Beside the name of parameters, you must specify the type of parameters, and the Pass By. There are 3 types of Pass by: value, reference, and readonly. Use reference if you want to change the value parameter then inside the function script.
Click OK to create.


Now you can type the script inside the.
In this example, we create a function call f_yearafter. The function will return a date type value, which it is the date result after some year added.

Once the function created, you can't change or rename the function name, but you can still change the return value, the parameter, etc. Please pay the attention, changing all of that value, will affect into the script inside the function. You can click the function painter icon in the toolbar, to edit the function



To call the function, just add the script like this:

Date dReturnFunction

//add 2 years for the date
dReturnFunction = f_yearafter("01/01/2008",2) // will return "01/01/2010"

»»  READMORE...

Saturday, October 23, 2010

How to create Sparkline GraphMicrosoft Excel 2010

One new feature in Microsoft Office Excel 2010 is Sparklines. 
 
Sparklines is a graph display of the collection of data in Microsoft Office Excel, but displayed only in one cell. 
 
There are 3 types Sparklines: Line, Column and Win / Loss. 
 
To make it, you are required to have a set of data, just as if you want to create an other graph. Click on the Insert ribbon menu, and select the desired type sparkline. And as usual, you are prompted to set the data that you show with this sparkline graph, and finally determine the cell where you want to display these sparkline.
 

Especially for type Win / Loss, sparkline this type is used if you have a set of data in which there is a negative number. 
 
And as usual, you sparkline graph can be modified in appearance, ranging from about the color until the value to be displayed.
 
 
»»  READMORE...

Wednesday, October 20, 2010

Powerbuilder Pipeline

Another feature in Powerbuilder programming is Pipeline.
According to manual help of Powerbuilder, a Pipeline system object is used to manage a data pipeline during execution.

You use a Pipeline object by defining a standard class user object inherited from the built-in Pipeline object in the User Object painter. You can then access the Pipeline events by writing scripts that contain code for the events.

Now I will show you how to execute pipeline by writing the script.

The scenario of this case is you want to pipeline a table from one database to another database. So, first you need at least 2 transaction objects, which mean we must declare first in the top of the script. Since we have a default database connection SQLCA, we only have declare another new transaction object called SQLCAtarget, which represent for the target database connection. Remember, in this case, SQLCA will be the source of database connection

transaction SQLCAtarget // declare this variable as INSTANT variable

SQLCA.DBMS = 'your source dbms name'
SQLCA.Database = 'your source database name'
SQLCA.LogId = 'your source database login id'
SQLCA.LogPass = 'your source database password'
SQLCA.ServerName = 'your source database server'
CONNECT USING SQLCA;

SQLCAtarget = CREATE transaction
SQLCAtarget.DBMS = 'your target dbms name'
SQLCAtarget.Database = 'your target database login id'
SQLCAtarget.LogPass = 'your target database password'
SQLCAtarget.ServerName = 'your target database server'
SQLCAtarget.LogId = 'your target database login id'
CONNECT USING SQLCAtarget;

Next step, you need to build pipeline object by clicking Pipeline painter in main toolbar. Remember, use MAIN TOOLBAR, if you want to pipeline the data to ANOTHER DATABASE.
Setup your source database and the target database profile, chooce the table(s), column(s) and criteria(s), then save as pl_mypipeline.



Choose source and target of Pipeline

Set the table, column and criteria of your pipeline


save your pipeline


Create a window, then put 1 datawindow object and 1 button object. You don't need to put dataobject for the datawindow, just keep it blank. And put the script below at clicked event in button object.

integer iReturn
pipeline myPipeline
myPipeline = CREATE pipeline

myPipeline.DataObject = "pl_mypipeline"
iReturn = myPipeline.Start(SQLCA, SQLCAtarget, dw_1)

// always disconnect your database connection
DISCONNECT USING SQLCA;
DISCONNECT USING SQLCAtarget;

iReturn should be has 0 (zero) value if the pipeline run smoothly.
»»  READMORE...

Friday, October 15, 2010

How to activate Microsoft Office Trial Version which bundled with Toshiba Notebook

When you buy a new Toshiba notebook, usually you will be given within Microsoft Office applications. By default, the application can only run for 60 days since it was first used, and even then you have to do the activation online, if not you can only use as much as 25 times.

How do I activate Microsoft Office applications are to be used for 60 days for free?


First of all, you need an internet connection, because this activation process requires an Internet connection directly into Microsoft's network of sites.


After you ensure that your notebook is connected to the Internet, you must run the registration application is Microsoft office, by clicking the icon on the desktop of your notebook. Follow all these steps, and at the end of the process, you will be informed 25 number keys for subsequent activation process. Keep these numbers carefully.


Finally you will be prompted to enter a 25 digit keys to activate the Microsoft Office
»»  READMORE...

Wednesday, October 13, 2010

Modify Compute Field Expression in Powerbuilder

Compute Field is an object in Powerbuilder programming, which can be inserted in datawindow. One of mandatory property of Compute Field is Expression.

Expression is set of statement or syntax which represent what you want to show at this compute field. Can be static text, calculation, or the other things.

When you create a datawindow and insert a compute field object, you can set the expression visually. But some times, you want to change the expression statement dynamically, which mean the expression will change depending of condition. Let say, if one of condition is fulfilled, you want to show: OK in the compute field, otherwise is NO.

Let say, in a Datawindow named dw_1, we create 1 compute object named co_1. The default expression is if(kd_kategori=2,'OK','NO'). It's mean if kd_kategori's value is 2, then we want to show text: OK, otherwise is: NO.




But, in some condition you want to change the default expression into if(kd_kategori=200,'OK','NO'), let say if someone in STAFF level is accessing the application.



Then you must create a script like below:

IF userlevel='STAFF' THEN
   dw_1.object.co_1.expression = "if(kd_kategori=200,'OK','NO')"
ELSE
   dw_1.object.co_1.expression = "if(kd_kategori=2,'OK','NO')"
END IF
»»  READMORE...

Wednesday, October 6, 2010

How to program Right Click Event in Powerbuilder

As we know at least there are 2 buttons in every mouse that you use with your computer. Known as Left and Right button.

For right-handed user, Left Button is for SELECT purpose. And Right button usually is for displaying the Popup Menu to shortcut the steps.

Now, I am trying to explain how to script Right button to show the Popup Menu in Powerbuilder.

In almost objects in Powerbuilder, there is an event called RBUTTONDOWN. In this case I will use with Windows object.

First, you need to create Menu object with 3 choices, then save as m_rightpopup.




Create new window and save as w_main, and put this script at RBUTTONDOWN event.

m_rightpopup popMenu
popMenu = CREATE m_rightpopup
popMenu.PopMenu(w_main.PointerX(), w_main.PointerY())

The script above, will shown a Popup Menu when you try to click the right button of your mouse, located exactly at your mouse pointer

»»  READMORE...

Saturday, August 28, 2010

Windows Registry Modification

Here are some Windows registries that you can do the modification to get a powerful Windows, specially for Security matters.

All you have to do first, it's DO THE BACKUP !!! Run the regedit.exe and click File menu then EXPORT.
And please remember before you do some modifications, do it with your own risk !

Disable / Enable Windows Wallpaper changing
To prevent other users to change the wallpaper, change the Data value to 0 to Enabled or 1 to Disable at
HKEY_CURRENT_USER,Software\Microsoft\Windows\CurrentVersion\Policies\ActiveDesktop
Value Name : NoChangingWallpaper
Data Type : DWORD Value

Show / Hide Folder Option at Windows Explorer
Note: Some computer viruses cause Folder Option menu at Windows Explorer disabled.
HKEY_CURRENT_USER,Software\Microsoft\Windows\CurrentVersion\Policies\Explorer
Value Name : NoFolderOptions
Data Type : DWORD Value
Data : 0 = show, 1 = hide

Show / Hide File menu at Windows Explorer
HKEY_CURRENT_USER,Software\Microsoft\Windows\CurrentVersion\Policies\Explorer
Value Name : NoFileMenu
Data type : DWORD Value
Data : 0 = show, 1 = hide

Remove arrow image at Shortcut icon
HKEY_CLASSES_ROOT\piffile
Value Name : IsShortcut
Data Type : String Value
Delete the value

Show / Hide Taskbar and Start Menu
You can use this if you want to make a kiosk PC or something like that.
HKEY_CURRENT_USER,Software\Microsoft\Windows\CurrentVersion\Policies\Explorer
Value Name : NoSetTaskbar
Data Type : DWORD Value
Data : 0 = show, 1 = hide

Show / Hide Shutdown Menu
HKEY_CURRENT_USER,Software\Microsoft\Windows\CurrentVersion\Policies\Explorer
ValueName : NoClose
Data Type : DWORD Value
Data : 0 = show, 1 = hide

Disable / Enable Right Click at desktop
HKEY_CURRENT_USER,Software\Microsoft\Windows\CurrentVersion\Policies\Explorer
Value Name : NoViewContextMenu
Data Type : DWORD Value
Data : 0 = Enable, 1 = disable
»»  READMORE...

Tuesday, August 24, 2010

Turn off the autorun of removable drive

Flash Drive, USB Drive, External Hard drive an Memory Card are an easy target for computer viruses entry into the computer system in the PC / notebook of us.

The present computer viruses can infect our system just when you plug the external devices. All could be happen because in the Windows Operating System, there is a technology call Autorun, which make possible to computer or system to run all the applications inside the external disk, automatically.


The preventive ways are: you installing the anti virus application and the security application on your PC or Notebook, and always do update the newest updated files as often as you can, and do the virus checking every time you plug the external devices. And also, play safely with your external devices, by not plug into any other unknown computers. But, like I mention above, that virus can infect our system just when you plug you external device, not even you have a chance to scan the device. How to solve that?


You can do turn off the autorun system by doing modification of your computer policy. Here's the step:
  1. On Start Menu, chooce Run and type gpedit.msc
  2. There are 2 sides (left and right) panels.
  3. On Left panel, pointing to tree view menu of Local Computer Policy, Computer Configuration, Administrative Template, System
  4. Then, on the right panel, find and right click Turn Off Autoplay and click Properties menu
  5. You can set to enable or disable the the Autorun, and even you can select for selected device to turn off.
  6. Click OK to finish.
  7. Restart your computer


This tips can be done for starting Windows 2000 until Windows 7 version.
»»  READMORE...

Monday, August 23, 2010

Twitter with Powerbuilder

Inspired from this article, I trying to made a simple script to post to Twitter from Powerbuilder. All you need is msxml2.dll which located at c:\windows\system32.

And also, you need to create a Twitter's account. Using an OleObject object, try this simple script:

Integer i
OleObject oleTwitter

OleTwitter = CREATE OLEObject
i = oleTwitter.ConnectToNewObject("Msxml2.XMLHTTP")
if i = 0 then
   oleTwitter.Open("POST", "http://youraccount:yourpassword@twitter.com/statuses/update.xml?status=Just for #..., Twitt from Powerbuilder", False)
   oleTwitter.setRequestHeader("Content-Type", "text/xml")
   oleTwitter.Send()
else
   MessageBox("Error","Cannot connect to Object"
end if

Please beware, I don't give a guarantee for any security matters that will caused for your Twitter's account, since I don't have any deep experiences using the XML.

And this is the result:

»»  READMORE...

Saturday, August 21, 2010

How to fix Facebook for Blackberry notification

Blackberry just releases the new version of Facebook for Blackberry. The new version is 1.80.49. You can download via Blackberry Application World.

Some of my friends facing that after they downloaded the new version, they didn't receive the online notifications.

Here is the step that may help you if you are facing the same problem above:

  1. Make sure your facebook email account is registered with Blackberry push email in your blackberry device
  2. Make sure your facebook email notification is not blocked by your email provider, make sure not in Spam list.
  3. Remove your facebook for blackberry application from your device, then restart the device with pull out the battery
  4. Re install facebook for blackberry application into your device with Blackberry App World or via www.blackberry.com/facebook Restart the device by pull out the battery
  5. Log on to your facebook account via PC, make sure turn on all the check list notifications at Option setting
  6. Make sure to always do LOG OUT everytime you log on into your facebook account at the PC
  7. Open your facebook for blackberry application, and do the Log on Wizard by open the Option menu.
Now, you should receive the notification(s) at your device.
»»  READMORE...

Friday, August 20, 2010

Creating Outlook Calendar Appointment with Powerbuilder

Microsoft Outlook is a popular Personal Information Management application. It is part of Microsoft Office package, which many users use it. Fortunately, Microsoft, as the maker Microsoft Outlook, has prepared the SDK to allows programmers to create their own applications that can interact seamlessly into the application Microsoft Outlook

One of the Outlook's feature is Calendar which it make possible to user to create their own schedule and will remind for it. It's very useful for people who has many schedules in their life.

In this part of session, I will try to explain how to insert or create a new appointment in outlook, programmatically, with Powerbuilder. One thing you should learn and know is Outlook Object Model, which you can find at Microsoft's MSDN site


Microsoft has prepared the AppointmentItem Class which has many properties, to create a new Appointment Object in Microsoft Outlook Calendar. Some properties that are commonly used for the calendar class are: Subject, Start, Duration, and Reminder.


First, you (or PC clients) must has Microsoft Outlook installed. Then at the script, you must declare OleObject variable type, than try to create the object and connect to Microsoft Outlook Object. In this example, I'm using Microsoft Outlook 2007 and Powerbuilder 6.5. Here's the full script to create a new Appointment Object:


// declare OleObject variable and Constant Variable
oleobject oleOutlook
oleobject oleAppt
Constant Integer olAppointmentItem = 1

// create the Object
oleOutlook = create oleobject

// Connect To the Outlook Object
oleOutlook.ConnectToNewObject ('Outlook.Application')

// Create the Appointment Object
oleAppt = oleOutlook.CreateItem (olAppointmentItem)

// Set some common properties of Appointment Object
oleAppt.Location = "Home"
oleAppt.Subject = "Watch Fulham vs Manchester United Live"
oleAppt.Start = "08/21/2010 19:00"
oleAppt.ReminderMinutesBeforeStart = 1  // in minute
oleAppt.Duration = 120 // in minute
oleAppt.Body = "Go MU !!! Go !!!"

// Save the Appointment
oleAppt.Save



And here the result of the example:









»»  READMORE...

Thursday, August 19, 2010

Microsoft Agent programming with Powerbuilder

According of wikipedia site, Microsoft Agent is a technology developed by Microsoft which employs animated characters, text-to-speech engines, and speech recognition software to enhance interaction with computer users. Thus it is an example of an embodied agent. It comes preinstalled as part of Microsoft Windows 2000 through Windows Vista (it is not part of Windows 7). Microsoft Agent functionality is exposed as an ActiveX control that can be used by web pages.

Before you can use the Agent in Powerbuilder, you need to download Microsoft Agent from Microsoft Agent site and install it into your computer. There 2 cores that you must download, one is Microsoft Agent core component, and the other is the Agent Character, which have 4 characters officially from Microsoft.

In this sample, I use Peedy, a green talking bird as a character

The next step is try to insert OLE Object at Powerbuilder's windows object. Choose the Microsoft Agent 2.0 from the Insert Control Tab.

Add Microsoft Agent Control 2.0 from the list

Agent OLE Object after inserted
In the Open event of window w_agent, type this script below:

//  set the agent, and named as Clippit
ole_1.Object.Characters.Load("Clippit","c:\windows\msagent\chars\peedy.acs")

// show the Clippit
ole_1.Object.Characters("Clippit").Show

// move the Clippit to position 400,200
ole_1.Object.Characters("Clippit").MoveTo(400,200)

// ask Clippit to play animation Greeting
ole_1.Object.Characters("Clippit").Play("Greet")

// ask Clippit to say something
ole_1.Object.Characters("Clippit").Speak("Hello World !!! I am Peedy !!! Called by Powerbuilder !!!")

If you have a speaker (and I bet you have), you can hear the voice speaking from Character.
Run the script, and you will get like this image


There's many build in functions in Agent character, and also many third party characters which you can find at Microsoft Agent's ring.

You can learn more about the functions and properties at Microsoft Agent official site, including the guidelines if you want to create your own character.

Of course, if you want to deploy your Powerbuilder applications with Microsoft Agent object, you also need to install Microsoft Agent cores at the PC Client.
»»  READMORE...

Powerbuilder function to get business day

The function is to get total business days between 2 dates, it means we ignore the Saturday and Sunday.
The function need 2 parameters to pass with datetime type, called: adt_awal and adt_akhir, and will return Long type.


integer i, counter, li_daynumber, li_weeks, li_daysremained
long ll_daysafter

ll_daysafter = DaysAfter(date(adt_awal), date(adt_akhir))
li_weeks = ll_daysafter / 7
li_daysremained = mod(ll_daysafter,7)
counter = li_daysremained

FOR i = 1 TO counter
    li_daynumber = DayNumber(RelativeDate(date(adt_awal), i))
    IF li_daynumber = 1 OR li_daynumber = 7 THEN
       li_daysremained --
    END IF
NEXT

RETURN (li_weeks * 5) + li_daysremained

To use this function, just type this script:

Long lBusinessDay
lBusinessDay = f_businessday(DateStart,DateEnd)
»»  READMORE...