Can the Sender be applied to a Spinner view

Mahares

Expert
Licensed User
Longtime User
When I click any of the 3 spinners, the Msgbox is completely ignored and bypassed. See below code excerpt:

Dim spnCode1, spnCode2, spnCode3 As Spinner
.
.
spnCode1.Initialize("MySpinnerCode")
spnCode2.Initialize("MySpinnerCode")
spnCode3.Initialize("MySpinnerCode")

Sub MySpinnerCode_ItemClick (Position As Int, Value As Object)
Dim Send As Spinner
Send=Sender
Msgbox(Send.SelectedItem.SubString2(0,2),"") 'displays the first 2 characters of the string: 0=1st chr, 1 is 2nd, 2 is excluded
End Sub
 

klaus

Expert
Licensed User
Longtime User
Unfortunately, you don't tell us the whole story!
The code below works fine:
B4X:
Sub Globals
    Dim spnCode1, spnCode2, spnCode3 As Spinner
End Sub

Sub Activity_Create(FirstTime As Boolean)
     Dim i As Int
     
    spnCode1.Initialize("MySpinnerCode")
    spnCode2.Initialize("MySpinnerCode")
    spnCode3.Initialize("MySpinnerCode")
    
    Activity.AddView(spnCode1, 10dip, 20dip, 200dip, 50dip)
    Activity.AddView(spnCode2, 10dip, 80dip, 200dip, 50dip)
    Activity.AddView(spnCode3, 10dip, 140dip, 200dip, 50dip)
    
    For i = 0 To 4
        spnCode1.Add("1" & i & "a") 
        spnCode2.Add("2" & i & "b") 
        spnCode3.Add("3" & i & "c") 
    Next
End Sub

Sub MySpinnerCode_ItemClick (Position As Int, Value As Object)
    Dim Send As Spinner
    Send=Sender
    Msgbox(Send.SelectedItem.SubString2(0,2),"") 'displays the first 2 characters of the string: 0=1st chr, 1 is 2nd, 2 is excluded
End Sub
You are missing to say where the Spinner were added.
If they were added in a layout file you MUST NOT initialize them once more in the code, they are automaticaly initilaized when the layout file is loaded.
If thy are not in a layout file you must add them to the Activity in the code.

Best regards.
 
Upvote 0

Mahares

Expert
Licensed User
Longtime User
You are correct Klaus. I did initialize the 3 spinners in the designer already. I removed the initialization from the code and it solved my problem. Thank you for the tip.
1. Is there a way that B4A warns of an error when a double initialization is made, because in my case I did not get any warning. That portion of the code was simply ignored and jumped over.
2. Also, I would like to review my OWN threads that I initiated and save them to an offline file on my PC for future reference. Can this be done?
Best wishes for a happy holiday.
 
Upvote 0

Mahares

Expert
Licensed User
Longtime User
It would be very helpful to have a button on the main home page of the forum that says: 'View my threads'. It would display all the threads posted by the member logged in. This can prevent repetitive threads that have already been addressed by the member in question.
 
Upvote 0
Top