2

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?

Community
  • 1
  • 1
MD XF
  • 7,860
  • 7
  • 40
  • 71

2 Answers2

3

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.

MD XF
  • 7,860
  • 7
  • 40
  • 71
MrSnrub
  • 1,123
  • 1
  • 11
  • 19
0

Considering that your program is working in a textual environment 25 Lines x 80 Columns (CGA Text Mode 640x200) Syntax for 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

Forgive me if I correct your opinion, but BASIC has evolved like other Programming Languages, VB.NET and FreeBASIC, where you can develop objects, libraries and take advantage of libraries written in other languages like C and C ++, Currently the same FreeBASIC is a Port of C and as like him has the same potential, in fact it is possible to develop applications for graphical and textual environment on Linux and Windows, you can implement libraries to use databases like MySQL and Oracle, also the same FreeBASIC manages multiple threads to run multiple processes simultaneously .

ExagonX
  • 141
  • 10