gpt4 book ai didi

menu - QBasic (QB64) 制作的主菜单?

转载 作者:行者123 更新时间:2023-12-04 07:17:10 26 4
gpt4 key购买 nike

我很久以前就制作了这个菜单,但我在大约 2 天前找到了这个文件,我想让它工作

CLS
FOR k = 10 TO 65
LOCATE 2, k: PRINT CHR$(222)
LOCATE 23, k: PRINT CHR$(222)
LOCATE 4, k: PRINT CHR$(222)
LOCATE 20, k: PRINT CHR$(222)
NEXT
FOR k = 2 TO 23
LOCATE k, 10: PRINT CHR$(222)
LOCATE k, 65: PRINT CHR$(222)
NEXT
LOCATE 3, 35: PRINT "M A I N M E N U"
LOCATE 6, 15: PRINT "[1] First Option"
LOCATE 8, 15: PRINT "[2] Second Option"
LOCATE 10, 15: PRINT "[3] Third Option"
LOCATE 12, 15: PRINT "[4] Fourth Option"
LOCATE 14, 15: PRINT "[5] Exit"
LOCATE 21, 15: INPUT "Enter your option"; op
现在,我想让它工作,例如:如果我按 1 它会自动转到该选项等等......

最佳答案

使用整数变量比使用浮点变量更快。出于效率原因,您可以将 k 和 op 变量更改为 k% 和 op%。
要在此菜单中直播,您有多种可能性。按照我个人喜好的顺序:
使用 SELECT CASE

DO
CLS
... ' the instructions that build your menu
LOCATE 21, 15: INPUT "Enter your option"; op%
SELECT CASE op%
CASE 1
... ' instructions belonging to 1st option
CASE 2
... ' instructions belonging to 2nd option
CASE 3
... ' instructions belonging to 3rd option
CASE 4
... ' instructions belonging to 4th option
CASE 5
END
END SELECT
LOOP
使用 IF
DO
CLS
... ' the instructions that build your menu
LOCATE 21, 15: INPUT "Enter your option"; op%
IF op%=1 THEN
... ' instructions belonging to 1st option
ELSEIF op%=2 THEN
... ' instructions belonging to 2nd option
ELSEIF op%=3 THEN
... ' instructions belonging to 3rd option
ELSEIF op%=4 THEN
... ' instructions belonging to 4th option
ELSEIF op%=5 THEN
END
END IF
LOOP
使用 ON GOSUB
DO
CLS
... ' the instructions that build your menu
LOCATE 21, 15: INPUT "Enter your option"; op%
IF op%>0 AND op%<6 THEN
ON op% GOSUB one, two, three, four, five
ENDIF
LOOP

one: ... ' instructions belonging to 1st option
RETURN
two: ... ' instructions belonging to 2nd option
RETURN
three: ... ' instructions belonging to 3rd option
RETURN
four: ... ' instructions belonging to 4th option
RETURN
five: END
DO ... LOOP使程序运行,直到用户最终按 5 选择退出。任何无效输入都会重新显示菜单。

关于menu - QBasic (QB64) 制作的主菜单?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/68695924/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com