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

returning the current segment

Status
Not open for further replies.

MagnaUnum

Programmer
Oct 12, 2000
6
US
I think I might have covered the entire breadth of my question in the subject line :)

obviously the current segment has to be stored in memory somewhere, but where? and once the location is known, how could you read it without changing the current segment to the segment in which the value resides?

Am I making a snip of sense here? :)

Mag
 
I don't think there is a way to retrieve that value with QB (Toshi will probably prove me wrong and I hope he does.)

In my mind, the best way to get the current segment is to store the value in a variable before you do a DEF SEG and then get it from the variable. Aside from that, as long as you haven't set a segment, you can assume the current segment is the default segment for QB.

That probably didn't help much. Under what conditions would your app forget the segment it has set with DEF SEG? Maybe we can work this out.
VCA.gif

Alt255@Vorpalcom.Intranets.com
 
well, it's actually not for me, but someone who was asking me for help. He's apparently putting together a set of routines that he wants the programmer to be able to use without having to worry about the fact that many of his routines work in other segments. So he wanted to make a routine that stores the current segment when one of his routines is called and then resets it when the routine is done.

Mag
 
Hi,

The QB45 help states that if you omit the address whe using DEF SEG the BASIC segment is used.

Does this help?

Pappy
 
"There are two internal variables BASIC maintains that you will find useful.
One is the current DEF SEG setting, and it is stored in the integer
variable named B$SEG." (Ethan Winer, BASIC Techniques and Utilities, pp.448)
This will only work when compiled on the command line, as far as I know.

 
"The same holds true for a routine that changes the
current DEF SEG setting, perhaps before loading or saving a file using
BLOAD or BSAVE. If you cannot return that to its original value, extra
work is needed in the main program each time the routine is used.
Access to B$SEG requires a single assembler instruction, as shown in the
complete GetSeg function shown following. Declare and use GetSeg like
this:
DECLARE FUNCTION GetSeg%()
SavedSeg = GetSeg%
.
.
DEF SEG = SavedSeg
.Model Medium, Basic
.Data
Extrn B$Seg:Word
.Code
GetSeg Proc
Mov AX,B$Seg ;load the value from B$Seg
Ret ;return with the function output in AX
GetSeg Endp
End


..." (Ethan Winer pp.448-449)

 
You may also want to check out this thread:

thread314-34793 a few pages back dealing with VarSegs, SADDs, etc. It may prove useful to you in your quest.

--MiggyD "It's mind over matter. They don't mind so you don't matter to them."
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top