MsgBox... What's wrong ??

skipsy

Member
Licensed User
Longtime User
Hi forum,

I don't understand. What's wrong with this code ?

B4X:
'Activity module
Sub Process_Globals
   'These global variables will be declared once when the application starts.
   'These variables can be accessed from all modules.

End Sub

Sub Globals
   Dim PNL_SCROLL As Panel
   Dim CVSLAYER As Canvas
End Sub

Sub Activity_Create(FirstTime As Boolean)
   PNL_SCROLL.Initialize( "SCROLL" )
   Activity.AddView( PNL_SCROLL, 0, 0, 100%x, 100%y )
   PNL_SCROLL.Color = Colors.transparent
   CVSLAYER.Initialize( Activity )
End Sub

Sub Activity_Resume

End Sub

Sub Activity_Pause (UserClosed As Boolean)

End Sub

Sub SCROLL_Touch (Action As Int, X As Float, Y As Float)
        Msgbox( "Down" ,"blabla")
End Sub

When I touch the screen the message box is displayed but the application is freezed. Nothing happens when I touch "OK". After a while, a message
appears : "Sorry! activity hmove does not respond" (Force close) (Wait)

Any idea ???

Thks,
WW
 

klaus

Expert
Licensed User
Longtime User
To test the touch event, try this code:
B4X:
Sub SCROLL_Touch (Action As Int, X As Float, Y As Float)
    Select Action
    Case Activity.ACTION_DOWN
        Activity.Title = "Down"
    Case Activity.ACTION_MOVE
        Activity.Title = "Move"
    Case Activity.ACTION_UP
        Activity.Title = "Up"
    End Select
End Sub
Best regards.
 
Upvote 0

skipsy

Member
Licensed User
Longtime User
This is what I did previously (the action was always "ACTION_DOWN") so
I simplify.
Anyway the result was the same !!

W.W.
 
Upvote 0

stevel05

Expert
Licensed User
Longtime User
It may be because you do not have the correct sub signature, it should be (from here)

B4X:
Sub SCROLL_Touch (Action As Int, X As Float, Y As Float) As Boolean

Try that and see if it helps
 
Upvote 0

skipsy

Member
Licensed User
Longtime User
Sorry,
I have also tried to add "as Boolean" even if I don't need any value returned.

If you copy/paste this code, do you have the same problem ?

W.W.
 
Upvote 0

stevel05

Expert
Licensed User
Longtime User
Having just tested it, it appears that using the msgbox is upsetting something. Maybe because it's blocking the thread that's awaiting a response?.

Replace that with:

Log( "Down blabla")

and it works as expected.
 
Upvote 0

klaus

Expert
Licensed User
Longtime User
The code I posted works fine, I tested it before posting it.
If you still have the MsgBox in the routine it won't work correctly.
This code works !
B4X:
Sub Globals
    Dim PNL_SCROLL As Panel
    Dim CVSLAYER As Canvas
End Sub

Sub Activity_Create(FirstTime As Boolean)
    PNL_SCROLL.Initialize( "SCROLL" )
    Activity.AddView( PNL_SCROLL, 0, 0, 100%x, 100%y )
    PNL_SCROLL.Color = Colors.transparent
    CVSLAYER.Initialize( Activity )
End Sub

Sub Activity_Resume

End Sub

Sub Activity_Pause (UserClosed As Boolean)

End Sub

Sub SCROLL_Touch (Action As Int, X As Float, Y As Float)
    Select Action
    Case Activity.ACTION_DOWN
        Activity.Title = "Down"
    Case Activity.ACTION_MOVE
        Activity.Title = "Move"
    Case Activity.ACTION_UP
        Activity.Title = "Up"
    End Select
End Sub
This code works too:
B4X:
Sub Globals
    Dim PNL_SCROLL As Panel
    Dim CVSLAYER As Canvas
End Sub

Sub Activity_Create(FirstTime As Boolean)
    PNL_SCROLL.Initialize( "SCROLL" )
    Activity.AddView( PNL_SCROLL, 0, 0, 100%x, 100%y )
    PNL_SCROLL.Color = Colors.transparent
    CVSLAYER.Initialize( Activity )
End Sub

Sub Activity_Resume

End Sub

Sub Activity_Pause (UserClosed As Boolean)

End Sub

Sub SCROLL_Touch (Action As Int, X As Float, Y As Float) As Boolean
    Select Action
    Case Activity.ACTION_DOWN
        Activity.Title = "Down"
    Case Activity.ACTION_MOVE
        Activity.Title = "Move"
    Case Activity.ACTION_UP
        Activity.Title = "Up"
    End Select
    Return True
End Sub
Best regards.
 
Upvote 0

stevel05

Expert
Licensed User
Longtime User
Sorry Klaus, I should have looked more closely at your first reply, would have saved some time!

I seem to remember having come across this in the past, and just tried log instead and when it worked, used that.
 
Upvote 0

skipsy

Member
Licensed User
Longtime User
Thks for your quick answers.
I have tried log("dddd") : Nothing is displayed.
Changing activity title works but... anyway, what I needed was a message
Box.

Can we say that using MsgBox in a _touch sub is not possible ?

W.W.
 
Upvote 0

stevel05

Expert
Licensed User
Longtime User
The "dddd" will be displayed in the Log. Select the Log tab in the bottom right to see the whole log and it will display in there but not on the device or emulator screen.
 
Upvote 0

klaus

Expert
Licensed User
Longtime User
Can we say that using MsgBox in a _touch sub is not possible ?
You should not use MsgBoxes in a touch event.
You could use a Label that you set to visible with the down event and hide with the up event. I have used this principle to show and hide Tooltips.
Do you really need the touch event ? Couldn't the Click event do what you want ?

Best regards.
 
Upvote 0
Cookies are required to use this site. You must accept them to continue using the site. Learn more…