Chapter 8: Advanced Statements in QBasic | CBSE Class 7 Computer

Notes — Chapter 8: Advanced Statements in QBasic | CBSE Class 7 Computer

🎨 QBasic Graphic Statements Explained

QBasic's graphic statements allow you to create shapes, colors, and sound in your programs, making learning coding more fun and creative!

🖥️ GRAPHIC MODE - SCREEN & RESOLUTION

  • SCREEN statement: Sets the display mode (resolution and color levels) required for drawing graphics.
    SCREEN mode_number
  • Common Modes:
    ModeResolutionColors
    0Text only-
    1320x2004 colors
    2640x2002 colors
    12640x48016 colors
Example:
SCREEN 1

🌈 COLOR STATEMENT

  • COLOR sets the foreground and background colors for text or graphics.
  • COLOR foreground, background
  • Some color codes:
    ColorCode
    Black0
    Blue1
    Green2
    Red4
    White7
    Yellow14
Example:
COLOR 4, 7
(Red text on white background)

⬛ PIXEL, PSET and PRESET

  • To color or read an individual pixel:
  • PSET (x, y), color plots a single pixel.
  • PRESET (x, y), color erases or puts background color at position.
Example:
PSET (100, 150), 14 ('Draws yellow pixel at 100,150)

📏 LINE Statement

  • LINE (x1, y1)-(x2, y2), color draws a line from (x1, y1) to (x2, y2).
  • B option: draws a rectangle.
    BF option: draws a filled box.
Draw a line:
LINE (50,60)-(180,160), 2
Draw a square box (side=50):
LINE (60,60)-(110,110), 3, B

⚪ CIRCLE Statement

  • CIRCLE (x, y), radius, color draws a circle with given center and radius.
Example:
CIRCLE (120,100), 40, 4 ('Red Circle)

🪄 PAINT Statement

  • Fills an area with color starting from (x, y).
  • PAINT (x, y), color, bordercolor
Example:
PAINT (120,100), 6, 4
Paints area from (120,100) with color 6 inside a red border (color 4).

✏️ DRAW Statement (Turtle Graphics)

  • Draws graphics using codes D, U, R, L, E, F, G, H (directions).
  • D: Down, U: Up, R: Right, L: Left, E: Up-Right, F: Down-Right, G: Down-Left, H: Up-Left
  • Syntax: DRAW "code" (e.g., DRAW "R50" moves right 50 units)
CodeDirection
DDown
UUp
RRight
LLeft
EUp-Right
FDown-Right
GDown-Left
HUp-Left
Example:
DRAW "R80D80L80U80" (Draws a square)

🔊 SOUND & BEEP Statements

  • BEEP: Simple short sound.
    BEEP
  • SOUND: Plays tone at selected frequency for specified time.
    SOUND frequency, duration
    (frequency in Hz, duration in 1/18 sec)
Example:
BEEP (Beep Sound)
SOUND 800, 10 (Tone at 800Hz for short time)

🚦 Unconditional and Exit Statements

  • END: Stops the program instantly.
    END
  • EXIT: Used to exit loop early.
    EXIT FOR
    EXIT DO
Example:
FOR I = 1 TO 10
  IF I = 5 THEN EXIT FOR
  PRINT I
NEXT I
    
(Prints 1 to 4, then exits loop)

🔀 GOSUB ... RETURN Statement

  • Jumps to a subroutine, then goes back to next statement after GOSUB.
  • GOSUB label ... RETURN
Example:
PRINT "Start"
GOSUB PrintMessage
PRINT "End"
END

PrintMessage:
PRINT "This is a subroutine"
RETURN
    
Answer the Question
Correct! Well done – You selected the right answer.

😊
🔔 Subscribe to My Channel

Post a Comment

0 Comments