Text on screen

New to FreeBASIC? Post your questions here.
PhiltheBear
Posts: 30
Joined: Jul 08, 2014 17:45

Text on screen

Post by PhiltheBear »

I've been usung FreeBasic for years - but basically for batch processing of large amounts of data. (I'm on Windows 64 version). If I write programs which require input I use the normal white on black screen which, after a CLS, starts from the top left of the screen. I would dearly love to make this a bit more useful and it's likely that someone has already done what I would like so I'm just putting this out there in hope - because I can't find anything relevant.

What I'd like to be able to do (in order) is:
Have a black on white screen
Be able to position at an x,y point on that screen to print or input text, ideally by line, character position and not by pixel co-ordinates
Be able to print individual text strings in colour

I'm quite happy with an 80w x 24h character screen using monoscript characters. I don't need to use a mouse on the screen.

Any ideas/solutions?
Vortex
Posts: 118
Joined: Sep 19, 2005 9:50

Re: Text on screen

Post by Vortex »

Hello,

Checking the FreeBASIC manual :

Code: Select all

Locate

Sets the current cursor position

Syntax

Declare Function Locate( row As Long = 0, column As Long = 0, state As Long = -1, start As Long = 0, stop As Long = 0 ) As Long
dodicat
Posts: 7976
Joined: Jan 10, 2006 20:30
Location: Scotland

Re: Text on screen

Post by dodicat »

Is it console or graphics screen?
Here are two quick example ways to do it:
graphics screen

Code: Select all


screen 19,32
color ,rgb(255,255,255) 'set whole screen white
cls

sub printcolouredtext(s as string,ypos as long,xpos as long)
      locate ypos,xpos
      for n as long=0 to len(s)-1
      color rgb(rnd*255,rnd*255,rnd*255)
      print chr(s[n]);
next n
print
end sub


printcolouredtext("Hello World!",5,5)
printcolouredtext("Goodbye!",15,5)
sleep 
Console

Code: Select all


shell "color f0"

sub printcolouredtext(s as string,ypos as long,xpos as long)
      locate ypos,xpos
      for n as long=0 to len(s)-1
            dim as long c=rnd*16
      color iif(c=15,0,c),15
      print chr(s[n]);
next n
print
end sub


printcolouredtext("Hello World!",5,5)

printcolouredtext("Goodbye!",15,5)

sleep 
PhiltheBear
Posts: 30
Joined: Jul 08, 2014 17:45

Re: Text on screen

Post by PhiltheBear »

Thank you guys. I'd just found the Locate function and am now experimenting. Thanks for getting back so quickly.
paul doe
Moderator
Posts: 1730
Joined: Jul 25, 2017 17:22
Location: Argentina

Re: Text on screen

Post by paul doe »

PhiltheBear wrote: Mar 27, 2022 9:46 ...
What I'd like to be able to do (in order) is:
Have a black on white screen
Be able to position at an x,y point on that screen to print or input text, ideally by line, character position and not by pixel co-ordinates
Be able to print individual text strings in colour
...
This snippet actually illustrates everything you need:

Code: Select all

function rng( aMin as long, aMax as long ) as long
  return( rnd() * ( aMax - aMin + 1 ) - 0.5d + aMin )
end function

dim as string text = "Hello!"

do
  '' Pick a random foreground and background color
  color rng( 0, 15 ), rng( 0, 15 )
  cls()
  
  '' Pick a random location and text color, and print some text
  for i as integer = 1 to 100
    locate rng( 1, 24 ), rng( 1, 79 - len( text ) ), 0
    color rng( 0, 15 )
  
    ? "Hello!"
  next
  
  sleep( 3, 1 )
loop until( len( inkey() ) )
The colors you have available on the console by default can be easily visualized for convenience:

Code: Select all

for i as integer = 0 to 15
  color , i
  ? "  ";
next

sleep()
speedfixer
Posts: 606
Joined: Nov 28, 2012 1:27
Location: CA, USA moving to WA, USA
Contact:

Re: Text on screen

Post by speedfixer »

Text in the graphics screen is much faster than native console and exactly like the native console.

It is easy to size and position that graphics console on any desktop. SCREENRES, SCREENCONTROL
You also get more flexibility with the colors.

With any of the font libraries, text sizing isn't too difficult. (Needed for us older people with BIG high def monitors.)
You just need a simple little char-to-pixel position function to make addressing easy that is missing from most of these font libs.
(One of the few missing features of FB needed to make FB more relevant in this modern time.)

david
PhiltheBear
Posts: 30
Joined: Jul 08, 2014 17:45

Re: Text on screen

Post by PhiltheBear »

I'll own up to the fact that my use of BASIC goes back to a version of the original by Kemeny & Kurtz (circa 50 years ago). Their idea was to produce a simple language which was easily understood by the programmer and, in those days, was interpreted rather than compiled. It was also basically for engineers and had fantastic matrix support. I don't work with graphics and have no great interest in doing so. My field has generally been concerned with business applications which require data input and the generation of formatted output e.g. bank statements, invoices, etc. To me inputting using a mouse to go from item to item slows things down so much that when high volumes are being input it becomes totally impractical. Having said that I can see the need for graphics processing for those that need it. What I do think is a problem is that the original simplicity of the language is getting lost. When I started looking to solve this little problem here I looked firstly at SCREEN and then the other things that followed it in the keywords list. Frankly, it's a nightmare. I would expect, for example, SCREEN(CONSOLE) to be a way of specifying a console type screen of x,y dimensions, possibly with something which indicated an overall size such as a character size or a fixed pixel size and perhaps a background colour. What I didn't expect was something that told me what a particular character colour at a location was. The info on the SCREEN page almost made me lose the will to live particularly when it suggests that SCREENRES is 'more flexible'.

Where has the simplicity gone? Thankfully, there are comparatively silver linings in the LOCATE and COLOR keywords which allow me to do what I wanted. I agree with David that the use of larger screens would be useful - but it needs to be simple. Certainly, what's available lets me produce a nice big screen - but the character size is exactly the same as on a small screen - and the small screen is nigh on impossible to read.

Now for my next task - to make the first screen disappear so that ony the new super colour screen is visible. (I'm sure there is a simple solution, even if there's no simple explanation). Thank you for reading and for your assistance.
dodicat
Posts: 7976
Joined: Jan 10, 2006 20:30
Location: Scotland

Re: Text on screen

Post by dodicat »

You have options
#lang "fblite"
(like older basic)
#lang "qb"
(like quickbasic)

The language has to evolve, but many old keywords still apply.
Graphics was always a part of basic, quickbasic, BBC basic, even zx basic (Sinclair spectrum).
Kemeny & Kurtz I don't know about.

Code: Select all


sub printcolouredtext(s as string,ypos as long,xpos as long)
      locate ypos,xpos
      for n as long=0 to len(s)-1
            dim as long c=rnd*16
      color iif(c=15,0,c),15
      print chr(s[n]);
next n
print
end sub

sub printtext(s as string,ypos as long,xpos as long,forecolour as ulong,backcolour as ulong)
      locate ypos,xpos
      color forecolour,backcolour
      print s
end sub

Sub changeconsolesize(cols As Long,lines As Long)
    Shell "MODE CON: COLS="+Str(cols)+ "LINES="+Str(lines)
End Sub

shell "color f0"
changeconsolesize(150,70)

for n as long=1 to 50
      var k=n
      if n mod 15=0  then k=0
      printtext(str(n)+"  "+str(n*1000),n,1,k,15)
next
printtext("press a key",csrlin,pos,0,15)



sleep
changeconsolesize(100,20)
printcolouredtext("Hello World!",5,15)
printcolouredtext("Goodbye!",8,15)
sleep
 
paul doe
Moderator
Posts: 1730
Joined: Jul 25, 2017 17:22
Location: Argentina

Re: Text on screen

Post by paul doe »

PhiltheBear wrote: Mar 27, 2022 18:12 ...
I would expect, for example, SCREEN(CONSOLE) to be a way of specifying a console type screen of x,y dimensions, possibly with something which indicated an overall size such as a character size or a fixed pixel size and perhaps a background colour.
Font size on the console is controlled by the OS, not the application.
...
Where has the simplicity gone?
...
Down the drain since desktop computers nowadays are supercomputers compared to the mainframes from 50 years ago.
...
Thankfully, there are comparatively silver linings in the LOCATE and COLOR keywords which allow me to do what I wanted. I agree with David that the use of larger screens would be useful - but it needs to be simple.
...
Setting a screen mode in FreeBasic is just one function call (screenRes( xRes, yRes, bitDepth )). How much more 'simplicity' do you need?
dodicat
Posts: 7976
Joined: Jan 10, 2006 20:30
Location: Scotland

Re: Text on screen

Post by dodicat »

To change the console font, some win api functions are required.

Code: Select all

#include "windows.bi"
shell "color f0" 'white background screen

Sub getfontsize(x as _CONSOLE_FONT_INFOEX)
        x.cbsize=Sizeof(_CONSOLE_FONT_INFOEX)
    getcurrentconsolefontex(GetStdHandle(STD_OUTPUT_HANDLE),false, @x )
End Sub

Sub changefontsize(w As Long, h As Long,ftype As String="consolas")
    Dim As  _CONSOLE_FONT_INFOEX  x
    With x
        .cbsize=Sizeof(_CONSOLE_FONT_INFOEX)
        .nfont=0
        .dwfontsize=Type(w,h)
        .fontfamily=0
        .fontweight=100
        .facename=ftype
    End With
    setcurrentconsolefontex(GetStdHandle(STD_OUTPUT_HANDLE),1, @x )
End Sub

sub printcolouredtext(s as string,ypos as long,xpos as long)
      locate ypos,xpos
      for n as long=0 to len(s)-1
            dim as long c=rnd*16
      color iif(c=15,0,c),15
      print chr(s[n]);
next n
print
end sub

sub printtext(s as string,ypos as long,xpos as long,forecolour as ulong,backcolour as ulong)
      locate ypos,xpos
      color forecolour,backcolour
      print s
end sub

dim as  _CONSOLE_FONT_INFOEX f

getfontsize(f)

changefontsize(3*f.dwfontsize.x,3*f.dwfontsize.y)
setwindowpos(getconsolewindow(),HWND_TOPMOST,20,20,800,600,0)


'some options
'Var sysMenu = GetSystemMenu(p, False)
'DeleteMenu(sysMenu, SC_CLOSE, MF_BYCOMMAND)    'cannot close console with close btn
'DeleteMenu(sysMenu, SC_MINIMIZE, MF_BYCOMMAND) 'To prevent user from minimizing console window
'DeleteMenu(sysMenu, SC_MAXIMIZE, MF_BYCOMMAND)'To prevent user from maximizing console window
'DeleteMenu(sysMenu, SC_SIZE, MF_BYCOMMAND)    'non resizable console



for n as long=1 to 500
      var k=n mod 15
      printtext(str(n)+"  "+str(sqr(n*1000)),n,1,k,15)
next




printcolouredtext("Goodbye!, press any key ...",csrlin,pos)

sleep

 
srvaldez
Posts: 3373
Joined: Sep 25, 2005 21:54

Re: Text on screen

Post by srvaldez »

excellent dodicat :)
PhiltheBear
Posts: 30
Joined: Jul 08, 2014 17:45

Re: Text on screen

Post by PhiltheBear »

dodicat wrote: Mar 27, 2022 21:52 Kemeny & Kurtz I don't know about.
Kemeny and Kurtz were two staff members at Dartmouth College in the USA in the 1960s. They created BASIC.

Here's a link that may be of interest: https://www.historyofinformation.com/detail.php?id=815

There's a whole load of information about what they did (other than just invent BASIC) here: https://en.wikipedia.org/wiki/Dartmouth ... ing_System

However, the simple fact is that BASIC was always meant to be simple and the fact that modern computers are faster and have added abilities is really irrelevant to the concept of simplicity. BASIC was, despite the Wikipedia article claiming no proof, implemented on a Digital Equipment Company's PDP1 machine as the first computer outside the Dartmouth time-sharing system and was made commercially available by DEC on their PDP/11 computers in the late 60s. In the early 70's Bll Gates and Paul Allen ported Basic on a DEC PDP/10 to Altair computers using a DOS then known as CPM. This was the first Microsoft (and pretty much the only) product in the early days. Gates acquired the rights to what became MS-DOS from another company after he was approached by IBM to provide an operating system. (A different company with a better DOS, called DR-DOS, was also approached but didn't believe it was IBM who called and thus lost out). IBM already had a computer prior to the PC on which they implemented and sold systems with CPM and MIcrosoft's BASIC. When IBM launched their PC the price was high and as Microsoft had leased MSDOS and BASIC to them they could also lease it elsewhere - hence the reason that early PCs all had MSDOS and the differing versions of BASIC.

My background for this - I implemented several commercial systems on the DEC PDP/11 computers (some people may remember Dateline - sorry but that was mine). I wrote some software for the Altair. I imported the first IBM computer into the UK - before IBM UK had it - and I worked on the IBM pre-cursor to the PC. If you remember Byte and Kilobaud magazines, my company at the time produced an accounting package for PCs sold under their name. That same package was used worldwide by companies like Pepsi. This was all done using BASIC in various guises. The major commonality - it was all simple to do. The only reason for BASIC to evolve is to be able to provide the functionality required. That's fine and so it should. But that doesn't mean a level of complication that is unnecessary. How many versions of SCREEN with different parameters are there in FreeBasic? Why jettison the perfectly good FIELD usage for an overly complicated TYPE usage? It doesn't keep BASIC simple - it's just change for the sake of it and it's really not necessary. More to the point, it's not desirable. FreeBasic is, without doubt, the best of the Basics now available but it has moved away from what BASIC is supposed to be.

Hint - Beginner’s All-Purpose Symbolic Instruction Code.
paul doe
Moderator
Posts: 1730
Joined: Jul 25, 2017 17:22
Location: Argentina

Re: Text on screen

Post by paul doe »

Thanks for the history lesson. Mind that it is just that: history.
PhiltheBear wrote: Mar 28, 2022 18:26 ...
FreeBasic is, without doubt, the best of the Basics now available but it has moved away from what BASIC is supposed to be.
...
Says who? A bunch of people that used to be someone in the 60's and feel left behind? Visual Basic is the current de-facto standard for Basic languages, not some dialect from 60 years ago. Oh and for the record, Visual Basic has been all but abandoned by Microsoft.
...
Hint - Beginner’s All-Purpose Symbolic Instruction Code.
We've had this same (pointless) argument many times before. Here's the thing: FreeBasic does not have to follow any design philosophy, nor abide to any acronym whatsoever. It started as a way to have QuickBasic code compile in modern 32-bit OSses, but has evolved far beyond that. Some people might not like that, but it is what it is. If that's not 'BASIC' enough, there are alternatives.
Imortis
Moderator
Posts: 1923
Joined: Jun 02, 2005 15:10
Location: USA
Contact:

Re: Text on screen

Post by Imortis »

PhiltheBear wrote: Mar 28, 2022 18:26 ...
Hint - Beginner’s All-Purpose Symbolic Instruction Code.
I want to say this as respectfully as I can, but I am unsure how to say it without sounding snarky. Please know that is not my intention.

The BASIC acronym has little bearing on this argument because, invariably, the person who uses it is not a beginner. All of them, every single one of them, is someone with past programming experience, either in older versions of BASIC or in more modern variations, who is unhappy that their experience is not as useful as they would have hoped with FreeBASIC. The fact is, that any time you move from one language to another, no matter how simple or beginner friendly that new language is, you have to unlearn/relearn things from that previous experience.

True beginners have nothing to unlearn. I have taught a handful of complete beginners programming concepts with FreeBASIC. It works for beginners just as well as any other BASIC variant.
grindstone
Posts: 862
Joined: May 05, 2015 5:35
Location: Germany

Re: Text on screen

Post by grindstone »

@PhiltheBear:
That's the great of freeBasic, and the main reason why I like it: It is both simple and sophisticated, just as you want. For an absolute beginner it takes less than 10 minutes to get a "Hello world" printout, on the other hand you could write an operating system with it.

Coding with FB can be still as simple as in the 60's. If you don't like the improvements made within the last 6 decades, then just don't use them. It will work anyway (on a 60's level, of course) :D
Post Reply