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!

run two loops at once

Status
Not open for further replies.

zolken1

Programmer
Oct 25, 2006
17
US
is there any way you can run two loops at once that are not inside each other??? i want one loop to open a file and print a line and the other loop ti input and save a message.

how do i do that


.... srry im new with some of this stuff..
 
I am not sure if this is what you want but a Qbasic program could "SHELL" a Windows "START" command which starts another window which could be a .BAT file that contains the running of any program including a Qbasic program of it's own.

Then the first Qbasic program could issue another "SHELL" "START" command. this is fairly straight forward if you are familiar with the Qbasic "SHELL" command & the WINDOWS "START" command. The new WINDOWS can run Max/Min plus a lot of other options.

These two new windows can be independent tasks of the orinination Qbasic program or it can "WAIT" on either window but that would defeat your purpose of doing multi-tasking the set of ".BAT" files.

to get help with the "START" command enter "START /?" on a command line.

Hope this helps.

I teach a lot of programming so I can learn. You can never learn it all.
 
ok so how do i use this statement, i tried it after i read your post i just wanted to see if i could get it to work. but i ccouldnt lol. but i think i ran across a post a while back saying that you could run two loops at once but i couldnt find it again. oh well. Im usiong this in my qbim program thats in another post..
 
An example use of the Qbasic SHELL command.

The first SHELL starts a sub shell that executes the directory request command with it's output going to a simple file. The swcond one starts a new window of NOTEPAD editing the created file. The second window can continue to run as an independent window even if the original Qbasic program terminates.
You can start any number of additional windows running independent of each other if desired. You will have to figure out the application needs but this is a simple implementation of what I was talking about.

A SHELL could issue the Windows "START" command.

SHELL "C:\DIR >C:\TEMP\DIR.TXT"
SHELL "NOTEPAD C:\TEMP\DIR.TXT"

I teach a lot of programming so I can learn. You can never learn it all.
 
Are they going to be running simultaneously as in when one is done, the other is?
if so just put calls to a print line sub, or a call to an input/save sub
 
The short answer is "No". There is no QBasic command such as "GC" (GOTO and Continue). If there were, you could code

Code:
PRINT "Start two processes"
CG ReadFile 'This will goto ReadFile but also immediately continue
OPEN "OutFile.dat" for output as #2
do
  line input "Enter message to be saved: "; M$
  if M$="" then exit do
  print #2, m$
loop 
close #2
END Me ' This would end only this task

ReadFile:
OPEN "InFile.dat" for input as #1
do
  if EOF(1) then exit do
  line INPUT #1, l$
  print l$
  line input "Read another line? "; a$
loop while ucase$(a$)="Y"
close #1
End Me ' This would end only this task

(In my imaginary instruction set, as soon as no tasks are running, the program would END.)

Anyway, you can't do that. Even if you could, it would be very confusing to the user. If the user hits a key, which of the two tasks would receive it?

That said, I would add that you can accomplish stuff like the above in a single task if you write your own replacement for LINE INPUT so that your basic program looks like

Code:
Dim Status as string*1 ' Identity of the task currently expecting user input
call Task1(""): call Task2("") ' Each will return when it needs a character
do
  k$=inkey$
  if k$=(some key that means swap tasks) then
    if Status=1 then Status=2
  elseif k$<>"" then
    if Status=1 then call Task1(k$) else call Task2(k$)
  endif
loop

That's just the big picture. Lots of details to make it work. So you really need to explain exactly what you want to accomplish and why.

Mac

 
This is not my basic but from what I know of timing problens with others I would suggest that you really need only one loop but handle things for both possibilities at different sections of the loop on a character by character basis.

Ed Fair
Give the wrong symptoms, get the wrong solutions.
 
Code:
Dim Status as string*1 ' Identity of the task currently expecting user input
call Task1(""): call Task2("") ' Each will return when it needs a character
do
  k$=inkey$
  if k$=(some key that means swap tasks) then
    if Status=1 then Status=2
  elseif k$<>"" then
    if Status=1 then call Task1(k$) else call Task2(k$)
  endif
loop
Status would eventually get stuck on two.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top