開啟計時器 (n) GOSUB 陳述式的解決方式是限制為 1 秒。
若要解決此限制 (以取得較小的時間間隔) 的三種不同方法如下:
- 使用時間間隔的 976 微秒的解析度的函式 86 十六進位 (或,十進位,134 函式的插斷 21) 的使用 BIOS 插斷 15 十六進位 (976 百萬分之一或.000976 的第二個)。
- 使用 BIOS 插斷 1A 十六進位 (十進位 26) 函式 0 解析度,以在大約 18.20648 刻度每秒 (或.05492549 秒為單位)。
- 播放 ON 陳述式用於在 30 秒的時間 (或.0333333).解析度
本文將告訴方法 1 上面。 若要尋找兩個其他文件說明方法 2 和 3,搜尋下列的實際單字此知識庫中:
基本計時器和增加第二個和較小
此資訊適用於 Microsoft QuickBasic 版本 4.00 4.00b,4.50 Microsoft 基本編譯器版本 6.00 和 6.00b 的 MS-DOS,並以 Microsoft 基本專業開發系統 (PDS) 7.00 和 7.10 的 MS-DOS 版本。
使用函式 86 十六進位的插斷服務常式 15 十六進位 (十進位格式: 函式 134 INT 21) 您可以延遲的 976 微秒為單位) 在間隔內執行程式。 此插斷函式只能在 IBM AT] 和 [PS/2 類別機器上正常運作並在電腦或 XT 類別電腦,這並不支援此函式上將會失敗。 如果在您的電腦上失敗,此插斷,可以使用方法 2 或 3 上面。
請注意插斷常式只為了 MS-DOS,而不支援在 OS/2 保護模式。
更多資訊有關在 MS-DOS 的插斷請參閱 「 進階 MS-DOS 程式,第二版 」,眷顧鄧肯柏,所發行的 Microsoft 按 (1988 年)。
範例程式碼
'| *******************************************************************
'| The DELAY% function below uses an interrupt call to suspend the
'| execution of the program for a given number of microseconds, in
'| integrals of 976 microseconds.
'| This program uses BIOS interrupt 15 hex with function 86 hex
'| (or, in decimal, interrupt 21 with function 134).
'|
'| NOTE : This interrupt only works on AT and PS/2 machines, and
'| will fail on PC or XT class machines. The function will
'| return a value of 1 when it fails to delay the program,
'| and a value of 0 when it completes the call.
'|
'| *******************************************************************
DECLARE FUNCTION DELAY% (Integral AS LONG)
'| Use the following $INCLUDE metacommand in Microsoft QuickBasic
'| 4.00/4.00b/4.50 or Basic Compiler 6.00/6.00B:
REM $INCLUDE: 'QB.BI'
'| You must change 'QB.BI' to 'QBX.BI' above if you are using
'| Basic PDS 7.00 or 7.10.
FUNCTION DELAY% (Integral&)
'| Set up the register parameters used by INTERRUPT routine:
DIM ToDOS AS RegType, FromDOS AS RegType
'| Interrupt service 15 hex with function 86 hex will suspend
'| the calling process for a specified interval in microseconds.
DOSINT% = &H15
ToDOS.Ax = &H8600
'| Calculate the Microseconds to pause (Integrals of 976):
MicroSeconds& = Integral& * 976
'| The Delay value is a long integer and must be broken into
'| the component high/low integer parts:
ToDOS.Dx = VAL("&H" + HEX$(MicroSeconds& MOD &H10000))
ToDOS.Cx = VAL("&H" + HEX$(MicroSeconds& \ &H10000))
CALL INTERRUPT (DOSINT%, ToDOS, FromDOS)
'| This interrupt service only works on a AT or PS/2 machine
'| and will fail on PC/XT machines, and possible other machines.
IF FromDOS.Flags AND 1 THEN
ReturnDelay% = 1 '| Failed interrupt call
ELSE
ReturnDelay% = 0 '| Call Worked and should have delayed
END IF
'| Return the flag to the caller:
DELAY% = ReturnDelay%
END FUNCTION