QB64.org Forum

Active Forums => QB64 Discussion => Topic started by: xra7en on May 11, 2019, 09:13:25 am

Title: [SOLVED] get cursor location
Post by: xra7en 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)
Title: Re: get cursor location
Post by: Pete 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
Title: Re: get cursor location
Post by: xra7en 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
Title: Re: [SOLVED] get cursor location
Post by: Ashish 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.  
Title: Re: [SOLVED] get cursor location
Post by: Pete 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 😁
Title: Re: [SOLVED] get cursor location
Post by: xra7en 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]
Title: Re: [SOLVED] get cursor location
Post by: Pete 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