Page 1 of 1

Arrow menues

Posted: Wed Jul 01, 2009 11:57 am
by izidor
Why sometimes one key press isn't enough?

Code: Select all

locate 1,4
print "goo"
locate 2,4
print "goo"
locate 1,1
print ">"
do
    if INKEY$ = chr$(0) + chr$(72) then cursor = 1
    if INKEY$ = chr$(0) + chr$(80) then cursor = 2

if cursor = 1 then
locate 1,1
print ">"
locate 2,1
print " "

elseif cursor = 2 then

locate 2,1
print ">"
locate 1,1
print " "
elseif INKEY$ = chr$(0) + chr$(72) AND cursor = 1 then cursor = 1
elseif INKEY$ = chr$(0) + chr$(80) AND cursor = 2 then cursor = 2
end if
loop

Posted: Wed Jul 01, 2009 2:43 pm
by burger2227
Because you use INKEY$ many times. Eliminate the 2 ElseIF's. That is just repetition.

To best read one press, use an INKEY$ variable. Like K$ = INKEY$ at start of loop. Then use the variable in the 2 keypress statements. INKEY$ only holds a keypress until it is read once!

Posted: Wed Jul 01, 2009 2:55 pm
by izidor
Yes! That's exactly what I wanted!
Thanks!

And btw Q-Basics is great!

Posted: Wed Jul 01, 2009 2:59 pm
by burger2227
Thanks. But it seems like it will never be done! I keep finding more to add.

Posted: Thu Jul 09, 2009 10:11 am
by izidor

Code: Select all

locate 1,4
print "goo"
locate 2,4
print "goo"
locate 1,1
print ">"

do
K$ = INKEY$
    if K$ = chr$(0) + chr$(72) then cursor = 1
    if K$ = chr$(0) + chr$(80) then cursor = 2

if cursor = 1 then
locate 1,1
print ">"
locate 2,1
print " "

elseif cursor = 2 then

locate 2,1
print ">"
locate 1,1
print " "

end if
loop
How to make more options in the menu?

Posted: Thu Jul 09, 2009 4:07 pm
by DDastardly71
Here is a simple way to dynamically add or delete menu items. This code only looks long because it's indended and its in blocks.

Code: Select all

'
' goo1
'

DEFINT A-Z

Main:
  CLS
  
  '-- To add or delete items from the array you only need to
  '   modify the data statement and do two things...
  '  
  '   1. Change the first data statement to the number of
  '      elements in the array.
  '
  '   2. Add the row, col, and text anywhere below the first
  '      data statement.
  '
  '
  ' ****************************************************************
  '   NOTE: NO NEED TO MODIFY THIS CODE, JUST THE DATA STATEMENTS.
  ' ****************************************************************

  RESTORE
  READ NumItems

  REDIM Item$(1 TO NumItems), Row(1 TO NumItems), Col(1 TO NumItems)

  FOR i = 1 TO NumItems
    READ Row(i), Col(i), Item$(i)

    LOCATE Row(i), Col(i)
    PRINT Item$(i)
  NEXT

  '--

  LastChoice = 0
  Choice = 1

  DO
    IF LastChoice <> Choice THEN

      '-- This removes the previous pointer
      IF LastChoice > 0 THEN
        LOCATE LastChoice, 8: PRINT " "
      END IF
           
      LOCATE Choice, 8: PRINT ">"
      LastChoice = Choice
    END IF

    '--

    SELECT CASE INKEY$
      CASE CHR$(27)                       'escape
        Choice = 0
        EXIT DO
      CASE CHR$(13)                       'enter
        EXIT DO
      CASE CHR$(0) + CHR$(71)             'home
        Choice = 1
      CASE CHR$(0) + CHR$(79)             'end
        Choice = NumItems
      CASE CHR$(0) + CHR$(72)             'up
        IF Choice > 1 THEN
          Choice = Choice - 1
        ELSE
          Choice = NumItems
        END IF
      CASE CHR$(0) + CHR$(80)             'down
        IF Choice < NumItems THEN
          Choice = Choice + 1
        ELSE
          Choice = 1
        END IF
    END SELECT
  LOOP

  '-- 

  CLS

  IF Choice > 0 THEN
    PRINT "You selected item"; Choice
  ELSE
    PRINT "You made no selection!"
  END IF
END

DATA 5                                   
DATA 1, 10, "orange"                     
DATA 2, 10, "pear"                       
DATA 3, 10, "apple"                      
DATA 4, 10, "peach"                      
DATA 5, 10, "banana"                     

Posted: Fri Jul 10, 2009 6:02 am
by izidor
Wow, that's great! Thank you! :D

EDIT: I know how to edit column but how to change row of ">" ?

Posted: Wed Jul 29, 2009 7:09 pm
by DDastardly71
For this example, the first time is in row 1, therefore, I only had to use Choice% as the pointer for the actual row.

LOCATE Choice, 8: PRINT ">"
LastChoice = Choice

However, if you wanted to move the menu items to a different position, change the data statement to reflect the new position..

Say we want to modify the current DATA statement which starts at row=1 col=10 to row=5 col10

DATA 5
DATA 1, 10, "orange"
DATA 2, 10, "pear"
DATA 3, 10, "apple"
DATA 4, 10, "peach"
DATA 5, 10, "banana"

Now we want to put these items in the center of the screen...

DATA 5
DATA 8, 10, "orange"
DATA 9, 10, "pear"
DATA 10, 10, "apple"
DATA 11, 10, "peach"
DATA 12, 10, "banana"

The part of the code that you need change is this.

Change from this...

LOCATE Choice, 8: PRINT ">"
LastChoice = Choice

To this...

LOCATE Row%(Choice), Col%(Choice) - 2: PRINT ">"
LastChoice = Choice

I hope this helps.