on 05-23-2014 3:26 PM
Hello people,
We have several internal applications written in VB6 and using CR8.
Now I am working on the upgrade for CRXIR2, and it requires some coding.
It has been easier than I imagined, but I found a situation not encountered yet, even in my application that already was with CRXIR2 for some years.
There are some reports that the user can choose among some sort options.
The code was like that in CR 8:
If OptOrderForn.Value = True Then
Report1.SortFields(0) = "+{TabExec.EX_Nome}"
Else
Report1.SortFields(0) = "-{RelDados.Numero1}"
End If
Now, after searching about how to implement it in CRXIR2, I discovered that we need to declare and create an object for the field definitios, so the code is like that:
Dim CRXDatabaseField As CRAXDRT.DatabaseFieldDefinition
If OptOrderForn.Value = True Then
Set CRXDatabaseField = rpt.Database.Tables.Item(1).Fields.Item(3)
rpt.RecordSortFields.Add CRXDatabaseField, crAscendingOrder
Else
Set CRXDatabaseField = rpt.Database.Tables.Item(3).Fields.Item(8)
rpt.RecordSortFields.Add CRXDatabaseField, crDescendingOrder
End If
OK, after several tries, it is working now, but I had a certain difficulty on discovering what was the table index, because it didn't match the order found in the rpt file. Anyway, I had also to open the rpt to look for the correct field index.
Besides this difficulty on coding it, I am wondering on what will happen if we add a new table in this report, or if we remove a table, or if the table's structure changes. The report won't work correctly.
My question is:
Is there a better way to code it, I mean, is there a way to specify exactly the table and field names we want to use, as it was before?
Thanks for any help.
Isis
Hello,
Maybe someone else could have the same difficulty I had migrating CR8 to CRXIR2, so I will post the solution for my question of how to pass the table and field parameters to the RecordSortFields dinamically.
In CR8 it was direct:
If OptOrderForn.Value = True Then
Report1.SortFields(0) = "+{TabExec.EX_Nome}"
Else
Report1.SortFields(0) = "-{RelDados.Numero1}"
End If
Now in CRXIR2 my code is:
Function ItemTab(pTab As String) As Integer
Dim i As Integer
ItemTab = 0
For i = 1 To rpt.Database.Tables.Count
If UCase$(rpt.Database.Tables.Item(i).Name) = UCase$(pTab) Then
ItemTab = i
Exit For
End If
Next
End Function
Function ItemCampo(pItemTab As Integer, pCampo As String) As Integer
Dim i As Integer
ItemCampo = 0
For i = 1 To rpt.Database.Tables.Item(pItemTab).Fields.Count
If UCase$(rpt.Database.Tables.Item(pItemTab).Fields.Item(i).Name) = UCase$(pCampo) Then
ItemCampo = i
Exit For
End If
Next
End Function
(part of printing code:)
Dim CRXDatabaseField As CRAXDRT.DatabaseFieldDefinition
Dim auxItemTab As Integer, auxItemCampo As Integer
If OptOrderForn.Value = True Then
auxItemTab = ItemTab("TabExec")
auxItemCampo = ItemCampo(auxItemTab, "{TabExec.EX_Nome}")
Set CRXDatabaseField = rpt.Database.Tables.Item(auxItemTab).Fields.Item(auxItemCampo)
rpt.RecordSortFields.Add CRXDatabaseField, crAscendingOrder
Else
auxItemTab = ItemTab("RelDados")
auxItemCampo = ItemCampo(auxItemTab, "{RelDados.Numero1}")
Set CRXDatabaseField = rpt.Database.Tables.Item(auxItemTab).Fields.Item(auxItemCampo)
rpt.RecordSortFields.Add CRXDatabaseField, crDescendingOrder
End If
Hope this could help someone.
Isis
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Hi Isis,
You do know the RDC is end of life in XI R2 also correct? You may want to look at upgrading Visual Studio and then the CR for VS 2010/2012/2013 which is a free download. To get there here is the home page:
And the download is:
Then convert to CR .NET, no Embedded Designer available for redistribution and most of the RDC API's are now in CR .NET. If not we can try to get them in.
It's a free download and check the Licensing link for more info:
Back to the question, it's been a while since I used the RDC but see if reading these 2 registry keys gets you the info you need:
HKEY_CURRENT_USER\Software\Business Objects\Suite 11.5\Crystal Reports\DatabaseOptions
SortFieldNames and SortTableNames
If changes to your DB are done then you can use the Viewers Field Mapping Event to remap the fields if required. Usually a Verify Database will "Clean up" the report but it all depends on what changes are done.
Unfortunately the .NET Viewer does not have this event, it defaults to Auto which means if CR can't map the field automatically it simply deletes the field and all references which usually makes the report unusable, depending on where the fields were used of course...
You can find RAS ( Report Application Server - RDC replacement ) sample from here:
NET RAS SDK Samples - Business Intelligence (BusinessObjects) - SCN Wiki
Good luck
Don
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Hi Don,
Thanks for your hints about upgrading VS and CR, but it is impossible now...
We have several applications here, some very large, and I am the only programmer here.
This upgrade from CR8 to CRXIR2 is giving me already some headache, I had to stop development for several days, so by now it is really impossible.
Well, I don't know if I understood your idea about these registry keys... Through regedit, I can see they have the values "no" and "yes", respectively.
I don't understand how it could help me.
The FieldMapping event belongs to the object "Report", not to the viewer.
I will study it to see if it can help me.
I also will try to create a function to return the item number giving the field name, using the available objects, collections and properties, even though I am not familiar with them.
Finally, I don't know why most softwares lose functionalities and become more difficult to use as they upgrade (CR8 SortFields was much better than CRXIR2 RecordSortFields). Maybe this is a factor developers consider when they decide to keep their applications with deprecated tools.
Anyway, thanks for your answer.
Isis
User | Count |
---|---|
91 | |
10 | |
10 | |
9 | |
9 | |
7 | |
6 | |
5 | |
5 | |
4 |
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.