Gestures?

J12345T

Member
Licensed User
Hi All,

This may be a silly question but is there any way to program the touch screen to respond to 'gestures' like the HTC Touch or the Apple iPhone. For example the HTC responds to sweeps over the touch screen and of course the iPhone has all sorts of tricks.. Any thoughts??

Cheers,

JT
 

Erel

Administrator
Staff member
Licensed User
You could use form's mouse events to analyze the gesture.
For example you can check the values of (x,y) in mousedown event and compare them to the values of (x,y) in mouseup event.
 

J12345T

Member
Licensed User
Thanks Erel,

I tried the following:-

sub mousedown (x,y)
end sub

sub mouseup (a,b)
if a-x > 200 then msgbox("gesture")
end sub

I found that I kept getting a variable with unassigned value error. I tried to set nominal values as globals but then got the error something like can't hide a global variable... etc.

I'm obviously doing it wrong. Any ideas?

Just to clarify I want to be able to sweep my finger from left to right across the screen (and VV) to enable an action.

Thanks.

JT.
 

DavidN

Member
Licensed User
Try this:

Sub Globals
Dim last_x, last_y
Thresh_x = 20
End Sub

Sub App_Start
Form1.Show
End Sub

Sub Form1_MouseDown (x,y)
last_x = x
last_y = y
End Sub

Sub Form1_MouseUp (x,y)
if x-last_x > Thresh_x Then
Msgbox("test")
End If
End Sub
 

agraham

Expert
Licensed User
I'm obviously doing it wrong. Any ideas?

The problem is here
B4X:
sub mousedown (x,y)
end sub
You need to understand the difference between global and local variables. In the above code fragment x and y are variables that are local to Sub MouseDown. This means that they exist only between the Sub and End Sub statements. When the flow of execution exits the Sub local variables are destroyed and their values lost.

For variables to exist independently and retain their values you need to declare them as global variables. You did the right thing in trying to save the values you wanted as global variables but as you found out B4PPC doesn't let you declare a parameter to a function (which is a local variable) with the same name as a global one.
 

dennishea

Active Member
Licensed User
agraham, Can you do something like this?

Sub Globals
dim Globalx, Globaly
End Sub

Sub MouseDown(x,y)
Globalx = x
Globaly = y
End Sub

dennishea
 

agraham

Expert
Licensed User
agraham, Can you do something like this?
Yes, any variable declared in Sub Globals is accessible from anywhere in the program. Also note that you can pass local variables to other Subs. The code below is a brief primer on variable uses - hope this isn't patronising but you seem to need a bit of help with variable use.
B4X:
Sub Globals
   'Declare the global variables here.
   Dim Globalx
End Sub

Sub App_Start
   x = 3 ' declare and set a local variable, can be a string OR a number
   A(x) ' pass the local variable to another sub to do something with
   A(Globalx) ' can also pass a Global variable if needed
   ' note that you can ignore a return value if you want as both above do
   x =A(x)
   Msgbox("local x = " & x & ", Globalx = " & Globalx) ' displays 12 in both cases
   ' x is lost on exit from Sub, Globalx remains with value 12
End Sub

Sub A(y)
   ' local variable y is a COPY of Sub A local variable x
   ' Do something with y
   y = y*4 ' can reuse a passed variable but the new value DOESN't affect Sub A variable x
   ' Do something else with new value of y
   Globalx = y ' to return a changed value from a Sub either use a Global
   Return y ' or you can return a single value
End Sub
 

J12345T

Member
Licensed User
Thanks everyone,

I am completely new to programming but have managed to muddle through with the help files etc. This forum is enormously helpful so thanks for your patience.

Regards,

JT.
 

dennishea

Active Member
Licensed User
@agraham

Thanks for the explanation on variables, that is one of many of my programming weaknesses.

dennishea
 
Top