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 Chris Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Detect current workspace? 3

Status
Not open for further replies.

Paco75

Programmer
Oct 11, 2001
239
US
Hi,

I want to know if there is a way to detect the current workspace. I need it to save the current workspace and DBF() on entering a .prg and then restore them before exit that same .prg

Ex:
Code:
SELECT 1
USE aTable EXCLUSIVE 
DO prg_program WITH aParameter

Code:
&& get the workspace (should return 1 here)
[COLOR=red]oldWorkspace = ???????????????[/color]
oldTable = DBF()

SELECT 2
USE another Table EXCLUSIVE
&& ... do something ...

SELECT oldWorkspace
USE oldTable

thanks
 
OldWorkSpace = Select(0)

Regards

Griff
Keep [Smile]ing

There are 10 kinds of people in the world, those who understand binary and those who don't.
 
Yes i knew it. but thanks. :)

Also in the solution (for others that might seek to do the same) i use ISEXCLUSIVE(oldTable) to save if the table was open in EXCLUSIVE mode... otherwise i open it in SHARED.
 
If you need your table untouched and selected when coming back from a called routine, don't just remember the workarea, you also need to check if your table is still open in it. Therefore it's even better to also remember the alias via ALIAS() and reselect that and check if your're in the same workarea.

May be a bit overcautious, depending on the routine you call.
You might even start a new datasession before starting something messing up with your session:

Code:
lnCurrentSession = Set("Datasession")
o = CreateObject("Session")
Set Datasession To o.DatasessionID
* Call routine
Set Datasession To lnCurrentSession

If the routine should work on your data that's of course not the way to go.

And also, if you call a method of an object, that will run in the datasession the object is created in.

Ok, enough said. Maybe I'm more confusing than helping, but keep it in the back of your mind, you can also control datasessions, not only via forms with private datasession.

Bye, Olaf.
 
Paco - one other comment. You have SELECT 1 in your code. It's a bad idea to rely on specific work areas. Instead of:

Code:
SELECT 1
USE aTable EXCLUSIVE

use:

Code:
SELECT 0
USE aTable EXCLUSIVE

That will open the table in the first available work area. From there on out, you refer to it by alias, not work area, like this:

Code:
SELECT aTable
* Now do something with aTable

In fact, you rarely need to actually select a work area. Most commands accept an IN clause and it's good practice to use it wherever it's available.

Tamar

 
Your are right Tamar! Thanks for the tip! :)
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top