PowerBuilder pasting in tabbed data window - tabs

I recently started a new job with a company and my first task is to update some quite old software for them.
There is a big back story but basically the software was written in PB8 (around 1997) and no one within the company (including me) has had any experience with PowerBuilder before and as the newbie I have been tasked to update and maintain it until a replacement has been approved and can be developed.
We have the license for PowerBuilder 12.5 so I am using PB12.5 Classic to do everything. The original developer cannot be contacted for support and no documentation exists.
One thing I am trying to understand, that will be a huge help in the future, is how to determine where functions are defined and where variables get their values..
The example I am working on at the moment is the following scenario.
There is a data window with tabs, named tab_detail each tab displays different whatever little orange men are in the tree list.
One of these are called dw_detail which allows pasting of data. None of the other tabs allow pasting of data, but I would like them to. dw_detail has an event rbuttondown() with the following code in it:
Window w_parentwin
If ib_add_mode Or ib_chg_mode Then
w_parentwin = Parent.GetParent().GetParent()
m_dwpaste m_pop_paste
m_pop_paste = CREATE m_dwpaste
m_pop_paste.idw_data = This
If ii_agent_code > 0 And Not IsNull(id_period) And Clipboard() <> "" Then
m_pop_paste.m_popup.m_paste.Enabled = TRUE
Else
m_pop_paste.m_popup.m_paste.Enabled = FALSE
End If
m_pop_paste.m_popup.PopMenu(w_parentwin.PointerX(), w_parentwin.PointerY())
DESTROY(m_pop_paste)
End If
When I add that code to the rbuttondown() event of tab number 2 (dw_adjustment) tab 2 now allows paste when I right click within the dw_adjustment data window but the data gets pasted to the fields within the dw_detail tab not the fields on the dw_adjustment tab.
I have tried debugging and stepping through the code but there are thousands of values in the variable window and without the ability to search I cannot find the variables used above and what their values are or why data gets pasted to the dw_detail tab instead of the dw_adjustment tab when I paste into the dw_adjustment tab.
Basically I am looking for any helpful tips on where to look or what the above is doing and why everything pastes to tab 1 instead of the tab I clicked paste in.
If more detail is needed from code from a different location or more information is needed I am happy to provide it.
As suggested by Seki I found the m_popup when double clicked it came up with wf_pastereturn():
Integer li_idx, li_rows, li_dwrows, li_comm, li_seqno
String ls_approval_type
If tab_detail.tabpage_details.dw_detail.RowCount() > 0 Then
li_idx = 1
li_dwrows = tab_detail.tabpage_details.dw_detail.RowCount()
Do Until li_idx > li_dwrows
ls_approval_type = tab_detail.tabpage_details.dw_detail.Object.approval_type [li_idx]
If IsNull(ls_approval_type) or ls_approval_type = "" Then
tab_detail.tabpage_details.dw_detail.DeleteRow(li_idx)
Else
li_idx++
End If
li_dwrows = tab_detail.tabpage_details.dw_detail.RowCount()
Loop
End If
If li_dwrows > 0 Then
li_seqno = Long(tab_detail.tabpage_details.dw_detail.Object.seq_no [li_dwrows])
End If
li_seqno += 10
If Clipboard() <> "" Then
If tab_detail.tabpage_details.dw_detail.ImportClipboard(1, li_rows, 1, 4, 3) <= 0 Then
MessageBox("Invalid Data", "Unable to paste!", StopSign!)
Return -1
End If
li_rows = tab_detail.tabpage_details.dw_detail.RowCount()
li_dwrows++
For li_idx = li_dwrows To li_rows
tab_detail.tabpage_details.dw_detail.Object.approval_type [li_idx] = trim(tab_detail.tabpage_details.dw_detail.Object.approval_type [li_idx])
tab_detail.tabpage_details.dw_detail.Object.approval_no [li_idx] = trim(tab_detail.tabpage_details.dw_detail.Object.approval_no [li_idx])
tab_detail.tabpage_details.dw_detail.Object.agent_code [li_idx] = ii_agent_code
tab_detail.tabpage_details.dw_detail.Object.period [li_idx] = id_period
li_comm = f_new_commission(Long(tab_detail.tabpage_details.dw_detail.Object.value_of_work[li_idx]), id_period)
tab_detail.tabpage_details.dw_detail.Object.levy_payable[li_idx]= &
inv_rate.of_CalculateLevyPayable (Long(tab_detail.tabpage_details.dw_detail.Object.value_of_work[li_idx]), id_period)
tab_detail.tabpage_details.dw_detail.Object.comm_deductable [li_idx] = li_comm
tab_detail.tabpage_details.dw_detail.Object.commission [li_idx] = li_comm
tab_detail.tabpage_details.dw_detail.Object.seq_no [li_idx] = li_seqno
li_seqno += 10
tab_detail.tabpage_details.dw_detail.Object.agent_return_detail_create_date[li_idx] = Today()
tab_detail.tabpage_details.dw_detail.Object.agent_return_detail_create_user[li_idx] = SQLCA.Logid
Next
Clipboard("")
Return 0
Else
Return -1
End If
I modified the function to use the windows SelectedTab property. Data will now paste into the tab but in the wrong input fields. I looked further and the data columns for the ImportClipboard function do not line up.
How is the best way to change the order of the selected database columns?
Here is a screenshot of what I mean by tabs:
So within the main program window, there are the above tabs, within each tab (where the input fields are) there is a data window labelled with the dw_ prefix.
Thanks heaps for your help.

I think first you should do some short tutorials. Please check out these:
PowerBuilder Classic 12/12.5 guide/tutorials
These are short and useful.
On the other side you are able to select specific variables in your own "watch variable" list, so you do not have to search over the several variables. You can right click on the variable name and do a Quickwatch or you can Insert the variable name in the Watch window.
Br. Gábor

The action with a contextual menu is in 2 times :
handle the mouse right click to display a contextual menu
perform an action among the one or several actions provided by the popup menu
You shown the pbscript that is displaying the menu with PopMenu() if there is something in the clipboard (Clipboard() <> "") and maybe you did not noticed that the pasting action is somewhere else.
Look in m_popup: there must be some code inside that may be hard-coded to paste in dw_detail. If so, maybe that you could store in the window instance variables a reference to the currently processed dw for the contextual menu.
Something like :
datawindow idw_current in the instance variables
then in the rbuttondown() event idw_current = this (this being the datawindow the rbuttondown() event belongs to)
and finally in the menu reuse the id_current instead of a hardcoded dw_detail
Concerning your question about where the variables are modified: what you can do is searching the variables by their name (right click on the target or a single pbl or object then 'search'), and put a breakpoint on the lines where they are affected. If you run in debug mode (CtrlDCtrlT instead of CtrlR) you will be able to trace when a variable is modified.

Paste Problem
Pass 1
It's hard to tell for sure, but I'd look at the code of m_dwpaste.m_popup.m_paste.Clicked. The worse case scenario is that dw_detail is hard coded into that script; the slightly better case is that it has a more flexible routine in there, but somehow dw_adjustment doesn't fit into that algorithm.
Pass 2
With the new information, we can see that the code of wf_pastereturn() (I'm not sure how you got to this script, but this looks like the culprit) is not simply pasting, but doing a lot more that involves specific fields. In fact, it's not just pasting, it's importing the data, which means that it's assuming the contents of the clipboard are not only in a specific format, but match the data set of the DataWindow (see the Columns pane in the DW painter, and be careful not to confuse the data set part of the DataWindow with the UI part). The question is, do you want:
"Pasting" like copying text from Notepad into a browser form; just putting text into the current field?
"Pasting" exactly like the other DataWindow, including assumptions that all the same columns mentioned in the script are in both DataWindows?
"Pasting" something like this script, but customized for the data set in the new DataWindow?
These all require somewhat different solutions, combined with the differences I asked about in my comment about tabs vs. DataWindows.
Finding Stuff
I'm going to give an unapologetically biased point of view, because I'm the author of a tool that, among other things, helps you search PowerBuilder code called PBL Peeper.
If you're looking at code in the Browse tab, and you want to see other mentions of the variable, you can select it, right click, and either
search forward or back within the script
search for the object name in the tree on the left (it'll make more sense when you see it)
search either the rest of the object or the rest of the application
Finding where a variable is assigned is more difficult than it sounds, because of the multiple syntaxes that could be involved.
// assigns a value on instantiation
int i = 1
// assigns a value when executed
i = 1
// does not assign a value
IF i = 1 THEN
// assigns a value possibly if the parameter is passed by reference (kind of like a pointer to the variable)
f_foo (i)
Finding the setting of a variable can be helped by understanding variable scope. If the variable is local, you only need to search the script. If the scope is instance or shared, you need to search the object (as above, pretty easy) and its descendants (easy to go to a given descendant with an RMB on the treeview, harder to search on a set of descendants). If the scope is global, you want to search the entire app.
Finding where a selected function is declared is possible, but you need to know a little secret (or RTFM). The Find on the RMB menu uses the parameters from the Find page, so you need to set Portion Type to All, not just Scripts, to find where functions are declared. Alternatively, you can use the Lists / Scripts pages and find the script using the functions on that page (Find, QuickFind, Filter, etc...).
The tool has a plethora of functionalities that let you find, filter and sift through code to get at what you're after. The above is just a quick introduction.
Good luck,
Terry.

Related

SSIS - Loop Through Active Directory

Disclaimer: new to SSIS and Active Directory
I have a need to extract all users within a particular Active Directory (AD) domain and import them into Excel. I have followed this: https://www.itnota.com/query-ldap-in-visual-studio-ssis/ in order to create my SSIS package. My SQL is:
LDAP://DC=JOHN,DC=JANE,DC=DOE;(&(objectCategory=person)(objectClass=user)(name=a*));Name,sAMAccountName
As you know there is a 1,000 row limit when pulling from the AD. In my SQL I currently have (name=a*) to test the process and it works. I need to know how to setup a loop with variables to pull all records and import into Excel (or whatever you experts recommend). Also, how do I know what the other field names are that are available to pull?
Thanks in advance.
How do I see what's in Active Directory
Tool recommendations are off topic for the site but a tool that you can download, no install required, is AD Explorer It's a MS tool that allows you to view your domain. Highly recommend people that need to see what's in AD use something like this as it shows you your basic structure.
What's my domain controller?
Start -> Command Prompt
Type set | find /i "userdnsdomain" and look for USERDNSDOMAIN and put that value in the connect dialog and I save it because I don't want to enter this every time.
Search/Find and then look yourself up. Here I'm going to find my account by using my sAMAccountName
The search results show only one user but there could have been multiples since I did a contains relationship.
Double clicking the value in the bottom results section causes the under pane window to update with the details of the search result.
This is nice because while the right side shows all the properties associated to my account, it's also updated the left pane to navigate to the CN. In my case it's CN=Users but again, it could be something else in your specific environment.
You might discover an interesting categorization for your particular domain. At a very large client, I discovered that my target users were all under a CN
(Canonical Name, I think) so I could use that in my AD query.
There are things you'll see here that you sure would like to bring into a data flow but you won't be able to. Like the memberOf that's a complex type and there's no equivalent in the data flow data types for it. I think Integer8 is also something that didn't work.
Loop the loop
The "trick" here is that we'll need to take advantage of the
The name of the AD provider has changed since I last looked at this. In VS 2017, I see the OLE DB Provider name as "OLE DB Provider for Microsoft Directory Service"
Put in your query and you should get results back. Let that happen so the metadata is set.
An ADO.NET source does not support parameterization as the OLE DB does. However, you can apply an Expression on the Data Flow which surfaces the component and that's what we'll do.
Click out of the Data Flow and back into the Control Flow and right click on the Data Flow and select Properties. In that properties window, find Expressions and click the ellipses ... Up pops the Property Expressions Editor
Find the ADO.NET source under Property and in the Expressions section, click the Ellipses.
Here, we'll use your same source query just to prove we're doing the right things
"LDAP://DC=JOHN,DC=JANE,DC=DOE;(&(objectCategory=person)(objectClass=user)(name=" + "a" + "*));Name,sAMAccountName"
We're doing string building here so the problem we're left to solve is how we can substitute something for the "a" in the above query.
The laziest route would be to
Create an SSIS variable of type String called CurrentLetter and initialize it to a
Update the expression we just created to be "LDAP://DC=JOHN,DC=JANE,DC=DOE;(&(objectCategory=person)(objectClass=user)(name=" + #[USer::CurrentLetter] + "*));Name,sAMAccountName"
Add a Foreach Loop Container (FELC) to your Control Flow.
Configure the FELC with an enumerator of "Foreach Item Enumerator"
Click the Columns...
Click Add (this results in Column 0 with data type String) so click OK
Fill the collection with each letter of the alphabet
In the Variable Mappings tab, assign Variable User::CurrentLetter to Index 0
Click OK
Old blog posts on the matter because I like clicks
https://billfellows.blogspot.com/2011/04/active-directory-ssis-data-source.html
http://billfellows.blogspot.com/2013/11/biml-active-directory-ssis-data-source.html

Passing Variables Between Forms

Forgive me if this has already been asked- I can’t seem to find a well written answer.
I am developing a small application for personal use.
Essentially what I have is two forms. Form 1 is a master view of all my contacts listed on a data grid view. Form 2 will be loaded on the cell/row double click of a particular record in order to edit it’s details.
My question is, what is the best practice/method for achieving this? I have seen many different methods.
Should I:
Pass only the primary key of the selected row then populate the fields on form 2 load
Pass all fields as a variable within a class then populate form 2 from that
Maybe I’m headed in the complete wrong direction though.
I have tried both ways, but wondering what the best method is for scalability.
My personal preference would be to pass a datarow into the opening argument of the form (rather than the PK / all the variables). You can then use the datarow inside your Form2 to bind to your controls or set their values, whichever you think is appropriate.
There are some useful examples on working with a datarow if you're unsure, alternatively you can also check out Microsoft Docs.
Public Sub New(ByVal row As DataRow)
InitializeComponent()
' your code for working with row here
End Sub
Edit:
In terms of "Binding" vs "Setting", you can either have your controls linked to your data to be two way (as you edit the data in a control at run time you alter the data in your database) or you can just set the values of the controls.
E.G. TextBox1.Text = row(0)("ColumnName")
You can find more on data binding on the Microsoft Docs page

MS Access 2007 - controlling UI behaviour after attempt to insert duplicate record

Creating a simple UI using MS Access, hoping to do minimal actual coding (actually helping a friend who is not a coder).
Simplified requirement: Single table, primary key is phone number, lots of other non-mandatory fields. Display a form allowing just the phone number to be entered, if a record with that key exists display the full record, if a record with that key does not exist bring up an form allowing the other fields to be entered for this phone number and hence create a new record.
Q1: Any simple way to achieve this kind of function? Example?
We've got some of this going with a standard form, can execute code if insertion fails, but a standard dialogue box is displayed warning about the duplciate key violation.
Q2: How can we trap that attempted insertion, avoid having the dialogue come up?
You will have to get your hands dirty and write some code to get this outcome. A starting point would be something like this presto code. Post back if you get stuck on any of the parts.
If fCheckIfRecordExists(lYourKey)=True then
Docmd.OpenForm “frmEditExistingRecord”
Else
Docmd.OpenForm “frmEnterNewRecord”
End if
Public function fCheckIfRecordExists (lYourKey as Long) as Boolean
‘Code to check if a record exists, simple method is to use dLookup or a count SQL statement with the criteria as the key you are trying to find
End function
EDIT:
First things first make a form with 1 text box called txtPhone_number and a command button called cmdSearch.
Next put this bit of code in the module behind the form
Public Function fDoes_record_exist(strPhone_number As String) As Boolean
If DCount("Phone_number", "tblYour_table", "Phone_number=" & strPhone_number) > 0 Then
fDoes_record_exist = True
Else
fDoes_record_exist = False
End If
End Function
Next you need to put some code behind the click event of the command button. This code can be expanded on to check for a valid phone number later if you want
If fDoes_record_exist(Me.txtPhone_number) = True Then
DoCmd.OpenForm "frmShow_existing_record"
Else
DoCmd.OpenForm "frmEnter_new_record"
End If
That should set you on your way nicely but post back if you run into problems
Here is an overview of the process with Access logic:
You need an unboud control labelled Phone in the form header, where user will be able to enter the phone number to search. You need to use the After_Update event of that control to trigger your search. There will be a second Phone control, bound this time, in the Detail section of the form for effective data entry/update.
Use the Form_Error event to intercept the error message when user tries to save a duplicate key, in order to display a nice message, and eventually Cancel his changes.
The advice from Kevin Ross to use VB Code is clearly one approach, and I think is appropropriate if we anticipate less trivial requirements in future. However I'm in a situation where I'm helping someone with zero coding background and hence if possible I'd prefer to let them use simple Macros rather than full-scale VB.
As it happens the functionality I require can be implemented with just Macros, and it depends on the suggestion from iDevelop.
The outline of the solution I used:
Create an InitialEntry form with no association to any particular table, it has:
a data entry field for the telephone number
a read-only text box where I can display a message
a button labelled Add
a button labelled Show
I write three macros:
A macro AlreadyExists that displays a message saying "We already that one"
A macro NewEntry that opens a data entry form for my table, in Add mode, and which copies the phone number from InitialEntry!TelephoneNumber
A macro TestForExisting this uses a condition
DCount("*","MyTable","[PhoneNumber] = [FormPhoneNumber] " ) > 0
to control whether to execute AlreadyExists, and a similar test to control whether to call NewEntry.
While this is not as efficient as VB, it does seem to be understandable by a non-coder, so at least we can implement our application.

MS Access 2003/2007 - Passing data through a variable on unbound forms vs. a hidden text box

Ok so I hope the title of the question matches what I about to ask, but here is what I am trying to get at:
So I have an access database that uses a number of unbound forms, and the purpose of the forms are to collect data and save to various tables with VBA click events using SQL statements (INSERT or UPDATE based on whether the ID of the record is present on the form in a hidden text box). When entering a new record (via INSERT), I get the row number with
MyRow = db.openrecordset("SELECT ##Identity")(0) 'thanks David
So you maybe getting the picture. If I have another form that relates to the first form in terms of the record, I just open a recordset and pass that value to another hidden text box.
So my question is, is there a better way to do this regarding passing that value (or just using that value) using a variable instead of this awkward method. So I realize a lot of folks are going to go with the obvious answer of, "Why not just make your forms bound instead of all this code"...and I am sure that is a valid answer, however I inherited this database which was already put together like this, and re-structuring it would be a daunting task.
Any and all advice, or learning resources are greatly appreciated, as they always are!
I use unbound controls on forms for all these kinds of values. The current solution of using an unbound form is sounder than using global or form level variables. If I recall the details correctly while debugging code and you hit the stop button you lose all global or form level variables. Or if the user hits an unhandled error.
Have you looked at OpenArgs?
DoCmd.OpenForm "Form1", , , , , , "Hello"

Use a value from a combo/text box in a file path string

I have a form that I intend to allow users to browse powerpoint presentations through, because there are a lot of different briefs for metrics, which is what I use this database for. So, I already know how to set up everything, just got one little hang up.
If I place a combo box on the form to select from a list of different presentation, can I use that in the file path string (that I have to use to pull the ppt into theobject frame in access.
example:
"C:\Users\Justin\Desktop\" & cmbTitle & ".ppt"
I tried it and it gives me the error message variable not defined. I never defined a control before on in these things, would it be as a string?
I realize that the exact file path much match the entered value. Access 2000-2003/XP
Thanks as always guys!
You need to refer to the field as Me.cmbTitle. As it is written, it looks like you're calling the variable cmbTitle which doesn't exist.
Is the value of cmbTitle some ID/Integer field or is it the actual string value? You may want to use the immediate window to check this. Also, make sure the value of cmbTitle doesn't have any backslashes or spaces (That may require quotes?).
I'm somewhat confused as to what you're trying to do. I will write my answer assuming:
you have a form in an Access database.
on that form is combo box that lists the PowerPoint presentations your users are working with.
the bound column of the combo box lists the filename (without path) of each PPT file.
when the user selects a filename from the combo box, you want to display it in an unbound OLE object frame.
The code for that, assuming the list of PPT files is called cmbTitle, would be in the combo box's AfterUpdate event and would look like this:
Private Sub cmbTitle_AfterUpdate()
Dim strPresentation As String
If IsNull(Me!cmbTitle) Then Exit Sub
strPresentation = "C:\Users\Justin\Desktop\" & Me!cmbTitle & ".ppt"
Me!olePPT.SourceDoc = strPresentation
End Sub
Now, I can't get a test unbound OLE object frame to work with this, but it seems to me to be the right way to do it.
My suspicion is that you're either attempting to set the wrong property, or you've defined your OLE frame wrongly, but I can't offer any more advice on that without knowing more about what you're actually attempting to do, and exactly what line of code is causing the error.