×
INTELLIGENT WORK FORUMS
FOR COMPUTER PROFESSIONALS

Contact US

Log In

Come Join Us!

Are you a
Computer / IT professional?
Join Tek-Tips Forums!
  • Talk With Other Members
  • Be Notified Of Responses
    To Your Posts
  • Keyword Search
  • One-Click Access To Your
    Favorite Forums
  • Automated Signatures
    On Your Posts
  • Best Of All, It's Free!

*Tek-Tips's functionality depends on members receiving e-mail. By joining you are opting in to receive e-mail.

Posting Guidelines

Promoting, selling, recruiting, coursework and thesis posting is forbidden.

Students Click Here

run two loops at once

run two loops at once

run two loops at once

(OP)
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..

RE: run two loops at once

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.

RE: run two loops at once

(OP)
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..

RE: run two loops at once

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.

RE: run two loops at once

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

RE: run two loops at once

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

    

RE: run two loops at once

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.

RE: run two loops at once

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.

Red Flag This Post

Please let us know here why this post is inappropriate. Reasons such as off-topic, duplicates, flames, illegal, vulgar, or students posting their homework.

Red Flag Submitted

Thank you for helping keep Tek-Tips Forums free from inappropriate posts.
The Tek-Tips staff will check this out and take appropriate action.

Reply To This Thread

Posting in the Tek-Tips forums is a member-only feature.

Click Here to join Tek-Tips and talk with other members! Already a Member? Login

Close Box

Join Tek-Tips® Today!

Join your peers on the Internet's largest technical computer professional community.
It's easy to join and it's free.

Here's Why Members Love Tek-Tips Forums:

Register now while it's still free!

Already a member? Close this window and log in.

Join Us             Close