Page 1 of 1

SCREEN Navigation??

Posted: Mon Apr 07, 2008 6:18 pm
by NuKMaN
Need some help on how to create a on screen navigation. I am pulling information from a flat file in the following format:
100:job1
200:job3
400:job6

I know how to capture keys using the inkey command, but what I am wanting to do is have the first line (from flat file) highlighted and allow the user to navigate to the line they want by using the arrow keys.

My other problem is once they pick the line they want, how do I get the information from the screen on that line?

Thanks Peps!

Posted: Wed Apr 09, 2008 8:55 am
by pebe
Can you explain what you mean by

100:job1
200:job3
400:job6

Also does 'flat file' = sequential file?

Posted: Wed Apr 09, 2008 5:38 pm
by NuKMaN
it is a dat file that has that content in it. That is a example of what each line in the file looks like

Posted: Wed Apr 09, 2008 9:17 pm
by pebe
Is it a simple comma delimited file like this?

......,100:job1,200:job3,400:job6,...

Posted: Wed Apr 09, 2008 9:51 pm
by NuKMaN
no
the file name is plants.dat
each line in the file are just like below:

100:benhill
300:athens
400:lithonia


the 3 lines above is exactly what is in the file. I am able to pull the information from it and sort on the screen, but I'm not sure where to go from there.

Posted: Thu Apr 10, 2008 12:29 pm
by Mac
Well, that is strange "data" to read from a file.

A "flat file" is a file that has no structure. Most
files are like that.



A typical file has ".dat" at the end such as "States.dat" but it doesn't have to. I could name it "States.exe" if I wanted to. Maybe I do that to trick snoopy sibling. If it is clicked on, it gets an error. Only I know to use "NOTEPAD states.exe"

Nearly all data files used in QBasic applications are "flat files". That just means that the data has no complicated format such as "indexed sequential" or binary.

A typical "flat file" could be "States.dat" containing
AL ALABAMA
AK ALASKA
AS AMERICAN SAMOA
AZ ARIZONA
... etc.

But the subject of your post is impossibly broad. Ask for help in small units so we have some hope of answering.

Here is a bad question because it is too broad
=========================================
=========================================
I have a file, "Plants.dat", containing these three lines:
100:job1
200:job3
400:job6

I would like to read that file and make those three lines appear as a list to navigate. It would start with the first line highlighted. Pressing the up-arrow should unlight current line and highlight the one over it until eventually the user is stuck in the top line.

The reverse for the down-arrow.

When the user presses [Enter], the program should do stuff depending on which line is highlighted.
=========================================
=========================================

Much too broad. Your question looks like homework, which nobody on this or any forum in the internet will honor.

Ask rather questions like
=========================================
=========================================
How can I tell if the up-arrow or down-arrow keys have been pressed? Also the [Enter] and [Esc]
=========================================
=========================================

That can be answered

CLS
PRINT "Use up-arrow, down-arrow, [Enter], or [Esc] only"
PRINT
DO
  DO: k$ = INKEY$: LOOP WHILE k$ = ""
  IF LEN(k$) = 2 THEN
    IF ASC(RIGHT$(k$, 1)) = 72 THEN
      PRINT "Up has been pressed"
    ELSEIF ASC(RIGHT$(k$, 1)) = 80 THEN
      PRINT "Down has been pressed"
    ELSE
      PRINT "You goofed!"
    END IF
  ELSE
    IF ASC(k$) = 13 THEN
      PRINT "[Enter] has been pressed"
    ELSEIF ASC(k$) = 27 THEN
      PRINT "[Esc] has been pressed"
      EXIT DO
    ELSE
      PRINT "You goofed!"
    END IF
  END IF
LOOP
PRINT : PRINT : PRINT "Successful run"
END

Any more questions for this thread?

Posted: Mon Apr 14, 2008 5:19 pm
by Mac
You get all the help you needed?

Posted: Mon Apr 14, 2008 6:31 pm
by NuKMaN
Not really, I am told my question is not direct enough. So let me start over. Once I get information onto the screen for a user, how do I add navigation to the screen. When I say navigation: The user is able to use the arrow keys to move a highlighted area to the line they want.

Once this is accomplished, I need to be able to take the information on that line (on the screen) and save it to a var$ for later use.

Posted: Mon Apr 14, 2008 7:07 pm
by pebe
It depends on how you got the information on to the screen in the first place - which is why I asked you which file type you are using. I can think of at least 3 ways you could have written "100:job1" to the screen from data in a file, and how you deal with the data depends on that.

If it uses a random access file then you can relate the highlighted line to a position in the file and gain instant access to it.

If it is a sequential file you really need to keep an array for each line written to the screen, so you can identify what it was.

Can you state how you picked up each line from the file and printed it to the screen?

Posted: Mon Apr 14, 2008 8:09 pm
by NuKMaN
Sure, I'll post that section of the code:

'LOAD PLANTS FROM FILE TO SCREEN
FH = FREEFILE
CL% = 3
CN% = 1
CT% = 9

OPEN "PLANTS.DAT" FOR INPUT AS #FH
DO WHILE NOT EOF(FH)
LINE INPUT #FH, INP$
Y = INSTR(INP$, ":")
IF Y = 0 THEN STOP
L = Y - 1
R = Y + 1

IF CN% < 11 THEN

LOCATE CT%, 3: COLOR 4, 0: PRINT "........................."
LOCATE CT%, 3: COLOR 4, 0: PRINT CN%; CHR$(28); LEFT$(INP$, L); "-"; MID$(INP$, R)
COLOR 14, 1
IF CN% = 10 THEN CT% = 8
ELSEIF CN% > 10 AND CN% < 21 THEN
LOCATE CT%, 29: COLOR 4, 0: PRINT "........................"
LOCATE CT%, 29: COLOR 4, 0: PRINT CN%; CHR$(28); LEFT$(INP$, L); "-"; MID$(INP$, R)
COLOR 14, 1
IF CN% = 20 THEN CT% = 8
ELSEIF CN% > 20 AND CN% < 31 THEN
LOCATE CT%, 54: COLOR 4, 0: PRINT "........................"
LOCATE CT%, 54: COLOR 4, 0: PRINT CN%; CHR$(28); LEFT$(INP$, L); "-"; MID$(INP$, R)
COLOR 14, 1

END IF
CT% = CT% + 1
CN% = CN% + 1
LOOP
LOCATE 20, 2: PRINT "SELECT THE PLANT TO DELETE/EDIT ABOVE THEN PRESS <ENTER>"
CLOSE FH%
LOCATE 21, 60: COLOR 7, 1: PRINT "®ESC¯ RETURN TO MAIN": COLOR 14, 1
'---------------------------------------------------------------------------------

Posted: Mon Apr 14, 2008 9:24 pm
by pebe
I'll come up with answers for you in a couple of days.

Posted: Tue Apr 15, 2008 8:56 pm
by pebe
I noted that your program had 30 records displayed on the screen as 10 rows of 3 records each. I didn't have your file to input from so I made up a sample one. I've tried to keep to the same layout.

All 30 records are input from file into a fixed length string array - they are easier to manipulate that way. The up/down cursor keys move the highlight through the list using the sub 'display'. <ENTER> ends the program with the value of CN% pointing to the array holding the wanted record.

I hope that's what you want. BTW,There's something wrong with your LOCATE statement for Line21. It overflows.

Code: Select all

DIM SHARED inline(30) AS STRING * 18
DECLARE SUB display (CN%)

OPEN "fildata" FOR OUTPUT AS #1   'make a sample file
a$ = "This is record"
FOR n% = 1 TO 30
  PRINT #1, a$; n%
NEXT
CLOSE
CLS

OPEN "fildata" FOR INPUT AS #1
CN% = 0
DO
  CN% = CN% + 1
  LINE INPUT #1, a$
  inline(CN%) = a$
LOOP WHILE NOT EOF(1)
CLOSE
maxCN% = CN% 

FOR CN% = 1 TO 30
  IF CN% = 1 THEN COLOR 4, 7 ELSE COLOR 4, 0
  CALL display(CN%)
NEXT
CN% = 1

COLOR 14, 1
LOCATE 20, 2: PRINT "SELECT THE PLANT TO DELETE/EDIT ABOVE THEN PRESS <ENTER>"

LOCATE 21, 60: COLOR 7, 1: PRINT "<ESC> TO RETURN TO MENU": COLOR 14, 1
''''''''''''End of initial display''''''''''''''''''''''.

''''''''' This to move the highlight and select the line'''''''''''''
DO
  k$ = INKEY$
  IF k$ <> "" THEN
    SELECT CASE k$
      CASE IS = CHR$(0) + CHR$(72)     'cursor up
        IF CN% <> 1 THEN NewCN% = CN% - 1
        COLOR 4, 0
        CALL display(CN%)  'print old file with black background
        CN% = NewCN%
        COLOR 4, 7
        CALL display(CN%)  'print new file with white background
      CASE IS = CHR$(0) + CHR$(80)     'cursor down
        IF CN% <> maxCN% THEN NewCN% = CN% + 1
        COLOR 4, 0
        CALL display(CN%)  'print old file with black background
        CN% = NewCN%
        COLOR 4, 7
        CALL display(CN%) 'print new file with white background
      CASE IS = CHR$(27)  'Escape
        GOTO action1
      CASE IS = CHR$(13)  'Return
        GOTO action2
    END SELECT
  END IF
LOOP

action1: 'program here for 'ESC' pressed
  
action2: LOCATE 24, 20: PRINT "Line Selected:- "; inline(CN%);
END

SUB display (CN%)
SELECT CASE CN%
  CASE IS < 11
    hor% = 3
    vert% = CN% + 2
  CASE IS < 21
    hor% = 29
    vert% = CN% - 8
  CASE IS < 31
    hor% = 54
    vert% = CN% - 18
END SELECT
LOCATE vert%, hor%: PRINT inline(CN%)
END SUB

Posted: Mon Apr 21, 2008 8:44 am
by pebe
NuKMAN, was that what you wanted?

Posted: Sat May 03, 2008 6:28 pm
by NuKMaN
Thanks Pebe.....

and yes this works great