What am I doing wrong here?

bodycode

Member
Licensed User
Longtime User
I'm such a :sign0104: I'm even struggling with CASE SELECT! God.. Anyway....

Why doesn't my button clicks change the text of labels based on this code? tags have been set for both buttons. In your first interface tutorials, I see that the click sub is called "btnPage_Click". For some reason, the name of that sub makes or breaks the case selects. Somehow, is that subroutine name just PART of the names of all three buttons and picking up the first part of the name of all three buttons? Damn I'm really confused here. ? I ask that because when I change the btnPage_Click to btnMyClicker, it doesn't work! When I change it back, it works again. Is that name btnPage_Click the first part of the button names? I noticed that the button names are btnPage1, btnPage2 and btnPage3 loaded into the Main layout.

Oh yes, I want to really thank Margaret and Lagore for all their immense help. And anyone else who jumps in to rescue stupidity from itself (me) :)


'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
'These global variables will be redeclared each time the activity is created.
'These variables can only be accessed from this module.

Dim lbl1 As Label
Dim lbl2 As Label
Dim btn1 As Button
Dim btn2 As Button
End Sub

Sub Activity_Create(FirstTime As Boolean)
Activity.LoadLayout("main")
End Sub

Sub Activity_Resume

End Sub

Sub Activity_Pause (UserClosed As Boolean)

End Sub
'One click event for all buttons.

Sub btnPage_Click
Dim Send As Button
Send = Sender

Select Send.Tag
Case "1"
lbl1.Text = "Button 1 clicked."
Case "2"
lbl2.Text = "Button 2 clicked."
End Select
End Sub
 
Last edited:

goron

Member
Licensed User
Longtime User
Hi

Did not see your Activity.LoadLayout("main")

Try case 1 instead of case "1"

HTH, Gideon
 
Upvote 0

bodycode

Member
Licensed User
Longtime User
Thanks Goron

I found out why? It's note the case comparitor value. It's the event name within the button! I was looking through the graphical examples in tutorial one, and I noticed that the event name of all the buttons!

I didn't even remember the tutorial ever saying that I need to change the event name of the buttons, however, obviously I'm wrong, I don't even think I have to run this to know it works. But I'll be running it anyway.

You know the case select values to compare are all enclosed within quotation marks and everything works perfectly, so I don't think it's that. I'll be getting back to you on this, and if what I noticed doesn't work I will certainly try your change. Thank you again for your input. I will master B4A if it kiills me :) Which it's doing.. But it's a sweet death... heh heh.

Hi

Did not see your Activity.LoadLayout("main")

Try case 1 instead of case "1"

HTH, Gideon
 
Upvote 0

bodycode

Member
Licensed User
Longtime User
Activity name with object is key

:) Success! Yes, so as I suspected, the actual event name within whatever view you're working on, has to match the new case select sub's name which I added by creating the new case select sub. All ya gotta do, is add an underscore and the word Click

In my example, I gave the event name of two buttons the name of btn_Event I typed in, into each button view, using the Designer. The sub name is simply that name, with an underscore and the word Click, like so: btnEvent_Click.

Renaming the comparitor values to not include quotes around them, yielded a non-functioning case-select sub. Adding the quotes back made the sub function perfectly. Apparently these are not values in the sense of numbers, but, a string that needs to be passed to the keyword Case as as true Basic string, which needs quotes to define.



Hi

Did not see your Activity.LoadLayout("main")

Try case 1 instead of case "1"

HTH, Gideon
 
Upvote 0
Top