deprecatedbasicfreebasic

Get/set cursor position in BASIC


I know BASIC is a deprecated language but it's fun to play around with. I'm using FreeBASIC on Windows and I'm trying to re-compile an old program that I originally wrote for the Apple ][.

One instruction that no longer works is HOME, which coincidentally HOMEs the cursor. I found this about getting/setting the cursor position in VB.NET, but as I'm using BASIC I assume it will not work.

Therefore, my question is... how can I get/set the cursor position in BASIC?


Solution

  • You can set the cursor position using LOCATE:

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

    LOCATE can be used as a function as well to detect the current cursor position. But there are also dedicated functions for that, CSRLIN and POS.