【问题标题】:Get/set cursor position in BASIC在 BASIC 中获取/设置光标位置
【发布时间】:2017-05-05 01:47:31
【问题描述】:

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

一个不再起作用的指令是HOME,巧合的是HOMEs 光标。我发现this 关于在 VB.NET 中获取/设置光标位置,但由于我使用的是 BASIC,所以我认为它不起作用。

因此,我的问题是……如何在 BASIC 中获取/设置光标位置?

【问题讨论】:

    标签: deprecated basic freebasic


    【解决方案1】:

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

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

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

    【讨论】:

    • 在 FreeBASIC、Vintage BASIC 和 MS BASIC 中完美运行。谢谢。
    【解决方案2】:

    考虑到您的程序在文本环境中运行 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 的一个端口,和他一样有同样的潜力,事实上可以在 Linux 和 Windows 上开发图形和文本环境的应用程序,你可以实现库来使用 MySQL 和 Oracle 等数据库,也一样FreeBASIC 管理多个线程以同时运行多个进程。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2016-04-17
      • 2016-04-27
      • 2017-07-27
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多