Q(uick)BASIC Statement: ON STRIG

Quick View

ON STRIG(n)

An e trapping statement that specifies a subroutine to branch to when joystick trigger n is pressed

Worth knowing

Useful and cross-version information about the programming environments of QBasic and QuickBasic.

Syntax
  • STRIG(n%) ON
  • STRIG(n%) OFF
  • STRIG(n%) STOP
  • ON STRIG(n%) GOSUB line
Description/Parameter(s)
n% A value that specifies a joystick trigger:
n%Trigger
0Lower trigger, joystick A
2Lower trigger, joystick B
4Upper trigger, joystick A
6Upper trigger, joystick B
STRIG(n%) ON Enables joystick event trapping.
STRIG(n%) OFF Disables joystick event trapping.
STRIG(n%) STOP Suspends joystick event trapping. Events are processed once event trapping is enabled by STRIG ON.
line The label or number of the first line of the event-trapping subroutine.
Example
'This example requires a joystick. ON STRIG(0) GOSUB Handler STRIG(0) ON PRINT "Press Esc to exit." DO UNTIL INKEY$ = CHR$(27): LOOP END Handler: PRINT "Joystick trigger is depressed." RETURN
Syntax
  • ON STRIG(n) GOSUB {linelabel | linenumber}
Description/Parameter(s)
Following are the integer values for each joystick trigger:
  • 0 = lower button, first joystick
  • 2 = lower button, second joystick
  • 4 = upper button, first joystick
  • 6 = upper button, second joystick
Example

There is no programming example for the ON STRIG(n) statement.
The following programming examples show how to integrate ON event statements, statements that enable traps, and event-handling subroutines into a working program: ON PLAY(n) statement programming example
ON TIMER(n) statement programming example

See also:

Syntax
  • ON STRIG(n%) GOSUB {linenumber | linelabel}
Description/Parameter(s)
n% The trigger number (an integer expression):
n%TriggerJoystick
0LowerFirst
2LowerSecond
4UpperFirst
6UpperSecond
linenumber or linelabel The first line of the event-handling routine to branch to when joystick trigger n% is pressed.
A linenumber value of 0 disables event trapping and does not specify line 0 as the start of the routine.
ON STRIG is not available for OS/2 protected mode.

Usage Notes

  • The ON STRIG statement specifies only the start of an event-trapping routine. The STRIG Statements determine whether the routine is called and how events are handled when trapping is off:
    STRIG ONEnables event trapping. Event trapping occurs only after a STRIG ON statement is executed.
    STRIG OFFDisables event trapping. Even if an event takes place, it is not remembered.
    STRIG STOPSuspends event trapping. Any events that occur are remembered and are trapped as soon as a STRIG ON statement is executed.
  • If your program contains event-handling statements and you are compiling from the BC command line, use the BC /W or /V option. (The /W option checks for events at every label or line number; the /V option checks at every statement.) If you do not use these options and your program contains event traps, BASIC generates the error message, "ON event without /V or /W on command line."
  • The RETURN linenumber or RETURN linelabel forms of RETURN can be used to return to a specific line from the trapping routine. Use this type of return with care, however, because any other GOSUB, WHILE, or FOR statements active at the time of the trap remain active. BASIC may generate error messages such as "NEXT without FOR. " In addition, if an event occurs in a procedure, a RETURN linenumber or RETURN linelabel statement cannot get back into the procedure because the line number or label must be in the module-level code.
Example

This example uses the EVENT and STRIG statements to enable joystick event trapping for two buttons on each of two joysticks. The ON STRIG statement passes control to an event-handling routine when a button is pressed. The STRIG function is used to determine which button was pressed, and the STICK function returns the position of both joysticks.

CLS 'Turn on event processing. EVENT ON 'Enable the upper and lower buttons on both joysticks. STRIG(0) ON 'Lower button, joystick A STRIG(2) ON 'Lower button, joystick B STRIG(4) ON 'Upper button, joystick A STRIG(6) ON 'Upper button, joystick B 'Set up joystick event processing for each button. ON STRIG(0) GOSUB JoyButtonHandler ON STRIG(2) GOSUB JoyButtonHandler ON STRIG(4) GOSUB JoyButtonHandler ON STRIG(6) GOSUB JoyButtonHandler LOCATE 22, 6 PRINT "Press a button on either joystick to see a complete joystick report." LOCATE 23, 20 PRINT "Press ANY keyboard key to end the program." 'Infinite loop waiting for a Joystick event or keyboard key input. DO LOOP WHILE INKEY$ = "" WrapItUp: CLS STRIG(0) OFF STRIG(2) OFF STRIG(4) OFF STRIG(6) OFF END JoyButtonHandler: 'Print a label on screen. LOCATE 10, 14: PRINT "Joystick A" LOCATE 10, 45: PRINT "Joystick B" LOCATE 22, 1: PRINT STRING$(80, 32) DO 'Button 1, Joystick A. IF STRIG(1) THEN ButtonStatus$ = "DOWN" ELSE ButtonStatus$ = "UP " END IF EVENT OFF LOCATE 16, 10: PRINT "Button 1 is "; ButtonStatus$ EVENT ON 'Button 1, Joystick B. IF STRIG(3) THEN ButtonStatus$ = "DOWN" ELSE ButtonStatus$ = "UP " END IF EVENT OFF LOCATE 16, 42: PRINT "Button 1 is "; ButtonStatus$ EVENT ON 'Button 2, Joystick A. IF STRIG(5) THEN ButtonStatus$ = "DOWN" ELSE ButtonStatus$ = "UP " END IF EVENT OFF LOCATE 18, 10: PRINT "Button 2 is "; ButtonStatus$ EVENT ON 'Button 2, Joystick B. IF STRIG(7) THEN ButtonStatus$ = "DOWN" ELSE ButtonStatus$ = "UP " END IF EVENT OFF LOCATE 18, 42: PRINT "Button 2 is "; ButtonStatus$ EVENT ON GOSUB UpdateXY LOOP WHILE INKEY$ = "" RETURN WrapItUp UpdateXY: EVENT OFF LOCATE 12, 10: PRINT USING "X Position = ###"; STICK(0) LOCATE 14, 10: PRINT USING "Y Position = ###"; STICK(1) LOCATE 12, 42: PRINT USING "X Position = ###"; STICK(2) LOCATE 14, 42: PRINT USING "Y Position = ###"; STICK(3) EVENT ON RETURN