Get/set BASIC 中的光标位置

Get/set cursor position in BASIC

我知道 BASIC 是一种已弃用的语言,但使用起来很有趣。我在 Windows 上使用 FreeBASIC,我正在尝试重新编译我最初为 Apple 编写的旧程序][.

一个不再有效的指令是 HOME,巧合的是 HOME 是光标。我在 VB.NET 中找到了 this 关于 getting/setting 的光标位置,但是因为我使用的是 BASIC,所以我认为它不起作用。

因此,我的问题是...如何 get/set BASIC 中的光标位置?

您可以使用LOCATE设置光标位置:

CLS
LOCATE 3, 30
PRINT "Hello World"
GETKEY
END

LOCATE 也可以用作检测当前光标位置的函数。但是也有专门的功能,CSRLIN and POS.

考虑到您的程序在文本环境中运行 25 行 x 80 列(CGA 文本模式 640x200) FreeBASIC

的语法
dim as integer column = 0, row = 0 'Set the variable for store the position
dim as string char = "" ' Set a variable for store the pressed key
cls ' Clear the screen

row = csrlin ' read the actual cursor row and store inside the var row
column = pos ' read the actual cursor column and store inside the var column

do until ( char = chr(27) ) ' make a loop until you press ESC key

char = inkey ' store the pressed key in char variable



    if  not(char = "") Then ' When you press a key and char store the pressed key then start this routine

        if not(char = chr(27)) then ' if pressed a key and not are the ESC or Enter or backspace key

            if char = chr(13) then ' when press enter
                row = row + 1 ' add a new line if enter are pressed
                if row > 23 then row = 23 ' put the stop at row 23
                column = 0 ' Put the column at beginning
            end if

            if char = chr(8) then ' when press backspace
                locate row, column 
                print " "
                column = column - 2 ' remove a value from column
                if column < 0 then column = 0 ' column cant be lower than 0

            end if


            if column > 79 then column = 79 ' stop the cursor at 79 column
            locate row, column ' move the cursor where 
            print char ' print the key pressed
            column = column + 1 ' add a value to the initial value



        end if


        locate 24,60 : Print "Row:(" & str(Row) & ") Column:(" & Str(Column) & ")" ' this show where the next cha appair

    End if
loop

请原谅我纠正你的观点,但 BASIC 像其他编程语言一样发展,VB.NET 和 FreeBASIC,你可以在其中开发对象、库并利用用其他语言(如 C 和 C)编写的库++,目前同一个FreeBASIC是C的Port,和他一样有潜力,实际上可以在Linux和Windows上开发图形和文本环境的应用程序,你可以实现使用 MySQL 和 Oracle 等数据库的库,同样的 FreeBASIC 管理多个线程以同时 运行 多个进程。