Domain Builder

  • Subscribe to our RSS feed.
  • Twitter
  • StumbleUpon
  • Reddit
  • Facebook
  • Digg

Monday, 28 January 2008

Avoiding "Double" Error Messages in DW Validation

Posted on 00:39 by Unknown
A common problem when setting up validation logic in ItemChanged is that two message get
displayed. First, the intended message in ItemChanged and then a default PowerBuilder message:
"Item '[value]' does not pass validation test". One simple solution to avoid this problem is to
have descendents set a flag (ib_SuppressMsg) in the ItemChanged event, when they've already
displayed an error message.
In ItemChanged event:
IF ... error situation ... THEN
... display message ...
li_Return = 1 // reject value
END IF

// Bottom of ItemChanged script ...
// set flag so ItemError know to suppress its default message
IF li_Return = 1 THEN
ib_SuppressMsg = True
END IF


In ItemError, check this flag and, if set, return 1 so the default ItemError message is suppressed:
IF ib_SuppressMsg THEN
li_Return = 1
ib_SuppressMsg = False // reset flag for next time
ELSE
... error not caused by ItemChanged
END IF
Read More
Posted in DataWindow | No comments

Sunday, 27 January 2008

Capturing Special Keys on your DataWindow

Posted on 23:47 by Unknown
A common requirement for applications is to capture certain keystrokes and perform special
actions when the user presses these keys. To capture keystrokes on your DataWindow, do the
following:
  1. Declare an event on your DataWindow (possibly your ancestor DW, as is done here) and assign that event the pbm_dwnkey event id. This causes all keystrokes to be processed through the event.
  2. Code that event to handle the special keystrokes in the desired manner. Ideally, common keystrokes (like Enter, Tab) will be captured at the ancestor level and a standard event will be called. A sample event that catches certain keystrokes is shown below.
In this sample event, the following keystrokes can be captured:
  • tabs: to do so, a descendant DW sets the ib_CaptureTab instance variable to True. The
    ue_Tab or ue_BackTab event are then invoked when Tab/BackTab is pressed to allow
    the descendant to code appropriate logic.
  • enter keys: to do so, a descendant DW sets the ib_CaptureEnter instance variable to True.
    The ue_Enter event is then called when Enter is pressed to allow the descendant to code
    appropriate logic.
sample ue_key event code:
// if descendent DW wants tab ... capture it
IF ib_CaptureTab AND KeyDown(KeyTab!) THEN
// determine whether it is a tab or back-tab
IF NOT KeyDown(KeyShift!) THEN
This.POST ue_Tab()
ELSE
This.POST ue_BackTab()
END IF
Return 1 // have key not otherwise be ignored by PB

// if descendent DW wants enter keys ... capture it
ELSEIF ib_CaptureEnter AND KeyDown(KeyEnter!) THEN
This.POST ue_Enter()
Return 1 // have key not otherwise be ignored by PB

// otherwise send the key to the window-level for standard processing
ELSE
IF IsValid(iw_ParentWin) THEN
iw_ParentWin.TriggerEvent(Key!)
ELSE
// how did we get a key event for invalid parent?
f_SignalError(0/gi_zero,"Invalid Parent Window in Key Event")
END IF
END IF


Note: a handle to the parent window (iw_ParentWin) is obtained in the Constructor event. PFC's
of_GetParentWindow function is a good method to generically get a handle to the parent
window.
Read More
Posted in DataWindow | No comments

Center a Response Window

Posted on 17:38 by Unknown
You can centralized your windows with the following code and put it on open event:
LONG   ll_X, ll_Y, ll_XCtr, ll_YCtr
WINDOW lWin

lWin = aw_Window.ParentWindow();

ll_XCtr = lWin.X + ( lWin.Width / 2 );
ll_YCtr = lWin.Y + ( lWin.Height / 2 );

ll_X = ll_XCtr - ( aw_Window.Width / 2 );
ll_Y = ll_YCtr - ( aw_Window.Height / 2 );

IF ll_X < 0 THEN ll_X = 0;
IF ll_Y < 0 THEN ll_Y = 0;

RETURN aw_Window.Move( ll_X, ll_Y )


For MDI child window you can use the following code:
LONG   ll_X, ll_Y, ll_XCtr, ll_YCtr
WINDOW lWin

lWin = aw_Window.ParentWindow();

IF ( ( ( lWin.WindowType = MDI! ) OR ( lWin.WindowType = MDIHelp! ) ) AND &
( aw_Window.WindowType = Child! ) ) THEN
ll_XCtr = lWin.WorkSpaceWidth() / 2;
ll_YCtr = lWin.WorkSpaceHeight() / 2;

IF lWin.WindowType = MDIHelp! THEN
ll_YCtr = ll_YCtr - 40;
END IF

ll_X = ll_XCtr - ( aw_Window.Width / 2 );
ll_Y = ll_YCtr - ( aw_Window.Height / 2 ) - 200;

IF ll_X < 0 THEN ll_X = 0;
IF ll_Y < 0 THEN ll_Y = 0;
ELSE
ll_X = aw_Window.X;
ll_Y = aw_Window.Y;
END IF

RETURN aw_Window.Move( ll_X, ll_Y )
Read More
Posted in PowerScript | No comments

Thursday, 24 January 2008

If Statements Using SQL

Posted on 23:44 by Unknown
When building list windows for users you often want to allow them to specify search criteria. If the search criteria are simple and only have a single field or all fields must be entered than a simple WHERE clause with retrieval arguments will do the job.

For very complicated arguments with multiple selections you will have to resort to dynamically altering the SQL behind the datawindow. But you may not realize that if you do not require multiple selections for a single field then with some clever SQL coding you can avoid time consuming dynamic SQL.

For example if we were building a selection window for employees, you may want to allow the user to search based on employee number, employee name, Address or any combination of the three. We can achieve this by declaring three retrieval arguments of the correct datatypes. In your retrieve script on the window you would have designed the arguments input criteria using a datawindow! so you could select the empty field is null option of the edit control. If you have not and shame on you then if the field is empty you will need to manually set it to null.
Then in the SQL you would code for the NULL values:
SELECT emp_no, emp_name, emp_addr1, emp_telno
FROM employee
WHERE ( emp_no = :al_emp_no OR :al_emp_no IS NULL )
AND ( emp_name = :as_emp_name OR :as_emp_name IS NULL )
AND ( emp_addr1 = :as_emp_addr OR :as_emp_addr1 IS NULL )
You would also want to concatenate '%' on to the end of the strings to allow for pattern matching and convert both sides of the comparison to Lower case to make it more user friendly, you would convert the retrieval argument to lower case once in Powerscript and pass it to the datawindow:
( Lower( emp_name ) LIKE :as_emp_name...
Read More
Posted in Database | No comments

Run an Application Only Once

Posted on 22:25 by Unknown
In this tips, I would like to discuss how to make an application run only once at a time. When user try to run your application, first try to see if it is already running. If it is already running bring it to top and return. There are some sleek SDK functions you can make use of to implement this. The following are the steps to create this feature:
  1. Create a "Custom Class UserObject"
    Custom Class PowerBuilder UserObject
  2. Set the AutoInstantiate to TRUE
  3. Declare the Win32 API modul at the UserObject on Declare -> Local External Functions
    Function Long GetLastError () Library 'kernel32.dll'
    Function ULong CreateMutex (ULong lpsa, Boolean fInitialOwner, String lpszMutexName) Library 'kernel32.dll' Alias for CreateMutexA
  4. Create a UserObject Function like this:
    Create UserObject Function - isRunning
    String ls_name
    If Handle(GetApplication()) > 0 Then
    ls_name = GetApplication().AppName + Char(0)
    CreateMutex(0, True, ls_name)
    If GetLastError() = 183 Then Return True
    End If
    Return False
  5. Save the UserObject as uo_mutex (for example)
Below is how to use the object. Put this code at the beginning of open event from your Application object:
uo_mutex lou_mutex
If lou_mutex.uf_isrunning() Then
MessageBox ('Warning', 'Application is already running', StopSign!)
HALT CLOSE
End If
//...
// Your next line code
//...
Read More
Posted in Win32 API | No comments

C/C++ Datatype Conversion

Posted on 20:17 by Unknown
If you want to use the Win32 API within PowerBuilder, you have to know the prototype modul. The following list is not an exhaustive list of all C and C++ to PowerBuilder Datatype but most of the common Datatype that I've used over the years of interfacing PowerBuilder and C/C++ programs. There are two lists, the first is PowerBuilder to C++ Datatype, useful for the C Proxy Generator. Then there is a list of C/C++ to PowerBuilder Datatype useful for people writing DLL's and the like:
PowerBuilder DatatypeC/C++ Datatype
BlobPBBlob
Booleanint
Characterchar
DatePBDate
DateTimePBDateTime
DecimalPBDecimal
Doubledouble
Integerint
Realfloat
StringPBString
TimePBTime
UnSignedIntegerunsigned int

C/C++ DatatypePowerBuilder Datatype
BOOLBoolean
WORDUnSignedInteger
DWORDUnSignedLong
HANDLEUnSignedLong
HWNDUnSignedLong
LPSTRString Ref
LPBYTEString Ref
LPINTLong Ref
charBlob {1}
intInteger
unsigned intUnsignedInt
longLong
ULONG/unsigned longUnsignedLong
doubleDouble
char *String Ref
Read More
Posted in Win32 API | No comments

Wednesday, 23 January 2008

Registering OCX Components in an Exe

Posted on 20:56 by Unknown
Having problems with OCX's which work fine in development and EXE on your machine but when you ship the EXE to a users machine and install your program the OCX does not work?

The problem is that the way OCX's are designed to work is that every OCX should attempt on its own to register with the system during its constructor event. This is done by the container calling a function that is in EVERY OCX called DLLRegisterServer.

The problem is that PowerBuilder does not call this function. Even if you run the REGSRV utility, the OCX will fail to register itself. To correct this problem, in object where you are using the OCX you need to goto the constructor event and call the OCX DLLRegesterServer function.

Declare a local external function in the container object
Function long DllRegisterServer() Library "ocxname.OCX"

In the constructor event

LONG ll_RC
ll_RC = DllRegisterServer()
Read More
Posted in Win32 API | No comments

Get The Name of a Network Share

Posted on 20:43 by Unknown
Using the Get Volume API tip previously posted will return the names of the drives connected to your machine. Unfortunately for network drives this returns the name of the physical drive not the name of the share you have mapped to. If you have many shares mapped to a single physical network drive you will not be able to distinguish between the drives.

To improve this situation you can use an API call to return the name of the network share. This is more meaningful and easier for the user. The API call you will need to use is WNetGetConnectionA. To use the API call declare the local external function as follows:
function ulong WNetGetConnectionA( string szLocalPath, &
ref string szNameBuffer, ref ulong lpBufferSize) Library "mpr.dll"

Then in your script you can call the API as follows:
Ulong lul_Max
Long ll_RC
String ls_Drive, ls_Volume

// hard coded for the f: drive
ls_Drive = 'f:'
lul_Max = 2000

// pre allocate string to stop GPF
ls_Volume = Space( 2000 )

// call the API function, the share name
// will be in the ls_Volume variable
ll_RC = WNetGetConnectionA( ls_Drive, ls_Volume, lul_Max )
ls_Volume = Trim( ls_Volume )
Read More
Posted in Win32 API | No comments

Get Volume Information

Posted on 20:40 by Unknown
In order to show a list of Drives We needed to get the name of the Drive. The following API call gets the volume name as well as the serial number.

Create an NVO add the following local external function:
function long GetVolumeInformationA( ref string ls_RootPath, &
ref string ls_VolName, long ll_VolLen, ref string ls_volserial, &
long ll_maxcomplen, long ll_systemflags, &
ref string ls_SystemName,&
long ll_SystemLen ) Library 'kernel32'

Then add a function called GetVolumeName which accepts a string and returns a string and add the following code:
// Call the API function to get the volume label from a drive letter
Long ll_Max, ll_Flags, ll_Ret, ll_FileSys
Long ll_Vol

String ls_Vol
String ls_Drv, ls_FileSys, ls_Flags, ls_Serial


ls_Drv = as_Vol
ls_Vol = Space(32)
ls_FileSys = Space(32)
ls_Serial = Space(32)
ll_Vol = Len( ls_Vol )
ll_FileSys = Len( ls_Filesys )

ll_Ret = GetVolumeInformationA( ls_Drv, ls_Vol, ll_Vol, &
ls_Serial, ll_Max, ll_Flags, ls_FileSys, ll_FileSys )

IF (ll_Ret = 0) THEN
ls_Vol = ''
ELSE
ls_Vol = Trim( ls_Vol )
END IF

RETURN (ls_Vol)

Call the function passing the drive you want the volume name for. For example C:\
Read More
Posted in Win32 API | No comments

Mapping a Network Drive

Posted on 20:28 by Unknown
This tip show how to use the Window API for mapping a network drive from PowerBuilder.
Function Declaration:
FUNCTION ulong WNetUseConnectionA (ulong hwndOwner, &
REF s_netresource lpNetResource, string lpPassword,
string lpUsername, ulong dwFlags, REF string lpAccessName, &
REF ulong lpBufferSize, REF ulong lpResult) library "mpr.dll"

Structure Definition:
$PBExportHeader$s_netresource.srs
global type s_netresource from structure
unsignedlong dwScope
unsignedlong dwType
unsignedlong dwDisplayType
unsignedlong dwUsage
string lpLocalName
string lpRemoteName
string lpComment
string lpProvider
end type

Mapping Code:
CONSTANT ulong NO_ERROR = 0
CONSTANT ulong CONNECT_REDIRECT = 128
CONSTANT ulong RESOURCETYPE_DISK = 1

s_netresource lstr_netresource

String ls_null
String ls_buffer
String ls_MappedDrive

uLong ll_bufferlen
uLong ll_null
uLong ll_ErrInfo
uLong ll_success

SetNull(ll_null)
SetNull(ls_null)

ls_buffer = Space(32)
ll_bufferlen = Len(ls_buffer)

lstr_netresource.dwType = RESOURCETYPE_DISK
lstr_netresource.lpLocalName = ls_null
lstr_netresource.lpRemoteName = "UNC resource name here"
lstr_netresource.lpProvider = ls_null

ll_ErrInfo = WNetUseConnectionA(ll_null, lstr_netresource, &
'password', 'username', &
CONNECT_REDIRECT, ls_buffer, ll_bufferlen, ll_success)

IF ll_ErrInfo = NO_ERROR THEN
MessageBox("Drive Mapped", "Drive Letter is " + ls_buffer)
Return 1
ELSE
MessageBox("Mapping Falied", "Error is " + String(ll_ErrInfo))
Return -1
END IF
Read More
Posted in Win32 API | No comments

Getting Active Directory

Posted on 17:34 by Unknown
With this simple trick you can get the current active directory. Declare the Win32 API modul on Declare -> Local External Functions
Function boolean GetCurrentDirectoryA (long nBufferLength, ref string lpBuffer) Library "kernel32.dll"

Write this code:
string ls_temp
ulong lul_value
boolean lb_rc

lul_value = 255
ls_temp = space(255)
lb_rc = GetCurrentDirectoryA (lul_value, ls_temp)
If lb_rc Then MessageBox('Current Directory', ls_temp, information!)
Read More
Posted in Win32 API | No comments

Getting Computer Name

Posted on 17:20 by Unknown
You can get the computer name from within the application. Declare the Win32 API modul on Declare -> Local External Functions
Function boolean GetComputerNameA (ref string lpBuffer, ref ulong nSize) Library "kernel32.dll"

Now write this code:
string ls_temp
ulong lul_value
boolean lb_rc

lul_value = 255
ls_temp = space(255)
lb_rc = GetComputerNameA (ls_temp, lul_value)
messageBox ('Computer Name', ls_temp, information!)
Read More
Posted in Win32 API | No comments

Sending Key Press

Posted on 16:58 by Unknown
With this tips, you can make a control likely pressing (a) key(s). First declare the Win32 API modul on Declare -> Local External Functions
Subroutine keybd_event( int bVk, int bScan, int dwFlags, int dwExtraInfo) Library "user32.dll"

Next is an example to simulate pressing "A" key
integer li_vkey
li_vkey = 65 // Character A
sle_1.setfocus() // the desired control to view
keybd_event( li_vkey, 1, 0, 0)

Another example to simulate "Backspace" key
integer li_vkey
integer li_pos
li_pos = len(sle_1.Text) + 1
sle_1.selectText(li_pos, 0)// Cursor position on last text
li_vkey = asc ("~b") // backspace
keybd_event( li_vkey, 1, 0, 0)
Read More
Posted in PowerScript, Win32 API | No comments

Sending Hexadecimal Character to Printer

Posted on 16:44 by Unknown
When using several types of printer for a special purpose, sometime we have to send hexadecimal character to control the printer and to by pass the printer driver.
The example is shown below
int li_job
li_job = PrintOpen()
// Print Mode
PrintText ( li_job, "~h1B~h21~001", 0, 0)
// Spacing
PrintText ( li_job, "~h1B~h33~001", 0, 0)
PrintClose ( li_job )
Read More
Posted in PowerScript | No comments

Calling an Internet Browser from Application

Posted on 16:33 by Unknown
From PowerBuilder application, we can call (open) the default internet browser, as well as setting the default home page for the browser
Inet linet_base
GetContextService("Internet", linet_base)
linet_base.HyperlinkToURL("http://...")
If IsValid(linet_base) Then Destroy linet_base
Read More
Posted in PowerScript | No comments

Getting Date Format from Windows Registry

Posted on 04:21 by Unknown
By getting the date format from the Windows registry, we can use it for various need when you build a PowerBuilder application
RegistryGet("HKEY_CURRENT_USER\Control Panel\International","sShortDate", ls_shortdate
messageBox ("ShortDate", ls_shortdate)
Read More
Posted in PowerScript | No comments

Return Code on Application Exit

Posted on 03:48 by Unknown
Sometime when a PowerBuilder application is called by other program or a shell script, programmer want a return code after exiting the PowerBuilder application, just to get the status of the application called.

To give a return code, simply set the Message.LongParm property on the close event of the Application object with the desirable value.
   If ib_endingOK then
Message.LongParm = 1
Else
Message.LongParm = 0
End If
Read More
Posted in PowerScript | No comments

Saturday, 19 January 2008

Sitemap

Posted on 03:42 by Unknown
Sitemap :
  • If Statements Using SQL
  • Run an Application Only Once
  • C/C++ Datatype Conversion
  • Registering OCX Components in an Exe
  • Get The Name of a Network Drive
  • Mapping a Network Drive
  • Getting Active Directory
  • Getting Active Directory
  • Getting Computer Name
  • Sending Key Press
  • Sending Hexadecimal Character to Printer
  • Calling an Internet Browser from Application
  • Getting Date Format from Windows Registry
  • Return Code on Application Exit
Friend's Blog:
  • Oracle Tips & Tricks
  • Misterpopo Blog
  • Indonesian Career Information Directory
  • Avatar Fansite
  • Info Karir
Read More
Posted in | No comments

Friday, 18 January 2008

Privacy Policy

Posted on 21:15 by Unknown
Privacy Policy
If you require any more information or have any questions about our privacy policy, please feel free to contact us by email at sprpopo@yahoo.com.

At power-builder.blogspot.com, the privacy of our visitors is of extreme importance to us. This privacy policy document outlines the types of personal information is received and collected by power-builder.blogspot.com and how it is used.

Log Files
Like many other Web sites, power-builder.blogspot.com makes use of log files. The information inside the log files includes internet protocol ( IP ) addresses, type of browser, Internet Service Provider ( ISP ), date/time stamp, referring/exit pages, and number of clicks to analyze trends, administer the site, track user’s movement around the site, and gather demographic information. IP addresses, and other such information are not linked to any information that is personally identifiable.

Cookies and Web Beacons
power-builder.blogspot.com does use cookies to store information about visitors preferences, record user-specific information on which pages the user access or visit, customize Web page content based on visitors browser type or other information that the visitor sends via their browser.

Some of our advertising partners may use cookies and web beacons on our site. Our advertising partners include Google Adsense, .

PowerBuilder Tips & Tricks utilizes certain services from Google for ad serving and web traffic analysis. Please review Google's privacy policy for more information on how Google AdSense and Google Analytics stores your personal information. These Google servies may place and read cookies on your browser, or use web beacons to collect information, in the course of ads being served on the PowerBuilder Tips & Tricks website. Additionally, Google uses the DART cookie to enables it to serve ads to based on your visits to PowerBuilder Tips & Tricks and other sites on the Internet. You may opt out of the use of the DART cookie by visiting the Google ad and content network privacy policy.

These third-party ad servers or ad networks use technology to the advertisements and links that appear on power-builder.blogspot.com send directly to your browsers. They automatically receive your IP address when this occurs. Other technologies ( such as cookies, JavaScript, or Web Beacons ) may also be used by the third-party ad networks to measure the effectiveness of their advertisements and / or to personalize the advertising content that you see.

power-builder.blogspot.com has no access to or control over these cookies that are used by third-party advertisers.

You should consult the respective privacy policies of these third-party ad servers for more detailed information on their practices as well as for instructions about how to opt-out of certain practices. power-builder.blogspot.com's privacy policy does not apply to, and we cannot control the activities of, such other advertisers or web sites.

If you wish to disable cookies, you may do so through your individual browser options. More detailed information about cookie management with specific web browsers can be found at the browsers' respective websites.
Read More
Posted in | No comments
Newer Posts Home
Subscribe to: Comments (Atom)

Popular Posts

  • Using Windows Scripting Host
    You can use Windows Scripting Host on PowerBuilder for many purpose. On sample code below, you can use it to get the network domain, user na...
  • List available ODBC datasources
    You can list available ODBC datasources from within PowerBuilder. You need to declare the following external functions : FUNCTION integer SQ...
  • Sorting Datawindow
    Here's a script to sort datawindow rows when the column header is clicked as in windows explorer. Requirements : Column header should be...
  • Faster Exist Checking in Oracle
    When performing checks in business logic to see if a record is used as part of a foreign key in a child table people often opt for the Selec...
  • Return Code on Application Exit
    Sometime when a PowerBuilder application is called by other program or a shell script, programmer want a return code after exiting the Power...
  • Keeping Column into Array
    With this simple tips you can keep all the column name on DataWindow into an array int colNum, numCols string colName[] numCols = Integer(dw...
  • Julian Date
    Here's a function to calculate Julian Day number for the specified day, month, year. If the year is B.C. it must be negative. /* public...
  • Getting Computer Name
    You can get the computer name from within the application. Declare the Win32 API modul on Declare -> Local External Functions Function bo...
  • Get a list of printers installed
    In this example, we populate a listbox with the printers name /* Get Printer List */ string printers[] int rtn, i, nbPrinters rtn = Registry...
  • Calling Oracle Stored Procs/Functions from PB
    Whenever you want to make a call to an Oracle stored procedure or stored function, a good approach is to first declare it as an external fun...

Categories

  • Database
  • DataWindow
  • PowerScript
  • Win32 API

Blog Archive

  • ▼  2008 (34)
    • ►  March (14)
    • ►  February (1)
    • ▼  January (19)
      • Avoiding "Double" Error Messages in DW Validation
      • Capturing Special Keys on your DataWindow
      • Center a Response Window
      • If Statements Using SQL
      • Run an Application Only Once
      • C/C++ Datatype Conversion
      • Registering OCX Components in an Exe
      • Get The Name of a Network Share
      • Get Volume Information
      • Mapping a Network Drive
      • Getting Active Directory
      • Getting Computer Name
      • Sending Key Press
      • Sending Hexadecimal Character to Printer
      • Calling an Internet Browser from Application
      • Getting Date Format from Windows Registry
      • Return Code on Application Exit
      • Sitemap
      • Privacy Policy
Powered by Blogger.

About Me

Unknown
View my complete profile