Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Problem
#1
what is wrong with this snippet?

[syntax="qbasic"] for i = 1 to numwindows
line (win(i).x, win(i).y)-(win(i).x + win(i).xsize, win(i).y + win(i).ysize), windowcolour, bf
line (win(i).x, win(i).y)-(win(i).x + win(i).xsize, win(i).y + win(i).ysize), bordercolour, b
next [/syntax]
Reply
#2
Only one real problem:
Suppose a window is at (1,1) and it's 1 pixel wide and 1 tall. It will draw from (1,1)-(1+1,1+1) - that's a 2x2 box! You have to subtract 1 in the equations for the x,y of the second coordinate.
Reply
#3
So if nothing is wrong, why doesnt it work!

(FB.12)


Full Code:
Code:
'GUI
'Dark Prevail
'5/3/05

'$dynamic
Declare sub drawwindows()
type windowtype
   x as integer
   y as integer
   xsize as integer
   ysize as integer
end type
Dim win(0) as windowtype
Dim sorter(0)

'Declare shared variables --
Dim shared numwindows
Dim shared bordercolour, windowcolour 'colours
'--

'set variables
bordercolour = rgb(220,220,220)
windowcolour = rgb(150,150,150)
'--

Screen 20, 24, 2, 1
screenset 1, 0

setmouse 512, 384, 1

Do
   getmouse mousex, mousey, wheelstatus, buttonstatus
   locate 1, 1
   print mousex; mousey; wheelstatus; buttonstatus
   drawwindows
   screencopy
   cls
loop until inkey$ <> ""

sub drawwindows()
   for i = 1 to numwindows
      line (win(i).x, win(i).y)-(win(i).x + win(i).xsize, win(i).y + win(i).ysize), windowcolour, bf
      line (win(i).x, win(i).y)-(win(i).x + win(i).xsize, win(i).y + win(i).ysize), bordercolour, b
   next
end sub
Reply
#4
Quote:
Code:
[...]
end type
Dim win(0) as windowtype
Dim sorter(0)
[...]
sub drawwindows()
   for i = 1 to numwindows
      line (win(i).x, win(i).y)-(win(i).x + win(i).xsize, win(i).y + win(i).ysize), windowcolour, bf
      line (win(i).x, win(i).y)-(win(i).x + win(i).xsize, win(i).y + win(i).ysize), bordercolour, b
   next
end sub
The problem is the drawwindows sub doesn't know win, as you dim'ed it without the shared option... So it expects it to be a normal variable, not an array, and it bails out when it finds the first open parenthesis next to win...
The solution is to declare win as shared:
Code:
Dim shared win(0) as windowtype
It is a good habit to use option explicit; these kind of things are prohibited if you use it, and you immediately get what's wrong.
ngelo Mottola - EC++
Reply
#5
oops! Thanks, Lillo!
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)