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

reading variables from another file running at the same time

Status
Not open for further replies.

Guest_imported

New member
Jan 1, 1970
0
Hi,
Is there a way to read the variable from another qbasic file that is running?(i can complie that file into an exe if necesserry)
Thanks
 
Do you mean two modules running in the same program? Look for help under the SHARED key word... or do you mean two separate applications?

If that app reading the variable has shelled from the app that set the variable the easiest way is to set the value in the environment.

For example:
[tt]
MyNumber = 52647
ENVIRON "MyVariable=" + STR$(MyNumber)
[/tt]
In the shelled app:[tt]
MyNumber = VAL(ENVIRON$("MyVariable"))[/tt]

If, on the other hand, you have two apps running in separate windows, the problem becomes a little sticky. The environment tables won't be shared between the two windows. You could use InterruptX to read and write to the Master Environment Table (I believe you will find it in the PSP of the primary command processor) but this is no easy task for
a beginning programmer.

The easy way is to place your values in a user-defined data structure, write them to a file and allow the second app to read the values from the file.

If none of these suit your requirements, post back and clarify your needs.
 
yeah, i'd like to know how to place the values in a user defined structure, and write them to a file and then be able to read them from the second app.
 
Try it like this...

Place the following lines in the first app:[tt]
TYPE Variables
ShortInt AS INTEGER
LongInt AS LONG
SinglePrec AS SINGLE
DoublePrec AS DOUBLE
WriteTime AS STRING * 8
END TYPE
REDIM MyVariable(1 TO 1) AS Variables
MyVariable(1).ShortInt = 32767
MyVariable(1).LongInt = 2147483647
MyVariable(1).SinglePrec = 3.402823D+38
MyVariable(1).DoublePrec = 1.797693134862315D+308
MyVariable(1).WriteTime = TIME$

OPEN "C:\DataFile.Dat" FOR BINARY AS #1
PUT #1, 1, MyVariable(1)
CLOSE #1
[/tt]
Add the type declarations and REDIM statementto the second app and add the following lines:
[tt]
OPEN "C:\DataFile.Dat" FOR BINARY AS #1
GET #1, 1, MyVariable(1)
CLOSE #1
PRINT MyVariable(1).ShortInt
PRINT MyVariable(1).LongInt
PRINT MyVariable(1).SinglePrec
PRINT MyVariable(1).DoublePrec
PRINT MyVariable(1).WriteTime
[/tt]
Naturally, you would want to make sure that the values are up to date. The "WriteTme" string will tell the second app how recently the data was saved from the first app.

I hope this starts you out on the right foot. Check QBasic help for more details on the variable types and the OPEN, PUT, GET and CLOSE commands.
gears.gif



[sig]<p> <br><a href=mailto: > </a><br><a href= plain black box</a><br>[/sig]
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top