It looks like you want to be able to drag the block with the mouse?
In that case, it isn't working because if the user moves the mouse too quickly, it will move off the sprite before the program can detect it.
I'm having a hard time describing it, but this code fixes that. See if you can figure out what I changed:
create bitmap 1,640,480
cls rgb(200,100,50)
line 20,20,50,20
line 20,20,20,40
line 20,40,50,40
line 50,40,50,20
get image 2,20,20,51,41
delete bitmap 1
x as float
x=200
sync on
do
if rightkey()=1 then inc x,0.15
if leftkey()=1 then dec x,0.15
olda=a
a=mousex()
sprite 3,x,100,2
if mouseclick()=1 and a>sprite x(3) and a<sprite x(3)+30
clicked=1
endif
if clicked=1
if mouseclick()=0
clicked=0
endif
if a-olda>0
inc x,a-olda
else
if a-olda<0
inc x,a-olda
endif
endif
endif
sync
loop