Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Threads in QBasic
#1
I am working on a 24 Game (Math 24) Card Solver that is currently very slow. I am wondering if there is any way to use threads in qbasic (have a sub return control to the code that called it immidiatly (sp?) after it begins running), or to make code that does something similar. Here is the function that I would want to apply this concept to:
Code:
FUNCTION CardWork% (Num1 AS INTEGER, Num2 AS INTEGER, Num3 AS INTEGER, Num4 AS INTEGER, cardNum AS INTEGER)
        DIM intn(0 TO 3)
        SUpTo = 1
        intn(0) = Num1
        intn(1) = Num2
        intn(2) = Num3
        intn(3) = Num4
        DIM o(0 TO 2)
        DIM nu(0 TO 3)
        DIM give(0 TO 1)
        i = 1
        FOR i = 1 TO 999
                Solutions(cardNum, i) = ""
        NEXT i
        FOR n1 = 0 TO 3
                FOR n2 = 0 TO 3
                        IF n2 <> n1 THEN
                                FOR n3 = 0 TO 3
                                        IF n1 <> n3 AND n2 <> n3 THEN
                                                FOR n4 = 0 TO 3
                                                        IF n1 <> n4 AND n2 <> n4 AND n3 <> n4 THEN
                                                                FOR o1 = 0 TO 3
                                                                        FOR o2 = 0 TO 3
                                                                                FOR o3 = 0 TO 3
                                                                                        nu(0) = intn(n1)
                                                                                        nu(1) = intn(n2)
                                                                                        nu(2) = intn(n3)
                                                                                        nu(3) = intn(n4)
                                                                                        ts(0) = nu(0)
                                                                                        o(0) = o1
                                                                                        o(1) = o2
                                                                                        o(2) = o3
                                                                                        FOR slw = 1 TO 4
                                                                                                FOR tlw = 1 TO 2
                                                                                                        IF slw >= 3 THEN tlw = tlw + 2
                                                                                                        CALL DoSelects(o(0), p(1), ts(1), e(1), nu(0), nu(1))
                                                                                                        IF slw = 1 THEN
                                                                                                                give(0) = ts(1)
                                                                                                                give(1) = nu(2)
                                                                                                        ELSEIF slw = 2 THEN
                                                                                                                give(0) = nu(2)
                                                                                                                give(1) = ts(1)
                                                                                                        ELSEIF slw = 3 THEN
                                                                                                                give(0) = nu(2)
                                                                                                                give(1) = nu(3)
                                                                                                        ELSE
                                                                                                                give(0) = nu(3)
                                                                                                                give(1) = nu(2)
                                                                                                        END IF
                                                                                                        CALL DoSelects(o(1), p(2), ts(2), e(2), give(0), give(1))
                                                                                                        IF tlw = 1 THEN
                                                                                                                give(0) = ts(2)
                                                                                                                give(1) = nu(3)
                                                                                                        ELSEIF tlw = 2 THEN
                                                                                                                give(0) = nu(3)
                                                                                                                give(1) = ts(2)
                                                                                                        ELSEIF tlw = 3 THEN
                                                                                                                give(0) = ts(1)
                                                                                                                give(1) = ts(2)
                                                                                                        ELSE
                                                                                                                give(0) = ts(2)
                                                                                                                give(1) = ts(1)
                                                                                                        END IF
                                                                                                        CALL DoSelects(o(2), p(3), ts(3), e(3), give(0), give(1))
                                                                                                        IF slw >= 3 THEN tlw = tlw - 2
                                                                                                        IF Check(cardNum) THEN works = TRUE
                                                                                                NEXT tlw
                                                                                        NEXT slw
                                                                                NEXT o3
                                                                        NEXT o2
                                                                NEXT o1
                                                        END IF
                                                NEXT n4
                                        END IF
                                NEXT n3
                        END IF
                NEXT n2
        NEXT n1
        IF works THEN CardWork% = TRUE ELSE CardWork% = FALSE
END FUNCTION

For the full code of the program, see 24 Game (Math 24) Card Solver.
Reply
#2
As QBasic is a 16bit DOS environment, it does not support multitasking, and thus, not threading.

So, no, cant be done.
Reply
#3
You are not exactly right, ZireSmile
There is a neat possibility of user defined events in QB71/VBD
Code:
on uEvent gosub ev111 '/ or goto (dont remember:)
uevent on

call process
end

ev111:
' do something:)

return
sub process
    for i=1 to 1000000 ':)
       'run some qb - function -that shifts point to event threating                                              
       'procedure see in qb71 manual (i dont remember)
    next
end sub
url=http://zerodivide.h15.ru/cyclone.html]Cyclone v2.5.2 GUI For QBasic 4.5/7.1[/url]
Explorer For DOS
Reply
#4
It is possible but it requires ASM knowledge. I've already done this with PB but it should be possible with QB too. I don't know if there's a library for this already ...

Regards,
Mark
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)