Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Error? Why?
#1
When I try to run this code I get a "parameter type mismatch" error on the third argument of the DrawX SUB.. even though the DrawY SUB is the exact same. Please inform me of waht I am doing.
I apologize if my comments move to the new line, creating confusion.

Code:
'**********************************************************
'** This program is fairly simple, and was my first      **
'** attempt at really playing around with graphics in QB **
'** x and y control the intersection of the lines.       **
'** endtime controls the speed at which the lines move   **
'**         the higher the #, the slower they move.      **
'** xgoway and ygoway are integers with the value of     **
'** 1 or -1, depending if the lines are moving L/R/U/D   **
'** Written By:  Brett Haralson                          **
'**********************************************************

DECLARE SUB DrawX (x, y, xgoway AS INTEGER)
DECLARE SUB DrawY (x, y, ygoway AS INTEGER)

SCREEN 12                               'Set screen to 12, (640 X 480 resolution)

CONST XMAX = 640                        'This constants are use to draw the lines to absolute positions
CONST YMAX = 480                        'on the monitor. eg. LINE (x, 0)-(x, YMAX) draws up/down line.

DIM x, y, endtime, xgoway, ygoway AS INTEGER

x = 1: y = 0: endtime = 20000: xgoway = 1: ygoway = 1

DO
  CALL DrawY(x, y, ygoway)              'This draws the line on Y axis (up down)
  FOR i = 0 TO endtime: NEXT            'This creates a small delay so the prog doesn't run too fast.
  CALL DrawX(x, y, xgoway)              'This draws the line on the X axis
  IF (INKEY$ <> "") THEN : END          'This monitors keyboard input and quits whenever any key is pressed.
LOOP

SUB DrawX (x, y, way AS INTEGER)  'draws the sweeping x line
  
   IF (x = 0) THEN : way = 1                                    'If x line has reached far left, reverse direction.
   IF (x = 639) THEN : way = -1: LINE (640, 0)-(640, YMAX), 9   'If x line has reached far right, reverse direction, and draw last line.
   LINE (x - way, 0)-(x - way, YMAX), 0                         'Cover up old line.
   LINE (x, 0)-(x, YMAX), 9                                     'Draw new line (notice how change in line position is dictated by the value of variable 'way'
   x = x + way                                                  'change the value of x so the sub will know where to draw line next time it is called
  
END SUB


SUB DrawY (x, y, way AS INTEGER) 'draws the sweeping x line

   IF (y = 0) THEN : way = 1
   IF (y = 479) THEN : way = -1: LINE (0, 480)-(XMAX, 480), 9
   LINE (0, y - way)-(XMAX, y - way), 0
   LINE (0, y)-(XMAX, y), 9
   y = y + way

   'Since DrawX is called in both For loops in Main program, I
   'chose to insert the hit any key to quit thing here.
   IF (INKEY$ <> "") THEN : END

END SUB
Reply
#2
Not sure if this is it or not, but your variable names for the declare and the sub routine are different for the third arguments.
Reply
#3
Code:
DIM x, y, endtime, xgoway AS INTEGER, ygoway AS INTEGER
Reply
#4
Can you explain to me why that is?

why you have to say
Code:
DIM x, y, xgoway AS INTEGER, ygoway AS INTEGER

and not
Code:
DIM x, y, xgoway, ygoway AS INTEGER
Reply
#5
If you don't specify a type for a variable in a DIM statement, it is the default type.
Code:
DIM x, y, xgoway AS INTEGER, ygoway AS INTEGER
dimensions x and y as SINGLEs and xgoway and ygoway as INTEGERs.
Code:
DIM x, y, xgoway, ygoway AS INTEGER
dimensions x, y and xgoway as SINGLEs and ygoway as an INTEGER.

If you want to change the defult type for the program to INTEGERs, you can use the line
Code:
DEFINT A-Z

at the beginning of the program (you can also use it above the header of any SUB).
hrist Jesus came into the world to save sinners, of whom I am first.(I Timothy 1:15)

For God so loved the world, that He gave His only begotten Son,
that whoever believes in Him should not perish, but have eternal life.(John 3:16)
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)