"Locate" wrong position

New to FreeBASIC? Post your questions here.
Post Reply
Bad_Idea
Posts: 8
Joined: Sep 11, 2017 3:46

"Locate" wrong position

Post by Bad_Idea »

Hello :)
I have a weird issue with "Locate". It works fine in a console-window with 80x24, but when it's bigger than 24 rows, the locating doesn't work anymore.
This code works fine with 80x24, but it doesn't with everything above:

Code: Select all

ymax=HiWord(Width)
For i As Integer=1 To ymax
	Locate i,20
	Print "H"
Next
It should print a "H" from top to bottom in column 20. But when i>24, it prints them at column 1 instead.
fxm
Moderator
Posts: 12145
Joined: Apr 22, 2009 12:46
Location: Paris suburbs, FRANCE

Re: "Locate" wrong position

Post by fxm »

Welcome to the forum!

Yes, auto-scrolling disrupts the behavior of the full LOCATE statement.
Workaround: execute the positioning in 2 successive steps:

Code: Select all

For i As Integer=1 To ymax
   Locate i
   Locate ,20
   Print "H"
Next
Bad_Idea
Posts: 8
Joined: Sep 11, 2017 3:46

Re: "Locate" wrong position

Post by Bad_Idea »

Hm, weird. But it is working now thanks. :)
I guess I should take a look at ncurses instead.
counting_pine
Site Admin
Posts: 6323
Joined: Jul 05, 2005 17:32
Location: Manchester, Lancs

Re: "Locate" wrong position

Post by counting_pine »

Could someone post a bug report?
Is this in Linux or Windows/elsewhere? (I'm guessing the former.)
(Are you any relation to badidea, by any chance?)
Bad_Idea
Posts: 8
Joined: Sep 11, 2017 3:46

Re: "Locate" wrong position

Post by Bad_Idea »

I am on Linux.
And no, i am not the other guy. I am the worse idea.
fxm
Moderator
Posts: 12145
Joined: Apr 22, 2009 12:46
Location: Paris suburbs, FRANCE

Re: "Locate" wrong position

Post by fxm »

badidea
Posts: 2594
Joined: May 24, 2007 22:10
Location: The Netherlands

Re: "Locate" wrong position

Post by badidea »

Are you any relation to badidea, by any chance?
Not that i know :-) Also on linux BTW

Add ";' to omit the line break:

Code: Select all

dim as integer ymax=HiWord(Width)
For i As Integer=1 To ymax
   Locate i,20
   Print "H";
Next
sleep
Trinity
Posts: 214
Joined: Sep 16, 2017 17:07

Re: "Locate" wrong position

Post by Trinity »

This code , makes the last line append wrongly at the line before last unless one breaks up the locate into locate(x,) : locate(,y) :

P.S.
Not sure if it is a screw up of mine or if it is the locate , but if one changes "For b = 1 to (winheight/16)" to "For b = 1 to int(winheight/16)" then it do not append wrongly. When "For b = 1 to (winheight/16)" then one have to set the locate part to "locate (b,) : locate (,1+(t*Len(mystring)))" else it will append last line to the line before last .
(?)

Code: Select all

#include "fbgfx.bi"
Using FB ' namespace
dim as integer monitorwidth,monitorheight,winwidth,winheight,b,c,t
Dim as string mystring

screeninfo monitorwidth,monitorheight 
winwidth=monitorwidth-100 : winheight=monitorheight-100
screenres winwidth,winheight,,, GFX_NO_FRAME : Width winwidth\8, winheight\16 



Cls
mystring="abcdefghijklmnopqrstuvwxyz"
c=(int(int(winwidth/8)/len(mystring))-1)

For b = 1 to (winheight/16)
    For t = 0 to c  
        locate (b,1+(t*Len(mystring)))
        ' locate (b,) : locate (,1+(t*Len(mystring)))
        Print ; mystring ;
        
    next t
Next b


Sleep
coderJeff
Site Admin
Posts: 4342
Joined: Nov 04, 2005 14:23
Location: Ontario, Canada
Contact:

Re: "Locate" wrong position

Post by coderJeff »

Not a bug. Info added to Locate page:
Locate will attempt to position the cursor at the specified row and column. If the position is beyond the screen extents, cursor will not reposition. And next Print to the screen will continue at last valid cursor position. When printing to the last line of the screen, and the Print statement has a new line character, the screen will scroll and reposition the cursor automatically to the last line, column 1.
Joshua123
Posts: 3
Joined: May 22, 2018 19:59

Re: "Locate" wrong position

Post by Joshua123 »

coderJeff wrote:Not a bug. Info added to Locate page:
Locate will attempt to position the cursor at the specified row and column. If the position is beyond the screen extents, cursor will not reposition. And next Print to the screen will continue at last valid cursor position. When printing to the last line of the screen, and the Print statement has a new line character, the screen will scroll and reposition the cursor automatically to the last line, column 1.
Thank you so much.
Post Reply