Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Some questions about programming

Status
Not open for further replies.

Memphistn80

Technical User
Feb 15, 2008
2
NL
Hello all,

For a school assignment i have to make an application in powerbuilder. Now, i'm not a programmer at all so i have some problems with the syntax and just not knowing what names there are for certain things.

I want to program a search function where i'm able to check other options to take it within the search. For example if i want to search for a customer with the name of johnson, i check the checkbox customer and fill in 'johnson' in the single line edit control, when i click the search button, all the customers named johnson appear in my window.

This is the code i have so far:

IF pbm.cbx_customer = TRUE THEN
dwc_clients.DataObject = "dw_customer"
retrieve()

Now the problem is, that i don't know how the checkbox is called, so this is what's going wrong in the syntax. I also don't know what to put between the () for the retrieve, should it be "+%" to get only the customers with the name of johnson and not other customers? And is this the right code/syntax to fix this problem?

I hope someone can help me with this problem.
Kind regards,
Richard
 
Let's go one-by-one... For the checkbox call, where is the function located that is checking the checked value of the checkbox? If it's in the window (window function or window event... even an object on that window), then you can simply use this:

IF cbx_customer.Checked THEN
//your code
END IF
 
Now filtering just on your customer's name (be it first, last, etc) kinda depends on where the data is coming from. If it's a SQL select statement in the datawindow, I do one of three things:

1) Pass parm into datawindow, and use the parm in the WHERE clause of the SQL
2) Dynamically create/modify the datawindow's SQL using the GetSQLSelect( ) and SetSQLSelect( ) functions for a datawindow.
3) Use the datawindow's Filter( ) & SetFilter( ) functions to filter out the rows.

If you're not dealing with a great deal of rows, or wanting the most basic option, in my opinion, read up on the SetFilter( String ) & Filter( ) functions.

What goes in between the "( )" for the Retrieve( ) function is your parms, based on the parms of that datawindow. If no parms are defined, then a simple "( )" suffices, but if there are parms required for that datawindow, then you'll get a arguments mismatch error when trying to retrieve.

Another pointer... Whatever you do, don't get into managing several datawindows that basically retrieve the same information, based on different inputs!

Any other questions, just ask!
 
Hello,

Thank you for the reply on my question.

I think i have the right code now, but still wondering what to put between the ().

This is the code:

IF cbx_klant.Checked = TRUE THEN
dwc_clients.DataObject = "dw_klanten"
retrieve()

END IF

Klant or klanten is Dutch, it means customer/customers.

What i would like is to get the data out of the data window. The teacher said i could do that for several options that are checkboxes, for instance date of birth, lastname, firstname. For each one i have to create a new datawindow and use the code to retrieve the data from the database.

Is this possible and what should i put between the () for the retrieve? Thanks!
 
// dw_select = " select name from customers where name like :'name what you search%'"
IF pbm.cbx_customer = TRUE THEN
dwc_clients.DataObject = "dw_customer"
dwc_clients.settransobject(sqlca)
retrieve( "name what you search" )
 
In the actual DataWindow, are you using a SQL statement to get the information? Also, what version of PB?

Anyway... Open the DataWindow in its painter, and look for a button to open the datasource. When the datasource is open, then there should be a menu option under the "Design" menu called "Retrieval Arguments". You can add as many as you like, and these are what you're assigning values to in between the "( )" in the Retrieve( ) function. Number of and types must match.

Then, to filter, (assuming it's a SQL SELECT) you'll need to add criteria to the WHERE clause. e.g. -- Suppose you're wanting all customers with the last name Smith... It would look something like this:

/*as_last = retrieval argument*/
SELECT LAST_NAME,
FIRST_NAME,
DOB
FROM CUSTOMER_TABLE
WHERE ( LAST_NAME = :as_last OR :as_last = '' )

Your arguments must be preceded by a colon :)), and the last part of the WHERE clause is so that you can pass in a blank string, and NOT query on it.

Personally, I hate this method, because for some reason I would rather programatically control the SQL statement rather than pass in arguments... That would look something like this:

/*this would be a function/event you call to retrieve*/
String ls_sql, ls_where

ls_sql = dw_cust.GetSQLSelect( )

IF cbx_last_name.Checked THEN
IF ls_where = '' THEN
ls_where = 'WHERE '
END IF

ls_where += "LAST_NAME = '" + sle_last_name.Text + "'"
END IF

IF cbx_first_name.Checked THEN
IF ls_where = '' THEN
ls_where = 'WHERE '
ELSE
ls_where += " AND ~r "
END IF

ls_where += "FIRST_NAME = '" + sle_first_name.Text + "'"
END IF

//depending on the known SQL statement, you may have to parse ls_sql to insert ls_where
ls_sql += ls_where

dw_cust.SetSQLSelect( ls_sql )
dw_cust.Retrieve( )


The above code will only add to the WHERE clause if need be added. Can be tedious to work with at times, but offers MANY more options!
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top