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!

Looking up values 1

Status
Not open for further replies.

fisol

Programmer
Mar 1, 2002
24
MY
I am working on 2 tables named as ?A? and ?B?.
..............................
TableA with 3 fields as below
------+-----------+-------
Score | ResultA |ResultB
------+-----------+-------
150.00| 35.00 | 25.00
------+-----------+-------
255.00| 45.00 | 30.00
------+-----------+-------

TableB with 4 fields as below
-------+--------+---------+---------
LowLim | UpLim | ResultA | ResultB
-------+--------+---------+---------
100.01 | 200.00 | 35.00 | 25.00
-------+--------+---------+---------
200.01-| 300.00 | 45.00 | 30.00
-------+--------+---------+---------
.................................
Whenever I put in a value in the ?Score? field in table ?A? I need to get the values for ?ResultA? and ?ResultB? in table ?B?. As long as my score value in table ?A? is within the range of any given ?LowLim? and the ?UppLim? values of table ?B? the values for ?ResultA? and ?ResultB? are valid to be recorded in my table ?A?.
I find that I cannot use ?lookup table? in the usual manner which Paradox allows since my score value does not match the value of neither the ?LowLim? nor the ?UppLim? fields in table ?B?.
Is there a way of solving this problem? Or am I asking something which is beyond the capability of Paradox.
 
Fisol,

No, this can be done; however, it probably easiest to use ObjectPAL to do this.

Here's an example of one approach; others are certainly possible:

Code:
method pushButton(var eventInfo Event)
var
   tcA,
   tcB  TCursor
endVar

   tcA.attach( TableA )
   tcA.edit()
   tcB.open( ":work:tableb" )

   scan tcA :

      scan tcB :

         if ( tcA."Score" >= tcB."LowLim" ) AND
            ( tcA.&quot;Score&quot; <  tcB.&quot;UpLim&quot; ) then

            tcA.&quot;ResultA&quot; = tcB.&quot;ResultA&quot;
            tcA.&quot;ResultB&quot; = tcB.&quot;ResultB&quot;
            tcA.postRecord()
            quitLoop

         endIf
      endScan
      tcB.home()

   endScan
   tcA.endEdit()
   tcA.close()  ; be sure to do this!
   tcB.close()  ; be sure to do this!

endMethod

Now, there's little error checking, but it works in a simple case. In production, you'll probably want to see whether or not the records in TableA are already locked (if so, you won't be able to update them) and respond accordingly.

One trick I use in this wort of thing is the either post any pending edits or cancel the operation of the table's already in Edit mode, depending on which works best for your user(s).

You'll note I flagged the closing of TCursors as important. In certain versions of Paradox, it's possible to accidentally leave a TCursor open in memory with no way to get to it. There are a number of factors involved, but I've found it best to simply--and formally--close all TCursors before they go out of scope.

I generally use something like this:

Code:
   if tc.isAssigned() then
      try
         tc.close()
      endTry
   endIf

I've been told this is overly paranoid, but I've been bitten by it enough that I've simply made it a habit, especially when devising code designed to work with multiple versions of Paradox.

Hope this helps...

-- Lance

 
Thank you Lance.
I followed EXACTLY your coding; putting my tables and the fields in their appropriate places.
On checking the syntex I received an error pointing to your code : tcA.attach(TableA).
&quot;attach&quot; is highlighted and the error is :parameter mismatch.
 
Lance.
When I replaced your code.... tcA.attach( TableA )....
with this ....tcA.open(&quot;:work:tableA.db&quot;).... things worked great for me.
Now I can do the look up in double quick time.
Thanks again to you.
 
Fisol,

You're welcome. I should've described that in more detail. Attach() associates a tCursor with the data set bound to a UIObject, such as a table frame, multi-record object, or field on a form.

Open, on the other hand, goes directly to the disk.

There are times you'll want either, so my code illustrated both.

As you continue to learn Paradox, I think you'll find there's not a lot you can't do with it. There's a bit to learn and to get used to, but once you get past a few things, you'll find it's really more capable and powerful than people suspect.

Also, if you run into problems with anything I post in the future, please don't hesitate to contact me privately. My informations on the profile.

Hope this helps...

-- Lance
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top