Displaying data on screen

General FreeBASIC programming questions.
Gablea
Posts: 1049
Joined: Apr 06, 2010 0:05
Location: Northampton, United Kingdom
Contact:

Displaying data on screen

Postby Gablea » May 08, 2019 19:37

hi Everyone,

I hope everyone is well

I would like some guidance on the following that I have been trying to work out.

I have the following screen
Image

what I am after is advice on the following

1. how would i display data on the screen so they line up with the headers that are all ready created.
Like example beloew
Image


2. how would i handle large qty of display data (I was thinking something like "pages")

I am assuming I would have to handle my own highlighting code (to show a box around the line that is select) or would it be better to use a ►to show what line is being selected?

I would appreciate it if someone could point me in the direction that i need to go (or if you have a sample code that i can read to understand the code) It would be appreciated
badidea
Posts: 1609
Joined: May 24, 2007 22:10
Location: The Netherlands

Re: Displaying data on screen

Postby badidea » May 08, 2019 20:17

1) like so?

Code: Select all

#include "string.bi"

enum H_ALIGN
   H_ALIGN_LEFT
   H_ALIGN_RIGHT
end enum

sub printAt(x as integer, y as integer, text as string, align as H_ALIGN)
   if align = H_ALIGN_RIGHT then x -= len(text)
   locate y, x
   print text;
end sub

dim as integer xOffset = 30, yOffset = 5
dim as integer x, y
dim as string priceStr, headerStr = "Price"

randomize timer
printAt(xOffset, yOffset, headerStr, H_ALIGN_RIGHT)
for y = 1 to 10
   priceStr = format(10 ^ (rnd * 5), "0.00")
   printAt(xOffset + x, yOffset + y, priceStr, H_ALIGN_RIGHT)
next

2) Pages or scroll with scrollbar. Pages easier. (buttons/commands: first page, previous page, next page, last page)
badidea
Posts: 1609
Joined: May 24, 2007 22:10
Location: The Netherlands

Re: Displaying data on screen

Postby badidea » May 08, 2019 20:38

I might have discovered a bug in Freebasic.
OK: priceStr = format(10 ^ (rnd * 5), "$0.00")
Not OK: priceStr = format(10 ^ (rnd * 5), "£0.00")

Edit: Not a bug, but unwanted behaviour. Solved by conversion to wstring:

Code: Select all

#include "string.bi"

enum H_ALIGN
   H_ALIGN_LEFT
   H_ALIGN_RIGHT
end enum

sub printAt(x as integer, y as integer, text as wstring, align as H_ALIGN)
   if align = H_ALIGN_RIGHT then x -= len(text)
   locate y, x
   print text;
end sub

dim as integer xOffset = 30, yOffset = 5
dim as integer x, y
dim as string priceStr, headerStr = "Price"

randomize timer
printAt(xOffset, yOffset, headerStr, H_ALIGN_RIGHT)
for y = 1 to 10
   priceStr = format(10 ^ (rnd * 5), "£0.00")
   printAt(xOffset + x, yOffset + y, priceStr, H_ALIGN_RIGHT)
next
dodicat
Posts: 6013
Joined: Jan 10, 2006 20:30
Location: Scotland

Re: Displaying data on screen

Postby dodicat » May 08, 2019 21:31

That is ultra neat Badidea.
And getting the £ sign to show properly also.
badidea
Posts: 1609
Joined: May 24, 2007 22:10
Location: The Netherlands

Re: Displaying data on screen

Postby badidea » May 08, 2019 21:53

dodicat wrote:That is ultra neat Badidea.
And getting the £ sign to show properly also.

Thanks, works with the (3-wide) € sign as well, but it seems that you guys at the other side of the North Sea don't have to worry about that anytime soon.
badidea
Posts: 1609
Joined: May 24, 2007 22:10
Location: The Netherlands

Re: Displaying data on screen

Postby badidea » May 08, 2019 22:57

An option for question 2.
Keys "Page up", "page down", "home", "end" left as an exercise for the reader.

Code: Select all

#include "string.bi"

enum H_ALIGN
   H_ALIGN_LEFT
   H_ALIGN_RIGHT
end enum

sub printAt(x as integer, y as integer, text as wstring, align as H_ALIGN)
   if align = H_ALIGN_RIGHT then x -= len(text)
   locate y, x
   print text;
end sub

const as string KEY_UP = chr(255) & "H"
const as string KEY_DN = chr(255) & "P"
const as string KEY_PGUP = chr(255) & "I"
const as string KEY_PGDN = chr(255) & "Q"
const as string KEY_ESC = chr(27)

function waitForKey() as string
   dim as string key = inkey
   while key = ""
      key = inkey
      sleep 1,1
   wend
   return key
end function

dim as string keyword(...) => {"Abs","Abstract","Access","Acos","Add","Alias","Allocate","Alpha","And","AndAlso","Append","As","Assert","AssertWarn","Asc","Asin","Asm","Atn","Base","Beep","Bin","Binary","Bit","BitReset","BitSet","BLoad","BSave","ByRef","ByVal","Call","CAllocate","Case","Cast","CByte","CDbl","cdecl","Chain","ChDir","Chr","CInt","Circle","Class","Clear","CLng","CLngInt","Close","Cls","Color","Command","Common","CondBroadcast","CondCreate","CondDestroy","CondSignal","CondWait","Const","Constructor","Continue","Cos","CPtr","CShort","CSign","CSng","CsrLin","CUByte","CUInt","CULng","CULngInt","CUnsg","CurDir","CUShort","Custom","CVD","CVI","CVL","CVLongInt","CVS","CVShort","Data","Date","DateAdd","DateDiff","DatePart","DateSerial","DateValue","Day","Deallocate","Declare","DefByte","DefDbl","defined","DefInt","DefLng","DefLongInt","DefShort","DefSng","DefStr","DefUByte","DefUInt","DefULongInt","DefUShort","Delete","Destructor","Dim","Dir","Do","Draw","DyLibFree","DyLibLoad","DyLibSymbol","Else","ElseIf","Encoding","End","EndIf","Enum","Environ","EOF","Eqv","Erase","Erfn","Erl","Ermn","Err","Error","Event","Exec","ExePath","Exit","Exp","Export","Extends","Extern","False","Field","FileAttr","FileCopy","FileDateTime","FileExists","FileLen","Fix","Flip","For","Format","Frac","Fre","FreeFile","Function","Get","GetJoystick","GetKey","GetMouse","GoSub","Goto","Hex","HiByte","HiWord","Hour","If","IIf","ImageConvertRow","ImageCreate","ImageDestroy","ImageInfo","Imp","Implements","Import","Inkey","Inp","Input","InStr","InStrRev","Int","Is","IsDate","IsRedirected","Kill","LBound","LCase","Left","Len","Let","Lib","Line","LoByte","Loc","Local","Locate","Lock","LOF","Log","Loop","LoWord","LPOS","LPrint","LSet","LTrim","Mid","Minute","MKD","MkDir","MKI","MKL","MKLongInt","Mks","MkShort","Mod","Month","MonthName","MultiKey","MutexCreate","MutexDestroy","MutexLock","MutexUnlock","Naked","Name","Namespace","Next","New","Not","Now","Oct","OffsetOf","On","Once","Open","Operator","Option","Or","OrElse","Out","Output","Overload","Override","Paint","Palette","pascal","PCopy","Peek","PMap","Point","PointCoord","Poke","Pos","Preserve","PReset","Print","Private","ProcPtr","Property","Protected","PSet","Public","Put","Random","Randomize","Read","Reallocate","ReDim","Rem","Reset","Restore","Resume","Return","RGB","RGBA","Right","RmDir","Rnd","RSet","RTrim","Run","SAdd","Scope","Screen","ScreenCopy","ScreenControl","ScreenEvent","ScreenInfo","ScreenGLProc","ScreenList","ScreenLock","ScreenPtr","ScreenRes","ScreenSet","ScreenSync","ScreenUnlock","Second","Seek","Select","SetDate","SetEnviron","SetMouse","SetTime","Sgn","Shared","Shell","Shl","Shr","Sin","SizeOf","Sleep","Space","Spc","Sqr","Static","stdcall","Step","Stick","Stop","Str","Strig","StrPtr","Sub","Swap","System","Tab","Tan","Then","This","ThreadCall","ThreadCreate","ThreadDetach","ThreadWait","Time","TimeSerial","TimeValue","Timer","To","Trans","Trim","Type","Typeof","UBound","UCase","Union","Unlock","Until","Using","Val","ValLng","ValInt","ValUInt","ValULng","Var","VarPtr","View","Virtual","Wait","WBin","WChr","WeekDay","WeekDayName","Wend","While","WHex","Width","Window","WindowTitle","WInput","With","WOct","Write","WSpace","WStr","Xor","Year"}
dim as integer firstKw, selKw, viewSel, pageSize = 15
dim as string key
dim as string displayText
print ubound(keyword)
locate ,,0 'disable cursor
while 1
   printAt(1, 1, "viewSel: " + format(viewSel, "000"), H_ALIGN_LEFT)
   printAt(1, 2, "firstKw: " + format(firstKw, "000"), H_ALIGN_LEFT)
   printAt(1, 3, "selKw  : " + format(selKw, "000"), H_ALIGN_LEFT)
   printAt(80, 1, "keys: UP, DOWN, ESC", H_ALIGN_RIGHT)
   displayText = string(20, " ")
   mid(displayText, 1) = keyword(selKw)
   printAt(1, 24, "keyword: " + displayText, H_ALIGN_LEFT)

   printAt(30, 5, "KEYWORD", H_ALIGN_LEFT)
   for i as integer = 0 to pageSize-1
      displayText = string(20, ".")
      mid(displayText, 1) = keyword(i + firstKw)
      if i = viewSel then color 0, 7
      printAt(30, 5 + 1 + i, displayText, H_ALIGN_LEFT)
      color 7, 0
   next

   key = waitForKey()
   select case key
   case KEY_UP
      viewSel -= 1
      if viewSel < 0 then
         viewSel = 0
         firstKw -= 1
         if firstKw < 0 then firstKw = 0
      end if
   case KEY_DN
      viewSel += 1
      if viewSel > pageSize - 1 then
         viewSel = pageSize - 1
         firstKw += 1
         if firstKw > ubound(keyword) - (pageSize - 1) then
            firstKw = ubound(keyword) - (pageSize - 1)
         end if
      end if
   case KEY_PGUP
   case KEY_PGDN
   case KEY_ESC
      exit while
   end select
   selKw = firstKw + viewSel
wend
Gablea
Posts: 1049
Joined: Apr 06, 2010 0:05
Location: Northampton, United Kingdom
Contact:

Re: Displaying data on screen

Postby Gablea » May 08, 2019 23:00

thanks for the example code

how would i deal with say 1,00 products (with a limited number on screen)
paul doe
Posts: 979
Joined: Jul 25, 2017 17:22
Location: Argentina

Re: Displaying data on screen

Postby paul doe » May 08, 2019 23:05

Gablea wrote:thanks for the example code

how would i deal with say 1,00 products (with a limited number on screen)

Didn't badidea's code in the previous post already answered this?
Gablea
Posts: 1049
Joined: Apr 06, 2010 0:05
Location: Northampton, United Kingdom
Contact:

Re: Displaying data on screen

Postby Gablea » May 08, 2019 23:12

opps my bad I did not see that one
badidea
Posts: 1609
Joined: May 24, 2007 22:10
Location: The Netherlands

Re: Displaying data on screen

Postby badidea » May 08, 2019 23:34

If the systems have a graphical screen, a gui toolkit like fltk may be easier. Making all these text based interfaces is a lot of work.
Gablea
Posts: 1049
Joined: Apr 06, 2010 0:05
Location: Northampton, United Kingdom
Contact:

Re: Displaying data on screen

Postby Gablea » May 08, 2019 23:57

A GUI would be easier but it would mean learning how to use the tool kit.

The software is still crashing with just the text interface (I’m working on that)

The tool kits only aim at Linux and windows I would like to also support DOS (if anyone knows of a gui tool kit that works on dos I’ll be interested in looking at it)
paul doe
Posts: 979
Joined: Jul 25, 2017 17:22
Location: Argentina

Re: Displaying data on screen

Postby paul doe » May 09, 2019 0:31

Gablea wrote:A GUI would be easier but it would mean learning how to use the tool kit.

The software is still crashing with just the text interface (I’m working on that)

The tool kits only aim at Linux and windows I would like to also support DOS (if anyone knows of a gui tool kit that works on dos I’ll be interested in looking at it)

If you're doing this in DOS, why not use a proper DMS, like those based on xBase , or FoxPro? Why are you doing this in plain FreeBasic is anyones' guess, especially given that you'll have to implement the TUI basically from scratch. Not to mention, console emulation in FreeBasic is too slow atm (if you want more performance, you'll either have to implement the console in a VGA mode, or use a library like ncurses)
Gablea
Posts: 1049
Joined: Apr 06, 2010 0:05
Location: Northampton, United Kingdom
Contact:

Re: Displaying data on screen

Postby Gablea » May 09, 2019 9:03

The only reason why i was using DOS was because I know how to set up the autoexec

I would use Debian in frame buffer mode but I have no idea how to auto start a program in Linux.

and I would have to learn how to use FoxPro (as I know FoxPro does have a interface that can act like a Program) I am using plan FB as it's a language I know (I was thinking about using VBDOS but I keep hitting the 640KB limit with the apps I make in that)
paul doe
Posts: 979
Joined: Jul 25, 2017 17:22
Location: Argentina

Re: Displaying data on screen

Postby paul doe » May 09, 2019 10:30

Gablea wrote:...
and I would have to learn how to use FoxPro (as I know FoxPro does have a interface that can act like a Program) I am using plan FB as it's a language I know (I was thinking about using VBDOS but I keep hitting the 640KB limit with the apps I make in that)

Fair enough, but do you really need an entire TUI for your program? How much functionality do you need, anyway? Perhaps some simple form generator will suffice. I did a lot of PoS/DB/Custom programs when I was in middle school to make a buck (mostly in BASICA, GW-BASIC, and FoxPro/dBase), and seldom needed a fully functional TUI (with overlapping windows and such). Eventually we (I worked with a lifelong friend on this 'endeavor' =D) did develop a full TUI, but by that time we had already moved to Win95 and never really looked back.
Gablea
Posts: 1049
Joined: Apr 06, 2010 0:05
Location: Northampton, United Kingdom
Contact:

Re: Displaying data on screen

Postby Gablea » May 09, 2019 10:48

most of what I need is just basic input screens etc that was why I though of the TUI for this project

Here in the UK we have a gap between manual cash registers and to of the range EPoS systems and nothing in between hence why I want to design this app (so small business can have the advantage of EPoS but not the cost)

I would love to hear your thoughts on the idea of PoS and any input you can offer Paul I would welcome it

I will admit My FB Skills are no as solid as my VB.net skills. (my app still crashes sometimes even when it is on the "signed off" screen)

Hell its getting to a point now where I want to Pay someone to debug my app and correct anything I have done wrong

Return to “General”

Who is online

Users browsing this forum: No registered users and 1 guest