Author Topic: [SOLVED] get cursor location  (Read 1266 times)

0 Members and 1 Guest are viewing this topic.

Offline xra7en

  • Seasoned Forum Regular
  • Posts: 284
    • View Profile
[SOLVED] get cursor location
« on: May 11, 2019, 09:13:25 am »
Not sure if it was QB, but is there a fuction for the following on a 80x25 text screen

clearEol (clears text at cur position to the end of the line)
wherex, wherey: returns location of cursor (not mouse)
« Last Edit: May 11, 2019, 09:33:14 am by xra7en »
I just like re-writing old DOS book games into modern QB64 code - weird hobby, I know!

Offline Pete

  • Forum Resident
  • Posts: 2361
  • Cuz I sez so, varmint!
    • View Profile
Re: get cursor location
« Reply #1 on: May 11, 2019, 09:30:01 am »
clearEOL, not in traditional QB. You need to locate the cursor and use something like this: PRINT STRING$(80 - POS(0), 32);

wherex, wherey: Yes, CSRLIN returns the text cursor row position while POS(0) returns the text cursor column position.

Pete
Want to learn how to write code on cave walls? https://www.tapatalk.com/groups/qbasic/qbasic-f1/

Offline xra7en

  • Seasoned Forum Regular
  • Posts: 284
    • View Profile
Re: get cursor location
« Reply #2 on: May 11, 2019, 09:32:55 am »
oh man yer soooo fast. I was still looking while I posted that (I am very impatient LOL).. here is what I came up with

Code: [Select]
    x = CSRLIN
    y = POS(0)
    LOCATE x, y: PRINT "some cool text: "
Hope that helps some one.

ps
I just recently found _printstring. Will have to look into that
I just like re-writing old DOS book games into modern QB64 code - weird hobby, I know!

Offline Ashish

  • Forum Resident
  • Posts: 630
  • Never Give Up!
    • View Profile
Re: [SOLVED] get cursor location
« Reply #3 on: May 11, 2019, 09:49:13 am »
Do you want something like this from clearEol()?
Code: QB64: [Select]
  1.  
  2. PRINT "QB64!"
  3. PRINT "Forever!!"
  4. clearEol
  5.  
  6.  
  7. SUB clearEol ()
  8.     row% = CSRLIN
  9.     column% = POS(0)
  10.     LOCATE row% - 1, column%
  11.     PRINT SPACE$(80 - column%)
  12.  
if (Me.success) {Me.improve()} else {Me.tryAgain()}


My Projects - https://github.com/AshishKingdom?tab=repositories
OpenGL tutorials - https://ashishkingdom.github.io/OpenGL-Tutorials

Offline Pete

  • Forum Resident
  • Posts: 2361
  • Cuz I sez so, varmint!
    • View Profile
Re: [SOLVED] get cursor location
« Reply #4 on: May 11, 2019, 09:51:52 am »
Or...

Code: QB64: [Select]
  1. PRINT "Who are better, Conservatives";
  2. x = CSRLIN: y = POS(0)
  3. PRINT " or Liberals?"
  4. PRINT "Press any key for answer..."
  5. LOCATE x, y: PRINT STRING$(80 - y, 32);

Pete 😁
Want to learn how to write code on cave walls? https://www.tapatalk.com/groups/qbasic/qbasic-f1/

Offline xra7en

  • Seasoned Forum Regular
  • Posts: 284
    • View Profile
Re: [SOLVED] get cursor location
« Reply #5 on: May 11, 2019, 11:54:28 am »
I did this :-)

Code: QB64: [Select]
  1. SUB clrEol (thisRow)
  2.     PRINT STRING$(80 - thisRow, 32);
  3.  

your second one is good too, but the "L" is not capitalized :P


actually, now that I think about it, i might expand this to include row and col and len of string[/code]
« Last Edit: May 11, 2019, 11:57:44 am by xra7en »
I just like re-writing old DOS book games into modern QB64 code - weird hobby, I know!

Offline Pete

  • Forum Resident
  • Posts: 2361
  • Cuz I sez so, varmint!
    • View Profile
Re: [SOLVED] get cursor location
« Reply #6 on: May 11, 2019, 02:07:19 pm »
Another one you might like for clearing just a portion of the SCREEN, CLS 2, when combined with VIEW PRINT...

Code: QB64: [Select]
  1. COLOR 15, 1: CLS
  2. msg$ = "This is the Title of the Program Window"
  3. LOCATE 1, 40 - LEN(msg$) / 2: PRINT msg$
  4. PRINT STRING$(80, 196)
  5. LOCATE 24, 1
  6. PRINT STRING$(80, 196);
  7. LOCATE 25, 1
  8. msg$ = "Press a key to continue this demo..."
  9. PRINT msg$;
  10.  
  11. COLOR 7, 0: CLS 2 ' Change only the viewable area to black background with white text.
  12. FOR i = 1 TO 21
  13.     LOCATE i + 2, 1: PRINT i;
  14.  
  15. CLS 2
  16.  
  17. PRINT "See? CLS 2 only cleared the VIEW PRINT area, and left the skin intact!";
  18.  

Pete
« Last Edit: May 11, 2019, 04:03:29 pm by Pete »
Want to learn how to write code on cave walls? https://www.tapatalk.com/groups/qbasic/qbasic-f1/